/* shwv.P104090729 */
/* (c)2009 SugarHill Works LLC - http://www.sugarhillworks.com */
/**
 * A simple querystring parser.
 * Example usage: var q = $.parseQuery(); q.fooreturns  "bar" if query contains "?foo=bar"; multiple values are added to an array. 
 * Values are unescaped by default and plus signs replaced with spaces, or an alternate processing function can be passed in the params object .
 * http://actingthemaggot.com/jquery
 *
 * Copyright (c) 2008 Michael Manning (http://actingthemaggot.com)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 **/
jQuery.parseQuery = function(qs,options) {
	var q = (typeof qs === 'string'?qs:window.location.search), o = {'f':function(v){return unescape(v).replace(/\+/g,' ');}}, options = (typeof qs === 'object' && typeof options === 'undefined')?qs:options, o = jQuery.extend({}, o, options), params = {};
	jQuery.each(q.match(/^\??(.*)$/)[1].split('&'),function(i,p){
		p = p.split('=');
		p[1] = o.f(p[1]);
		params[p[0]] = params[p[0]]?((params[p[0]] instanceof Array)?(params[p[0]].push(p[1]),params[p[0]]):[params[p[0]],p[1]]):p[1];
	});
	return params;
}

$(window).ready(function(){
	window.setTimeout("$('#overlay').hide(300);", 1000);
	full_scr_cntr = document.getElementById('full_scr_cntr');
	glassCntr = document.getElementById('glass_cntr');
	ssCntr = document.getElementById(ss_image_cntr_id);
	thmsCntr = document.getElementById(ss_thumb_cntr_id);
	titleCntr = document.getElementById(ss_title_cntr_id);
	captionsCntr = document.getElementById(ss_captions_cntr_id);
	alt_captionsCntr = document.getElementById(alt_captions_cntr_id);
//	caption1_cntr = document.getElementById(ss_caption1_cntr_id);
//	caption2_cntr = document.getElementById(ss_caption2_cntr_id);
	ssPlayCntr = document.getElementById('ssPlay_cntr');
	ssPauseCntr = document.getElementById('ssPause_cntr');	
	paypalFm = document.getElementById('paypal_fm');
	paypalViewFm = document.getElementById('paypal_view_fm');
	purchBtm = document.getElementById('purch_btm');
	ss_init(ss_image_cntr_id);
});



if (randomizeOrder === true) {
	slideshow.sort(randOrd);
}

var imgs = [];
//var paramStrings = [];
//var parampass;
var current_fr = 0;
var current = 0, current_title = 0, current_caption = 0;
var nIndex = 1;
var ssRunning;
var nPause;
var lastRun;
var fadeComplete = false;
var ssPauseTO;
var resumeImg;
//var navArwL_div;
//var navArwR_div;
//var navArwL = document.createElement('img');
//var navArwR = document.createElement('img');
var dir;
var resumeToggle = '';
var ssPlayCntr, ssPauseCntr;
var ssCntr;
var thmsCntr;
var thms = [];
var thmsScrCntr;
var thm_div;
var scr;
var scrolling;
var scrollingDisabled = false;
var thm_scroll_TO;
var thmsPerPg;

var glassCntr;
var titleCntr;
var titles = [];
var captionsCntr, alt_captionsCntr;//, caption1_cntr, caption2_cntr;
//var captions1 = [];
//var captions2 = [];
var captions = [];

var paypalFm, paypalViewFm;
var purchBtm;
//var PP_names = [];
//var PP_numbers = [];
//var PP_amounts = [];

//var oSize_bg, oSize_cntr;

var useWideLayout = false;

if (ss_resume_interval) {
	var ssPoll = window.setInterval("ssPoller()",ss_resume_interval);
}


function layoutThmScrCntr() {
	var thms_scr_cntrW = thm_div.offsetWidth * ssn;
//	alert(thmsScrCntr.id);
	thmsScrCntr.style.width = thms_scr_cntrW + 'px';
	thmsPerPg = Math.round(thmsCntr.offsetWidth / thm_div.offsetWidth);
	if (thmsPerPg >= ssn) {
		thmsScrCntr.style.left = ((thmsCntr.offsetWidth - (thm_div.offsetWidth*ssn)) / 2) + 'px';
		thmsPerPg = ssn;
		scrollingDisabled = true;
	}
	if (hideScrollArrows === true) { 
		$("#thmArwL_cntr").css('visibility','hidden');
		if (thmsPerPg >= ssn) {
			$("#thmArwR_cntr").css('visibility','hidden');
		}
	}
	CSBfleXcroll(ss_thumb_cntr_id);
//	CSBfleXcroll('main_thms_cntr');
//	window.setTimeout("CSBfleXcroll('main_thms_cntr');", 5000);
}

function ss_init(ss_cntr_id) { 
	var i; 
	if (!document.getElementById || !document.createElement) {
		return;
	}
	
	var q = $.parseQuery();
	if (q.pp_resume) {
		current = parseInt(q.pp_resume);
		if ((current < 0) || (current >= ssn) || (isNaN(current) === true)) { current = 0; }
	}
	
	if(glass_nav === true) {
		glassCntr.onclick = function () { ssPause(1); };
		glassCntr.className = 'glass_nav';
		if (showImgsTitleAtt === true) {
			glassCntr.title = (current+1) + ' of ' + ssn;
		}
	}
	ssCntr.innerHTML = '';
	

	if (thmsCntr) {
		thmsCntr.innerHTML = '';
		thmsScrCntr = document.createElement('div');
		thmsScrCntr.id = 'thms_scr_cntr';
		thmsScrCntr.style.overflow = 'auto';
		thmsScrCntr.style.position = 'relative';
		thmsScrCntr.style.visibility = 'visible';
		var thms_scr_cntrW = 0;
		for (var i = 0; i < ssn; i++) {
			thm_div = document.createElement('div');
			thm_div.className = 'thm_cntr';
			thm_div.style.visibility = 'visible';
			var thm_a = document.createElement('a');
			thm_a.id = i + '_thm_a';
			thm_a.style.visibility = 'visible';
			thm_a.onclick = function () {
				getImgsToFade(current, current_fr, nPause, parseInt(this.id));
			}
			var thm = new Image();
			thms_folder = slideshow.sPicsFolder.replace('images', 'thumbs');
			thm.src = thms_folder + slideshow[i].thumb;
			thm.id = "ssThm_" + i;
			thm.style.visibility = 'visible';
			thm.onmouseover = function() {
				this.xOpacity = 1;
				this.style.filter = "alpha(opacity=100)";
				this.style.MozOpacity = "1";
				this.style.opacity = "100";
	
			};
			if (showThmsTitleAtt === true) {
				thm.title = (i + 1) + ' of ' + ssn;
			}
			thm_a.appendChild(thm);
			thm_div.appendChild(thm_a);
			thmsScrCntr.appendChild(thm_div);
			thms.push(thm);
		}
		var clrbth = document.createElement('div');
		clrbth.style.clear = "both";
		thmsScrCntr.appendChild(clrbth);
		thmsCntr.appendChild(thmsScrCntr);
		//thmsCntr.scrollUpdate();
		
		if (thms_behavior === 'scrolly') {
			window.setTimeout("layoutThmScrCntr()", 750);
			for (i = 0; i < ssn; i++) {
				var thm = thms[i];
				if (i === current) {
					thm.xOpacity = 1;
					thm.style.filter = "alpha(opacity=100)";
					thm.style.MozOpacity = "1";
					thm.style.opacity = "1";
					thm.onmouseout = function() {
						this.xOpacity = 1;
						this.style.filter = "alpha(opacity=100)";
						this.style.MozOpacity = "1";
						this.style.opacity = "1";
			
					};
				}
				else {
					thm.xOpacity = thms_minOpacity;
					thm.style.filter = "alpha(opacity="+(thms_minOpacity*100)+")";
					thm.style.MozOpacity = thms_minOpacity.toString();
					thm.style.opacity = thms_minOpacity.toString();
					thm.onmouseout = function() {
						this.xOpacity = thms_minOpacity;
						this.style.filter = "alpha(opacity="+(thms_minOpacity*100)+")";
						this.style.MozOpacity = thms_minOpacity.toString();
						this.style.opacity = thms_minOpacity.toString();
					};
				}
			}
		}
	}



	for (var i = 0; i < ssn; i++) {
		imgs[i] = new Image();
		imgs[i].src = slideshow.sPicsFolder + slideshow[i].image;
		imgs[i].alt = "[image]"
	}

	for (i = 0; i < ssn; i++) {
		var img = imgs[i];
		img.id = 'ssImg_' + i;
		if (i === current) {
			img.style.visibility = 'hidden';
			img.style.display = 'block';
		}
		else {
			img.style.display = 'none';
		}
	}


	ssCntr.appendChild(imgs[current]); 
	safeStart();
	$('#ssImg_'+current).load(function () {
		posImgs(current, img_h_position, img_v_position);
		fadeComplete=true;
	});

	
	if (titleCntr) {
		titleCntr.innerHMTL = '';
		titles[0] = document.createElement('div');
		titles[0].id = 'title_txt_0';
		titles[1] = document.createElement('div');
		titles[1].id = 'title_txt_1';
		titles[0].innerHTML = slideshow[current].title;//.replace(/ /g, '&nbsp;');
		titleCntr.appendChild(titles[1]);
		titleCntr.appendChild(titles[0]);
	}
		if (captionsCntr) {
			captionsCntr.innerHTML = '';
			captions[0] = document.createElement('p');
			captions[0].id = 'caption_txt_0';
			captions[1] = document.createElement('p');
			captions[1].id = 'caption_txt_1';
			var c1p='', c1a='', c2p='', c2a='';
			var ac1p='', ac1a='', ac2p='', ac2a='';
			if (slideshow[current].caption1) { c1p = caption1Pre; c1a = caption1App; }
			if (slideshow[current].caption2) { c2p = caption2Pre; c2a = caption2App; }
			function doAltCaptions (useWideLayout) {
				if (useWideLayout !== true) {
					captionsCntr.appendChild(captions[0]);
					$("#"+captions[0].id).html(c1p + slideshow[current].caption1 + c1a  + c2p + slideshow[current].caption2 + c2a);
					$("#caption_txt_"+0).fadeIn(ss_fade_duration);
					$("#alt_caption_txt_"+0).fadeIn(ss_fade_duration);
				} else {
					alt_captionsCntr.appendChild(captions[0]);
					$("#"+captions[0].id).html(c2p + slideshow[current].caption2 + c2a + c1p + slideshow[current].caption1 + c1a);
					$("#caption_txt_"+0).fadeIn(ss_fade_duration);
					$("#alt_caption_txt_"+0).fadeIn(ss_fade_duration);
				}	
			}
			var func = function()
			{
				doAltCaptions(useWideLayout);
			}
			window.setTimeout(func, 100);
		}
	//	oSize_bg = document.getElementById('oSize_bg');
	//	oSize_cntr = document.getElementById('oSize_cntr');
	
	//	parampass = paramStrings[0];
	if (paypalFm) {
		paypalFm.item_number.value = (slideshow[current].image.replace(/\.[a-z]{3}/, '')) + '_img.' + (current+1);
		if ($(window).height() < 725) {
			paypalFm.shopping_url.value = window.location.toString().replace(/\/$|\/index.*|\/#.*$|\/\?.*$/i, '?pp_resume='+current+'#menu_cntr');
			paypalViewFm.shopping_url.value = window.location.toString().replace(/\/$|\/index.*|\/#.*$|\/\?.*$/i, '?pp_resume='+current+'#menu_cntr');
		} else {
			paypalFm.shopping_url.value = window.location.toString().replace(/\/$|\/index.*|\/#.*$|\/\?.*$/i, '?pp_resume='+current);
			paypalViewFm.shopping_url.value = window.location.toString().replace(/\/$|\/index.*|\/#.*$|\/\?.*$/i, '?pp_resume='+current);
		}
	}
	if (q.pp_resume) {
		window.setTimeout("animatedcollapse.show('purch_cntr_bg');animatedcollapse.show('purch_cntr');", 250);
		window.setTimeout("scrollThms(current);", 250);
	}

	if (ss_autorun === true) {
		window.setTimeout("ssResume();", ss_interval);
	}
	return ssRunning;
}


function safeStart() {
	if (imgs[current].height < 50) {
		window.setTimeout("safeStart()", 50);
		return;
	} else {
		posImgs(current, img_h_position, img_v_position);
		lastRun = new Date();
		if (fadeComplete === true) {
			if (ssRunning) { window.clearTimeout(ssRunning); }
			if (thm_scroll_TO) { window.clearTimeout(thm_scroll_TO); }
			return current, current_fr, nIndex;
		}
	}	
}

function ssPoller(arg) {
	var rnow = new Date();
	if ((rnow - lastRun) > ss_resume_interval) {
		if (ssRunning) { window.clearTimeout(ssRunning); }
		if (fadeComplete !== true) {
			return;
		}
		else {
			ssResume();
		}
	}
}



function ssPause(dir_arg) {
	if (fadeComplete === true) { 
		if (ssPauseTO) { window.clearTimeout(ssPauseTO); }
		if (ssRunning) { window.clearTimeout(ssRunning); }
		if (thm_scroll_TO) { window.clearTimeout(thm_scroll_TO); }
		nPause = 'paused';
		if (dir_arg === 0) {
			if (ssPlayCntr) {
				ssPlayCntr.style.display = 'block';
				ssPauseCntr.style.display = 'none';
			}
			return;
		} else {
			dir = dir_arg;
			getImgsToFade(current, current_fr, nPause, -1);
			return nPause, ssRunning, dir;
		}
	}
	else { 
		// try again later
		ssPauseTO = window.setTimeout("ssPause("+dir_arg+")", 50);
		return ssPauseTO;
	}
}

function ssResume() {
	if (isitIE === true) {
		fadeComplete = true;
	}
	if (fadeComplete === true) {
		if (ssRunning) { window.clearTimeout(ssRunning); }
		if (ssPauseTO) { window.clearTimeout(ssPauseTO); }
		if (thm_scroll_TO) { window.clearTimeout(thm_scroll_TO); }
		if ((!nPause) || (nPause == 'paused')) {
			nPause = 'resume';
			resumeToggle = 'run';
		} else if (nPause == 'run') { 
			nPause = 'resume';
			resumeToggle = 'paused';
		} else if (nPause == 'resume') {
			if (resumeToggle == 'run') {
				resumeToggle = 'paused';
			} else {
				resumeToggle = 'run';
			}
		}
		getImgsToFade(current, current_fr, nPause);
		return nPause, resumeToggle;//, ssPoll;
	} else {
		window.setTimeout("ssResume()", 25);
	}
}






//var resized = false;
//----- resize imgs and layout on window resize
//addEvent(window, 'resize', function() {
//	posImgs(current,'resz');
//	resized = true;
//});
//posImgs args: num = index of this img in imgs[] array, hpos = 'left'|'center'|'right', vpos = 'top'|'middle'|'bottom'
function posImgs(num,hpos, vpos) {
	imgs[num].style.visibility = 'hidden';
	if ((imgs[num].offsetWidth < 50) || (imgs[num].offsetHeight < 50)) {
		window.setTimeout("posImgs("+num+",'"+hpos+"'"+",'"+vpos+"');", 50);
		return;
	}
	
	if (layout_sm === true) { 
		var ss_cntrW = 315;//ssCntr.offsetWidth;
		var ss_cntrH = ssCntr.offsetHeight;
		var imgW = imgs[num].width;//offsetWidth;
		var imgH = imgs[num].offsetHeight;
	} else {
		var ss_cntrW = 315;//ssCntr.offsetWidth;
		var ss_cntrH = ssCntr.offsetHeight;
		var imgW = imgs[num].width;//offsetWidth;
		var imgH = imgs[num].offsetHeight;
	}
	
	function chkFit () {
		if (imgs[num].offsetWidth > ss_cntrW) {// ssCntr.offsetWidth) {
			var rsz = (ss_cntrW / imgW);
			imgW = Math.floor(imgW * rsz);
			//alert(imgW);
			imgH = Math.floor(imgH * rsz);
			imgs[num].style.width = imgW + 'px';
			imgs[num].style.height = imgH + 'px';
		}
		if (imgs[num].offsetHeight > ssCntr.offsetHeight) {
			var rsz = (ss_cntrH / imgH);
			imgW = Math.floor(imgW * rsz);
			//alert(imgW);
			imgH = Math.floor(imgH * rsz);
			imgs[num].style.width = imgW + 'px';
			imgs[num].style.height = imgH + 'px';
		}
	}
	if (imgFit === true) {
		chkFit();
	}
//	alert('ss_cntrW = '+ssCntr.offsetWidth+'\n'+
//		'ss_cntrH = '+ssCntr.offsetHeight+'\n'+
//		'imgW = '+imgs[num].offsetWidth+'\n'+
//		'imgH = '+imgs[num].offsetHeight);

	if (imgGrow === true) {
		if (imgs[num].offsetWidth < ssCntr.offsetWidth) {
			var rsz = (ss_cntrW / imgW);
			imgW = Math.floor(imgW * rsz);
			imgH = Math.floor(imgH * rsz);
			imgs[num].style.width = imgW + 'px';
			imgs[num].style.height = imgH + 'px';
			chkFit();
		}
		if (imgs[num].offsetHeight < ssCntr.offsetHeight) {
			var rsz = (ss_cntrH / imgH);
			imgW = Math.floor(imgW * rsz);
			imgH = Math.floor(imgH * rsz);
			imgs[num].style.width = imgW + 'px';
			imgs[num].style.height = imgH + 'px';
			chkFit();
		}
	}

	
	
	var img_h_position_setBack = hpos, capH, capP; 
	if (altWideLayout === true) {
		if (layout_sm === true) { 
			imgWmax = 315;
			ss_cntrWmax = 315;
			capH = '189px';
			capP = '241px 0 0 0';
		} else {
			imgWmax = 315;
			ss_cntrWmax = 315;
			capH = '239px';
			capP = '351px 0 0 0';
		}
		if (((altWideLayout === true) && (imgW > imgWmax)) || ((altWideLayout === true) && (slideshow[num].caption1 == '') && (slideshow[num].caption2 == ''))) {//ss_cntrW)) {
			ssCntr.style.width = ss_cntrWmax + 'px';
			ss_cntrW = ss_cntrWmax;
			captionsCntr.style.height = '1px';
			captionsCntr.style.padding = '0';
			useWideLayout = true;
			hpos = 'center';
		} else {
			ssCntr.style.width = imgWmax + 'px';
			ss_cntrW = imgWmax;
			captionsCntr.style.height = capH;
			captionsCntr.style.padding = capP;
			useWideLayout = false;
			hpos = img_h_position_setBack;
		}
	}

	
	if (hpos === 'left' || !hpos) {
		imgs[num].style.left = 0 + 'px';
	}
	if (hpos === 'center') {
		imgs[num].style.left = Math.round(parseInt((ss_cntrW - imgW) / 2)) + 'px';
	}
	if (hpos === 'right') {
		imgs[num].style.left = Math.round(parseInt(ss_cntrW - imgW)) + 'px';
	}
	if (vpos === 'top' || !vpos) {
		imgs[num].style.top = 0 + 'px';
	}
	if (vpos === 'middle') {
		imgs[num].style.top = Math.round(parseInt((ss_cntrH - imgH) / 2)) + 'px';
	}
	if (vpos === 'bottom') {
		imgs[num].style.top = Math.round(parseInt(ss_cntrH - imgH)) + 'px';
	}
	imgs[num].style.visibility = 'visible';
}







//auto scroll the thumbs into view if necessary...
function scrollThms(fadingIn) {//alert(scrolling);
	if (scrolling === true) { return; } //alert('isitIE6: '+isitIE6+'\nisitIE7: '+isitIE7+'\nisitIE8: '+isitIE8)
	if (scrollingDisabled === true) { return; }
	var thmScrSpeed = 4, intThmsPerPg, thmLmin, thmLmax, thmPos, thmScrAmt, scrL = false, thmAutoScr, i;
	intThmsPerPg = thmsPerPg;
	if ((isitIE6 || isitIE7) && !isitIE8) { //alert(navigator.appVersion);
		thmLmin = thms[1].offsetParent.offsetParent.offsetLeft;
		thmLmax = thms[intThmsPerPg - 2].offsetParent.offsetParent.offsetLeft;
		thmPos = thms[fadingIn].offsetParent.offsetParent.offsetLeft + thmsScrCntr.offsetParent.offsetLeft;//parseInt(thmsScrCntr.style.left, 10);
		//alert(thmLmin+'\n'+thmLmax+'\n'+thmPos);
	} else {
		thmLmin = thms[1].offsetParent.offsetParent.offsetLeft;
		thmLmax = thms[intThmsPerPg - 2].offsetParent.offsetParent.offsetLeft;
		thmPos = thms[fadingIn].offsetParent.offsetParent.offsetLeft + thmsScrCntr.offsetParent.offsetLeft;
	}
//		alert(thmsScrCntr.offsetParent.offsetLeft);
	if (thmPos < thmLmin) {
		thmScrAmt = thmLmin - thmPos;
		scrL = true
	} else if (thmPos > thmLmax) {
		thmScrAmt = thmPos - thmLmax;
	} else { 
		thmScrAmt = 0;
		scrolling = false;
		return;
	}
	if (thmScrAmt > 500) {
		thmScrSpeed *= 5;
		if (thmScrAmt > 1500) {
			thmScrSpeed *= 8;
		}
	}
	if (thmScrAmt === 0) { return; }
	
	for (i = 0; i < Math.ceil(thmScrAmt/thmScrSpeed); i++) {
		scrolling = true;
		if (scrL) {
			thmAutoScr = window.setTimeout("fleXcrollTo(ss_thumb_cntr_id,'-"+thmScrSpeed+"px',false,true);", i*25);
		} else {
			thmAutoScr = window.setTimeout("fleXcrollTo(ss_thumb_cntr_id,'"+thmScrSpeed+"px',false,true);", i*25);
		}
	}
	if (thmAutoScr) { window.clearTimeout(thmAutoScr); }
	scrolling = false;
}

//------------------- scrolling function for thumbs div ---------------------
function fleXcrollTo(id,x,y,relative,from_thms_arw) {

	var scrollDiv = document.getElementById(id);
	//Return if the target is null
	if (scrollDiv === null) {
		return;
	}//Do the scroll by using custom method attached by fleXcroll
	//but first check if the method exists.
	if (scrollDiv.contentScroll) { 
		sPos = scrollDiv.contentScroll(x,y,relative);
	}
	if (rewindThumbs === true) {
		loopThumbs = false;
		if (from_thms_arw) {
			if (sPos[0][0] == sPos[0][1]) {
				stopScroll();
				cscr = window.setTimeout("scrollThms(0);", rewindDelay);
			}
			if (sPos[0][0] == 0) {
				stopScroll();
				cscr = window.setTimeout("scrollThms("+(thms.length - 1)+");", rewindDelay);
			}
		}
	} else if (loopThumbs === true) {
		if (from_thms_arw) {
			if (sPos[0][0] == sPos[0][1]) {// alert(sPos[0][1]);
				stopScroll();
				cscr = window.setTimeout("fleXcrollTo(ss_thumb_cntr_id, '0px', false, false);", loopEndDelay);
				scr = window.setTimeout("contScroll(1);", (loopEndDelay + loopResumeDelay));
			}
			if (sPos[0][0] == 0) {
				stopScroll();
				cscr = window.setTimeout("fleXcrollTo(ss_thumb_cntr_id, '"+sPos[0][1]+"px', false, true);", loopEndDelay);
				scr = window.setTimeout("contScroll(-1);", (loopEndDelay + loopResumeDelay));
			}
		}
	} else if (hideScrollArrows === true) {
			if (sPos[0][0] == sPos[0][1]) {
				stopScroll();
				$('#thmArwR_cntr').css('visibility','hidden');
				$('#thmArwL_cntr').css('visibility','visible');
			} else if (sPos[0][0] == 0) {
				stopScroll();
				$('#thmArwR_cntr').css('visibility','visible');
				$('#thmArwL_cntr').css('visibility','hidden');
			} else {
				$('#thmArwR_cntr').css('visibility','visible');
				$('#thmArwL_cntr').css('visibility','visible');
			}
	}
}
var cscr;
// for the thumbs arrows
function contScroll(n) {
	if (scrolling === true) { return; }
	if (ssRunning) { window.clearTimeout(ssRunning); }
	if (scr) { window.clearInterval(scr); }
	scr = window.setInterval("fleXcrollTo(ss_thumb_cntr_id,'" + n*6 + "px',false,true,true)",25);
}
function stopScroll() {
	if (scr) { window.clearInterval(scr); }
	if (cscr) { window.clearTimeout(cscr); }
	scrolling = false;
	//alert(sPos[0][1]);
	//sPos[0][0] is current position
	//sPos[0][1] is total length (max position)
}

//-----------------------------------------------------------------------------




function getImgsToFade(current, current_fr, nPause, nIndex) {
	if (current == nIndex) {
		if(ssPlayCntr) {
			ssPlayCntr.style.display = 'block';
			ssPauseCntr.style.display = 'none';
		}
		ssPause(0);
		return;
	}
	if (fadeComplete === false) { return; } else { fadeComplete = false; }
	if (ssRunning) { window.clearTimeout(ssRunning); }
	if (thm_scroll_TO) { window.clearTimeout(thm_scroll_TO); }
	
	var fadingOut = current, fadingOut_fr = current_fr, fadingIn, fadingIn_fr, ss_TO=(ss_fade_duration+150);
	fadingIn_fr = ((current_fr === 0) ? 1 : 0);
	if (nIndex > -1) {  //alert(nIndex);// direct call from thumbnails, we know what imgs to fade...
		fadingIn = nIndex;
		nPause = 'paused';
		if (ssPlayCntr) {
			ssPlayCntr.style.display = 'block';
			ssPauseCntr.style.display = 'none';
		}
	} else {
		if (nPause == 'paused') { // make clicked thumb's image the next image to fade in
			if (current+dir < 0) {
				fadingIn = ssn - 1;
			} else {
				fadingIn = imgs[current + dir]?current+dir:0;
			}
			if (ssPlayCntr) {
				ssPlayCntr.style.display = 'block';
				ssPauseCntr.style.display = 'none';
			}
		} else if (nPause == 'resume') { //alert('resume')
			fadingIn = imgs[current+1]?current+1:0;
			nPause = resumeToggle;
			if (resumeToggle == 'paused') {
				if (ssPlayCntr) {
					ssPlayCntr.style.display = 'block';
					ssPauseCntr.style.display = 'none';
				}
			} else {
				ss_TO = (ss_interval+150);
				if (ssPlayCntr) {
					ssPlayCntr.style.display = 'none';
					ssPauseCntr.style.display = 'block';
				}
			}
		} else if (nPause == 'run') { //alert('run')
			if (ssPlayCntr) {
				ssPlayCntr.style.display = 'none';
				ssPauseCntr.style.display = 'block';
			}
			fadingIn = imgs[current+1]?current+1:0;
			ss_TO = (ss_interval+150);
		}
	}

//	if (fadingOut === fadingIn) { 
//		return;
//	}
//	if (fadingIn == null) { 
//		return;
//	}
//	
	posImgs(fadingIn, img_h_position, img_v_position);
	
	ssCntr.appendChild(imgs[fadingIn]);
	imgs[fadingIn].display = 'block';
	$("#"+imgs[fadingOut].id).fadeOut(ss_fade_duration);
	$("#"+imgs[fadingIn].id).fadeIn(ss_fade_duration, function(){shw_fade(fadingOut,fadingIn,fadingOut_fr,fadingIn_fr,nPause);});
	
	if (thmsCntr) {
		if (thms_behavior === 'scrolly') {
			thm_scroll_TO = window.setTimeout("scrollThms("+fadingIn+");", ss_fade_duration);
		}
		if (thms_linkFading === true) {
			$("#"+thms[fadingOut].id).fadeTo(ss_fade_duration,thms_minOpacity);
			$("#"+thms[fadingIn].id).fadeTo(ss_fade_duration,1);
		}
	}
	if (titleCntr) {
		titles[fadingIn_fr].innerHTML = slideshow[fadingIn].title.replace(/ /g, '&nbsp;');
		if (titles_linkFading === true) {
			$("#title_txt_"+fadingOut_fr).fadeOut(ss_fade_duration);
			$("#title_txt_"+fadingIn_fr).fadeIn(ss_fade_duration);
		}
	}
	
	if (captionsCntr) {
		var c1p='', c1a='', c2p='', c2a='';
		if (slideshow[fadingIn].caption1) { c1p = caption1Pre; c1a = caption1App; }
		if (slideshow[fadingIn].caption2) { c2p = caption2Pre; c2a = caption2App; }
		function doAltCaptions (useWideLayout) {//alert(useWideLayout);
			if (useWideLayout !== true) {
				captionsCntr.appendChild(captions[fadingIn_fr]);
				$("#"+captions[fadingIn_fr].id).html(c1p + slideshow[fadingIn].caption1 + c1a  + c2p + slideshow[fadingIn].caption2 + c2a);
				$("#caption_txt_"+fadingOut_fr).fadeOut(ss_fade_duration);
				$("#caption_txt_"+fadingIn_fr).fadeIn(ss_fade_duration);
				$("#alt_caption_txt_"+fadingOut_fr).fadeOut(ss_fade_duration);
				$("#alt_caption_txt_"+fadingIn_fr).fadeIn(ss_fade_duration);
			} else {
				alt_captionsCntr.appendChild(captions[fadingIn_fr]);
				$("#"+captions[fadingIn_fr].id).html(c2p + slideshow[fadingIn].caption2 + c2a + c1p + slideshow[fadingIn].caption1 + c1a);
				$("#caption_txt_"+fadingOut_fr).fadeOut(ss_fade_duration);
				$("#caption_txt_"+fadingIn_fr).fadeIn(ss_fade_duration);
				$("#alt_caption_txt_"+fadingOut_fr).fadeOut(ss_fade_duration);
				$("#alt_caption_txt_"+fadingIn_fr).fadeIn(ss_fade_duration);
			}	
		}
		var func = function()
        {
            doAltCaptions(useWideLayout);
        }
        window.setTimeout(func, 100);
	}

	//ssRunning = window.setTimeout("shw_fade("+fadingOut+","+fadingIn+","+fadingOut_fr+","+fadingIn_fr+",'"+nPause+"');", ss_TO);
	nIndex = fadingIn;
	
	return current, current_fr, nIndex, nPause, ssRunning;
}
	



function shw_fade(fOut,fIn,frfOut,frfIn,nPause) {
	var fading, fadingOut = imgs[fOut], fadingIn = imgs[fIn], fadingOutThm = thms[fOut], fadingInThm = thms[fIn], fadingOutTitle = titles[frfOut], fadingInTitle = titles[frfIn];//, fadingOutCaption1 = captions1[frfOut], fadingInCaption1 = captions1[frfIn], fadingOutCaption2 = captions2[frfOut], fadingInCaption2 = captions2[frfIn], fadingOutCaption = captions[frfOut], fadingInCaption = captions[frfIn];
	if (fOut == fIn) {
		fadeComplete = true;
		return;
	}
//	if (!fadingIn) {
//		return;
//	}
		$("#ss_cntr > img:not(#ssImg_"+fIn+")").remove();
		
		if ((thmsCntr) && (thms_linkFading === true)) {
			fadingInThm.onmouseout = function() {
				this.xOpacity = 1;
				this.style.filter = "alpha(opacity=100)";
				this.style.MozOpacity = "1";
				this.style.opacity = "1";
	
			};
			fadingOutThm.onmouseout = function() {
				this.xOpacity = thms_minOpacity;
				this.style.filter = "alpha(opacity="+(thms_minOpacity*100)+")";
				this.style.MozOpacity = thms_minOpacity.toString();
				this.style.opacity = thms_minOpacity.toString();
			};
		}
		if (showImgsTitleAtt === true) {
			glassCntr.title = (fIn + 1) + " of " + ssn;
		}
		if (paypalFm) {
			paypalFm.item_number.value = (slideshow[fIn].image.replace(/\.[a-z]{3}/, '')) + '_img.' + (fIn + 1);
			if ($(window).height() < 725) {
				paypalFm.shopping_url.value = window.location.toString().replace(/\/$|\/index.*|\/#.*$|\/\?.*$/i, '?pp_resume='+fIn+'#menu_cntr');
				paypalViewFm.shopping_url.value = window.location.toString().replace(/\/$|\/index.*|\/#.*$|\/\?.*$/i, '?pp_resume='+fIn+'#menu_cntr');
			} else {
				paypalFm.shopping_url.value = window.location.toString().replace(/\/$|\/index.*|\/#.*$|\/\?.*$/i, '?pp_resume='+fIn);
				paypalViewFm.shopping_url.value = window.location.toString().replace(/\/$|\/index.*|\/#.*$|\/\?.*$/i, '?pp_resume='+fIn);
			}
		}
		//------- reset --------
		fOut = fIn;
		frfOut = frfIn;
		lastRun = new Date();
		fadeComplete = true;
		if (nPause == 'run') {
			ssRunning = window.setTimeout("getImgsToFade("+fOut+", "+frfOut+", '"+nPause+"');", ss_interval)
			resumeImg = fOut;
		} else {
			window.clearTimeout(ssRunning);
		}
		current = fOut;
		current_fr = frfOut;
}

// ------------------------------------------------------------------------------------------------------------------------




//---------------- oversize images flyout layout ------------------------------
//var oSizeImg;
//var ztUh = 800;
//var ztDw = 0;
//var ztDh = 0;
//var ztw = ztDw, zth = ztDh;
//var ztUw = 1000;
//var ztwincr = 50;
//var zthincr = 45;
//var tipIsUp = false;
//var tipIsDown = false;
//var slidingUp = false;
//var slidingDown = false;
//var full_scr_cntr;
//var fs_content_wrapper;
//function show_oSize() {
//	if(!full_scr_cntr) { return };
//	if((slidingUp == true) || (slidingDown == true)) { 
//		window.setTimeout('show_oSize()', 100);
//		return;
//	}
//	if((tipIsUp == true)) {//hide
//		full_scr_cntr.style.visibility = 'hidden';
//		oSize_cntr.innerHTML = '';
//		contract_oSize();
//	} else {
////		ztUh = full_scr_cntr.offsetHeight;
//		oSizeImg = new Image();
//		var img_p = document.createElement('p');
//		img_p.style.width = '100px';
//		oSizeImg.src = slideshow.oSizeFolder + slideshow[current].image;
//		oSizeImg.onclick = function() { show_oSize(); }
//		img_p.appendChild(oSizeImg);
//		oSize_cntr.appendChild(img_p);
//		oSizeImg.style.visibility = 'hidden';
//		oSize_cntr.style.visiblity = 'hidden';
//		oSize_bg.style.visibility = 'visible';
//		expand_oSize();
//	}
//}
//function expand_oSize() {
//	if(tipIsUp == true) return;
//	ztw += ztwincr; if(ztw>ztUw)ztw=ztUw;
//	zth += zthincr; if(zth>ztUh)zth=ztUh;
//	if((ztw==ztUw)&&(zth==ztUh)) {
//		oSize_bg.style.width = ztw + 'px';
//		oSize_bg.style.height = zth + 'px';
//		oSize_cntr.style.width = (oSize_bg.offsetWidth - (oSize_bg.offsetWidth - oSizeImg.width)) + 'px';
//		oSize_cntr.style.height = zth + 'px';
//		oSize_cntr.style.top = (-1 * oSize_cntr.offsetTop) +  ((oSize_cntr.offsetHeight - oSizeImg.height) / 2) + "px";
//		//oSize_cntr.style.left = parseInt(((oSize_bg.offsetWidth - oSizeImg.width) / 2) / 2) + 'px';
//		oSize_cntr.style.visibility = "visible";
//		oSizeImg.style.visibility = "visible";
//		full_scr_cntr.style.visibility = 'visible';
//		slidingUp = false;
//		tipIsUp = true;
//		tipIsDown = false;
//		return;
//	} else {
//		slidingUp = true;
//		tipIsUp = false;
//		oSize_bg.style.width = ztw + 'px';
//		oSize_bg.style.height = zth + 'px';
//		oSize_cntr.style.width = ztw + 'px';
//		oSize_cntr.style.height = zth + 'px';
//		window.setTimeout('expand_oSize()', 20);
//		return;
//	}
//}
//function contract_oSize() {
//	if(tipIsDown == true) return;
////	fleXcrollTo('oSize_cntr',false,'0px',false);//reset scroll pos for next img
//	ztw -= ztwincr + 30; if(ztw<ztDw)ztw=ztDw;
//	zth -= zthincr + 30; if(zth<ztDh)zth=ztDh;
//	if((ztw==ztDw)&&(zth==ztDh)) { 
//		oSize_bg.style.width = ztw + 'px';
//		oSize_bg.style.height = zth + 'px';
//		oSize_cntr.style.width = ztw + 'px';
//		oSize_cntr.style.height = zth + 'px';
//		oSize_cntr.style.top = "-" + ztDh + "px";
//		full_scr_cntr.style.visibility = 'hidden';
//		slidingDown = false;
//		tipIsDown = true;
//		tipIsUp = false;
//		return;
//	} else {
//		slidingDown = true;
//		tipIsDown = false;
//		oSize_bg.style.width = ztw + 'px';
//		oSize_bg.style.height = zth + 'px';
//		oSize_cntr.style.width = ztw + 'px';
//		oSize_cntr.style.height = zth + 'px';
//		window.setTimeout('contract_oSize()', 30);
//		return;
//	}
//}

function chkCntrPos(elem) {
	if ((isOffPage(elem) == true) ) { 
		window.setTimeout("document.getElementById('"+elem+"').scrollIntoView(false);", 1000);
	}
}

function isOffPage(elem)
{
	var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
	//alert(viewportHeight);

	var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + viewportHeight;

    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();

    return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom)
      && (elemBottom <= docViewBottom) &&  (elemTop >= docViewTop) );
}





