

function showEmbedPopup(popup){
	
	var popupEl = $(popup);
	var popupFX = new Fx.Styles(popupEl, {duration:500, wait:false});
	var popupInitFX = new Fx.Styles(popupEl, {duration:0, wait:false});
	
	go();
	
	function go(){

		popupInitFX.start({
			'opacity': 0
		}).chain(function(){
			popupEl.style.display = 'block';
			popupFX.start({		
				'opacity': 1
			});
		});
	}
	
}

function hideEmbedPopup(popup){
	
	var popupEl = $(popup);
	var popupFX = new Fx.Styles(popupEl, {duration:500, wait:false});
	
	go();
	
	function go(){

		popupFX.start({		
			'opacity': 0
		}).chain(function(){
			popupEl.style.display = 'none';
		});
	}
	
}

function showNextThumbSet(){
	
	var thumbSets = $('thumbnailSets').childNodes;

	for(var c = 0; c < thumbSets.length; c++){
		
		if(thumbSets[c].style.display == 'block'){
			
			if(c == thumbSets.length-1){
				return false;
			} else {
				var hideSet = thumbSets[c];
				var showSet = thumbSets[c+1];
				var hideFX = new Fx.Styles(thumbSets[c], {duration:500, wait:false});
				var showFX = new Fx.Styles(thumbSets[c+1], {duration:500, wait:false});
				var showInitFX = new Fx.Styles(thumbSets[c+1], {duration:0, wait:false});
			}
			
			hideFX.start({
				'opacity': 0
			}).chain(function(){
				$(hideSet).style.display = "none";
				showInitFX.start({
					'opacity': 0
				}).chain(function(){
					$(showSet).style.display = 'block';
					showFX.start({
						'opacity': 1
					});
				});
			});
			
			if(showSet.id == 'set'+thumbSets.length){
				$('arrow_thumbnails_left').className = '';
				$('arrow_thumbnails_right').className = 'disabled';
			} else if(showSet.id == 'set1'){
				$('arrow_thumbnails_left').className = 'disabled';
				$('arrow_thumbnails_right').className = '';
			} else {
				$('arrow_thumbnails_left').className = '';
				$('arrow_thumbnails_right').className = '';
			}
			
		}
	}	
}

function showPrevThumbSet(){
	
	var thumbSets = $('thumbnailSets').childNodes;

	for(var c = 0; c < thumbSets.length; c++){
		
		if(thumbSets[c].style.display == 'block'){
			
			if(c == 0){
				return false;
			} else {
				var hideSet = thumbSets[c];
				var showSet = thumbSets[c-1];
				var hideFX = new Fx.Styles(thumbSets[c], {duration:500, wait:false});
				var showFX = new Fx.Styles(thumbSets[c-1], {duration:500, wait:false});
				var showInitFX = new Fx.Styles(thumbSets[c-1], {duration:0, wait:false});
			}
			
			hideFX.start({
				'opacity': 0
			}).chain(function(){
				$(hideSet).style.display = "none";
				showInitFX.start({
					'opacity': 0
				}).chain(function(){
					$(showSet).style.display = 'block';
					showFX.start({
						'opacity': 1
					});
				});
			});
			
			if(showSet.id == 'set1'){
				$('arrow_thumbnails_left').className = 'disabled';
				$('arrow_thumbnails_right').className = '';
			} else if(showSet.id == 'set'+thumbSets.length){
				$('arrow_thumbnails_left').className = '';
				$('arrow_thumbnails_right').className = 'disabled';
			} else {
				$('arrow_thumbnails_left').className = '';
				$('arrow_thumbnails_right').className = '';
			}
			
		}
	}	
}

function swapMainImage(image, newSrc, p_id){

	var image = $(image);
	var dl_og = document.getElementById('ogsizelink');
	var dl_og_size = document.getElementById('ogsize');
	var dl_lg = document.getElementById('lgsizelink');;
	var dl_lg_size = document.getElementById('lgsize');;
	image.src = newSrc;
	dl_og.href = ogSize[p_id];
	dl_og.innerHTML = ogSizew[p_id] + "x" + ogSizeh[p_id];
	
	//check if second largest image is avail
	if(lgSize[p_id]) {
		dl_lg.href = lgSize[p_id];
		dl_lg.innerHTML = lgSizew[p_id] + "x" + lgSizeh[p_id];
	}
	
}

 function unselectAllThumbs(){
    var list = $$('#thumbnailSets li');
    list.each(function(element) {
       element.className = '';
 
	});
}