$(document).ready(function() {
	// ------------   Load logo   ------------
	var flashvars = { strLanguage: "english" };
	var params = {	allowScriptAccess:"always", menu: "false", wmode: "transparent"	};
	var attributes = false;
	swfobject.embedSWF(baseURL+"multimedia/logo.swf", "mainLogo", "226", "268", "8.0.0", baseURL+"images/expressInstall.swf", flashvars, params, attributes);
	// ---------------------------------------

	logoInteraction ( "allSoundPause" );

	// ---------- Header login form ----------
	$('#headerUsername, #headerPassword')
	.focus(function () {	$(this).css('backgroundPosition','19px 200px');	})
	.blur(function ()
	{	if ( $(this).val() == "" )
		{	$(this).css('backgroundPosition','19px 6px');	}
	});
	$('#headerUsername, #headerPassword').each(function () {
		if ( $(this).val() != "" )
		{	$(this).css('backgroundPosition','19px 200px');	}
	});
});

// ------- Load the features flash -------
function loadFeatures ()
{	// Load the main shishavac page
	var flashvarsFeatures = { strLanguage: "english" };
	var paramsFeatures = {	allowScriptAccess:"always", menu: "false", wmode: "transparent"	};
	var attributesFeatures = false;
	swfobject.embedSWF(baseURL+"multimedia/features.swf", "featuresFlash", "915", "515", "9.0.0", baseURL+"images/expressInstall.swf", flashvarsFeatures, paramsFeatures, attributesFeatures);
}

// ------- Load the Homepage flash -------
function loadHomepage ()
{	// Load the main shishavac page
	var flashvarsHome = { strLanguage: "english", dealerLink: baseURL+"purchase/dealers/", demoLink: baseURL+"shishavac/video/shishaDemo2009/" };
	var paramsHome = {	allowScriptAccess:"always", menu: "false", wmode: "transparent"	};
	var attributesHome = false;

	//window.location = "http://www.shishavac.com/includes/sliders.php"
	//swfobject.embedSWF( "http://www.shishavac.com/includes/sliders.php", "mainHomeFlash", "626", "350", "9.0.0", baseURL+"images/expressInstall.swf", flashvarsHome, paramsHome, attributesHome);
	//swfobject.embedSWF(baseURL+"multimedia/english/main.swf", "mainHomeFlash", "626", "350", "9.0.0", baseURL+"images/expressInstall.swf", flashvarsHome, paramsHome, attributesHome);
    //$("#mainHomeFlash").load("http://www.shishavac.com/includes/sliders.php");

  // this/handles the pop up in the 2nd screen of the shishavac page

$(document).ready(function() {
			$("#popupvideo").fancybox({
				'width'				: 560,
				'height'			: 315,
				'autoScale'			: false,
				'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'type'				: 'iframe'
			});

	/* This code is executed after the DOM has been completely loaded */

	var totWidth=0;
	var positions = new Array();

    clearInterval(itvl);

	$('#slides .slide').each(function(i){

		/* Traverse through all the slides and store their accumulative widths in totWidth */

		positions[i]= totWidth;
		totWidth += $(this).width();

		/* The positions array contains each slide's commulutative offset from the left part of the container */

		if(!$(this).width())
		{
			alert("Please, fill in width & height for all your images!");
			return false;
		}

	});

	$('#slides').width(totWidth);

	/* Change the cotnainer div's width to the exact width of all the slides combined */

	$('#menu ul li a').click(function(e,keepScroll){

			/* On a thumbnail click */

			$('li.menuItem').removeClass('act').addClass('inact');
			$(this).parent().addClass('act');

			var pos = $(this).parent().prevAll('.menuItem').length;

			$('#slides').stop().animate({marginLeft:-positions[pos]+'px'},450);
			/* Start the sliding animation */

			e.preventDefault();
			/* Prevent the default action of the link */


			// Stopping the auto-advance if an icon has been clicked:
			if(!keepScroll) clearInterval(itvl);
	});

	$('#menu ul li.menuItem:first').addClass('act').siblings().addClass('inact');
	/* On page load, mark the first thumbnail as active */



	/*****
	 *
	 *	Enabling auto-advance.
	 *
	 ****/

	var current=1;
	function autoAdvance()
	{
		if(current==-1) return false;

		$('#menu ul li a').eq(current%$('#menu ul li a').length).trigger('click',[true]);	// [true] will be passed as the keepScroll parameter of the click function on line 28
		current++;
	}

	// The number of seconds that the slider will auto-advance in:

	var changeEvery = 10;

    clearInterval(itvl);
	var itvl = setInterval(function(){autoAdvance()},changeEvery*1000);

	/* End of customizations */
});

}

// ---------- Load the video ad ----------
function loadVideoAd2009 ()
{	var flashvarsVideoClip = { type:'youtube', file:'http://www.youtube.com/watch?v=-dBUP8vX-Fw', image:'none', stretching: "none", skin:baseURL+'multimedia/glow.zip', plugins: "sharing", "sharing.link": "http://www.youtube.com/watch?v=-dBUP8vX-Fw", autostart:'true' };
	var paramsVideoClip = { allowfullscreen:'true', allowscriptaccess:'always', menu: "false", wmode: "transparent" };
	var attributesVideoClip = { id:'videoClipFlash', name:'player1' };
	swfobject.embedSWF(baseURL+'multimedia/player.swf','videoClipFlash','915','515','9.0.115',baseURL+'images/expressInstall.swf',flashvarsVideoClip, paramsVideoClip, attributesVideoClip, loadVideoComplete);
}

// --------- Load the video demo ---------
function loadVideoDemo2009 ()
{	var flashvarsVideoClip = { type:'youtube', file:'http://www.youtube.com/watch?v=cEVREfBxhpY', image:'none', stretching: "none", skin:baseURL+'multimedia/glow.zip', plugins: "sharing", "sharing.link": "http://www.youtube.com/watch?v=cEVREfBxhpY", autostart:'true' };
	var paramsVideoClip = { allowfullscreen:'true', allowscriptaccess:'always', menu: "false", wmode: "transparent" };
	var attributesVideoClip = { id:'videoClipFlash', name:'player1' };
	swfobject.embedSWF(baseURL+'multimedia/player.swf','videoClipFlash','915','515','9.0.115',baseURL+'images/expressInstall.swf',flashvarsVideoClip, paramsVideoClip, attributesVideoClip, loadVideoComplete);
}

// --------- Trigger redirect on video completion ---------
function loadVideoComplete(e)
{
	logoInteraction ( "allSoundPause" );
	jwplayer(e.ref).onComplete(function() { loadNewPage ( baseURL+"shishavac/videos/" ); });
}

