var hash = '';
var currentpage ="default";
var inContent, ext, gIndex, pstatus,sel;

var DOM = {}
var ANIM = {}
var ANALYTICS = {}
DOM.basePageTitle = "SolFX";
DOM.baseExtension = '.aspx';
DOM.navActivator = "#ulMainNav li a, #ulTerms li a, #goHome, #quickLinks li a.social, #quickLinks li a.mail, .drivewearLink, .akumaLink, .shieldDemoLink, #drivewearNav a, #DWpnlWidget, #DWpnlDemo, #pnlDWfoot a";
DOM.ajaxContainer = "ajaxContainer";
DOM.contentContainer = "content";
DOM.navActiveClass = "active";
DOM.navActiveClassParent = "current_item_parent";
ANIM.typeEnter = {"opacity" : 1};
ANIM.typeExit = {"opacity" : 0};
ANIM.typeEasing = {};
ANIM.typeCallback = {};
ANIM.speed = 300;
ANALYTICS.google = true;
ANALYTICS.omniture = false;
ANALYTICS.webtrends = false;
ANALYTICS.reinvigorate = false;
//--------------------- Carousel -----------------------//
var cSquarePos = 1;

$(function(){	
	// apply to all png images and to class 'pngFix'
	 $('.pngFix').ifixpng();
	
	if($("body")[0].className.match("WheretoGetThem")){ WTabs.setupTabs();	}
	
	if($("#ulTabs")[0]){
		//Tab Navigation
		tabs = $("#ulTabs").tabs({
			select: function(event, ui) {
				var selectedTab = ui.index + 1;
				var currentClass = "selectedTab" + selectedTab;
				$("#ulTabs li a.mainTab").removeClass("selectedTab1 selectedTab2 selectedTab3 selectedTab4 selectedTab5");
				$("#ulTabs li a.mainTab").addClass(currentClass);
			}
		});
		if(window.location.hash != '') {
			var selectedTab = window.location.hash;
			selectedTab = selectedTab.substring(1,selectedTab.length);
			tabs.tabs('select', '#tabs-'+selectedTab);
			$("#ulTabs li a.mainTab").removeClass("selectedTab1 selectedTab2 selectedTab3 selectedTab4 selectedTab5");		
			var currentClass = "selectedTab" + selectedTab;
			$("#ulTabs li a.mainTab").addClass(currentClass);
			$("#ulTabs a")[0].focus();
		}
		
		$("#ulTabs-drivewear").tabs({
			select: function(event, ui) {
				var selectedTab = ui.index+1;			
				var currentClass = "selectedTab-road" + selectedTab;
				$("#ulTabs-drivewear li a.roadTab").removeClass("selectedTab-road");
				$("#ulTabs-drivewear ul li:nth-child("+selectedTab+") a.roadTab").addClass("selectedTab-road");			
			}
		});
	}
		   
		   
	//-------------------Flash Replacements
	/*$('#content.shieldProductDemo #demoArea').flash({
		src: 'Flash/akumaStandalone.swf?urlbase=Flash/languageXml/english_akumastandalonesmall%2Exml',
		width: 960,
		height: 485,
		wmode: 'transparent',
		flashvars: { initScene: 'road', roadScene: 'bike' }
	}, {expressInstall: true});*/
	
	$('.EN #actualWidget').flash({
		src: 'Flash/drivewearwidgiead.swf',
		width: 300,
		height: 250,
		wmode: 'transparent'
	}, {expressInstall: true});
	$('.ES #actualWidget').flash({
		src: '../Flash/drivewearwidgiead.swf',
		width: 300,
		height: 250,
		wmode: 'transparent'
	}, {expressInstall: true});
	$('.FR #actualWidget').flash({
		src: '../Flash/drivewearwidgiead.swf',
		width: 300,
		height: 250,
		wmode: 'transparent'
	}, {expressInstall: true});
	
	$('#content.experienceVideo #pnlVideo').flash({
		src: 'Flash/player.swf',
		width: 640,
		height: 410,
		wmode: 'transparent',
		flashvars: { src: '../Video/sunglass031209_hsfl_hi-2.flv', slate: 'images/videoSlate.jpg' }
	}, {expressInstall: true});
	
	$('.EN #pnlHomeFlash').flash({
		//src: 'Flash/SOLFX_Header.swf?urlbase=Flash/languageXml/english_header.xml',
		//URL encode "." characters for use in IE
		src: 'Flash/SOLFX_Header.swf?urlbase=Flash/languageXml/english_header%2Exml',
		width: 960,
		height: 393
	}, {expressInstall: true});
	$('.ES #pnlHomeFlash').flash({
		src: '../Flash/SOLFX_Header.swf?urlbase=%2E%2E/Flash/languageXml/spanish_header%2Exml',
		width: 960,
		height: 393
	}, {expressInstall: true});
	$('.FR #pnlHomeFlash').flash({
		src: '../Flash/SOLFX_Header.swf?urlbase=%2E%2E/Flash/languageXml/french_header%2Exml',
		width: 960,
		height: 393
	}, {expressInstall: true});
	
	
	/*$('.EN #content.interactiveDemo').flash({
		src: 'Flash/Selection_Screen.swf?urlbase=Flash/languageXml/english_Selection_Screen%2Exml&urlbase2=Flash/languageXml/english_general_demo%2Exml',
		width: 960,
		height: 485,
		wmode: 'transparent'
	}, {expressInstall: true}); 
	$('.FR #content.interactiveDemo').flash({
		src: '../Flash/Selection_Screen.swf?urlbase=%2E%2E/Flash/languageXml/french_Selection_Screen%2Exml&urlbase2=%2E%2E/Flash/languageXml/french_general_demo%2Exml',
		width: 960,
		height: 485,
		wmode: 'transparent'
	}, {expressInstall: true});
	$('.ES #content.interactiveDemo').flash({
		src: '../Flash/Selection_Screen.swf?urlbase=%2E%2E/Flash/languageXml/spanish_Selection_Screen%2Exml&urlbase2=%2E%2E/Flash/languageXml/spanish_general_demo%2Exml',
		width: 960,
		height: 485,
		wmode: 'transparent'
	}, {expressInstall: true});*/
		   
	//-------------------What is Drivewear
	if(currentpage.match("road") || location.href.match("road")){
		AppPopUp();
	}
	
	//-------------------Testimonials Page
	if(currentpage.match("road") || location.href.match("road")){
		$(".lightbox").click(function(){ 
			var vList = $(".lightbox");
			var index;
			for(i=0;i<vList.length;i++){ 
				if(vList[i] == this) { index = i;}
			}
			openLightBox(index); 
			return false;
		});
		//TempTestimonialsIEfix();
	}
	
	//-------------------Drivewear Widget
	$('#blogMyspace').click(function(){
		$('#pnlEmbedWidget').removeAttr('style');
		$('#pnlEmbedWidget').css({'opacity':'1'});
		return false;
	});
	$('#lnkCloseCode').click(function(){
		$('#pnlEmbedWidget').attr('style', 'display: none;');
		$('#pnlEmbedWidget').css({'opacity':'0'});
		return false;
	})
	mainDemoNav();
	
	$('.btnNext').click(function() {
	  	cSquarePos++;
	});
	$('.btnPrev').click(function() {
	  	cSquarePos--;
	});
	
	for(var i=0;i<$(".carouselHolder ul li").length;i++){
		if(i==0){
			$(".carouselHolder #carouselSquares").append("<span class='square active' id='cSq"+(i+1)+"'></span>");		
		}else{
			$(".carouselHolder #carouselSquares").append("<span class='square' id='cSq"+(i+1)+"'></span>");	
		}
	}
	
	$(".carouselHolder").removeClass("hide");
    $(".carouselHolder").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		auto: 3000,
		visible: 1,
		afterEnd: function(a){
			var cSquarePos = -1 * (parseInt($(".carouselHolder ul").css("left"))/320);
			
			if(cSquarePos>($(".carouselHolder ul li").length-1)){
				cSquarePos = 1;
			}
			/*if(cSquarePos<0){
				cSquarePos = 10;	
			}*/
			if(cSquarePos==0){cSquarePos=1;}
			
			$(".carouselHolder #carouselSquares .square").removeClass("active");
			$(".carouselHolder #carouselSquares #cSq"+Math.round(cSquarePos)).addClass("active");
			/*cSquarePos--;
			var styleString = "0px -" + cSquarePos * 11 + "px";
			
			$(".carouselHolder #carouselSquares").css("background-position",  styleString);*/
		}
	});
});
//------------------Interactive Demo Navigation-----------------------//
function mainDemoNav() 
{
	$(".iSubnav").bind("mouseenter",function(){
		$(this).children("ul").css({"display":"block","opacity":"0","position":"relative","top":"-30px"});
		$(this).children("ul").animate({"top":"0px","opacity":"1"},300);								 
	});
	$(".iSubnav").bind("mouseleave",function(){
		$(this).children("ul").animate({"top":"-30px","opacity":"0"},300,function(){
			$(this).children("ul").css({"display":"none"});
		});								 
	});
}
//------------------Thickbox-Style Pop-up Script-----------------------//
function openLightBox(index) 
{
	ext = '<a href="#" class="closeBTN">&nbsp;</a><a href="http://www.drivewearlens.com/find_ecp.php" title="Where to Get Drivewear" class="whereToBTN" target="_blank">Where to get Drivewear</a><a href="#" class="prevBTN">&nbsp;</a><a href="#" class="nextBTN">&nbsp;</a>';
	$("#content").append('<a id="popUpOverlay" href="#" style="display:none"></a><div id="popUpContent" style="display:none"><div class="detail">'+ext+'<div class="dwcopy"></div></div></div>');
	$("#popUpOverlay, #popUpContent").fadeIn(ANIM.speed);
	//Event Listeners for New Buttons
	$("#popUpOverlay, .closeBTN").click(function(){ closeLightBox();return false; });
	$(".prevBTN").click(function(){ switchContent(gIndex-1);return false; });
	$(".nextBTN").click(function(){ switchContent(gIndex+1);return false; });
	//pull in content from ".content" under selected link and place into Light Box
	var inContent = $(".lightbox:eq("+index+") .content")[0].innerHTML;
	$("#popUpContent .detail .dwcopy").append(inContent);
	gIndex = index;
	
	//APPLY PNG FIX HERE!!!
	//$(document).pngFix();
}

function closeLightBox() 
{
	$("#popUpOverlay, #popUpContent").fadeOut(ANIM.speed);
	var me=setTimeout("removeDOM()",ANIM.speed);
}

function switchContent(num) 
{
	if(num<0) { num=$(".lightbox").length-1;}
	else if(num>($(".lightbox").length-1)) {num = 0;}
	gIndex = num;
	inContent = $(".lightbox:eq("+num+") .content")[0].innerHTML;
	$("#popUpContent .detail").fadeOut(ANIM.speed);
	var me=setTimeout("emptyAndFade('#popUpContent .detail',(inContent))",ANIM.speed);
}

function emptyAndFade(fieldselector,inContent)
{
	$(fieldselector+" .dwcopy")[0].innerHTML = inContent;
	$(fieldselector).fadeIn(ANIM.speed);
}

function removeDOM() 
{
	$("#popUpOverlay, #popUpContent").remove();	
}


//------------What is Drivewear Applications Pop-up -----------------------//
function AppPopUp() 
{
	//Apply new Styles and content for Javascript version.
	pstatus = "clean";
	$("#content").addClass("jsStyle");
	$("#Applications").append("<a href='#' id='techPlusBtn' class='plusButn pngFix' title='technology'>&nbsp;</a><a href='#' id='perfPlusBtn' class='plusButn pngFix' title='performance'>&nbsp;</a><a href='#' id='stylePlusBtn' class='plusButn pngFix' title='style'>&nbsp;</a>");
	
	//Event Listeners for new buttons
	$("#techPlusBtn, #perfPlusBtn, #stylePlusBtn").click(function(){
		if(pstatus == "clean"){
			var content = $("#"+$(this).attr('title')+"Pnl")[0].innerHTML;
			openAppPopUp($(this).attr('title'),content);
			pstatus = "dirty";
		}
		return false;
	});
}

function openAppPopUp(title,content) 
{
	$("#Applications").append("<div id='appPopUp' class='pop"+title+"'>"+content+"</div>");
	
	if($("html")[0].className.match("msie6") || $("html")[0].className.match("msie7")){
		$("#appPopUp").slideDown(ANIM.speed);//!! IE6 & 7 Both break on this... what if it did something else.
	}else{
		$("#appPopUp").fadeIn(ANIM.speed);//!! IE6 & 7 Both break on this...
	}
	
	$("#appPopUp").bind("mouseleave",function(){
		closeAppPopUp();
	});
}

function closeAppPopUp() 
{
	if($("html")[0].className.match("msie6") || $("html")[0].className.match("msie7")){
		$("#appPopUp").slideUp(ANIM.speed);
	}else{
		$("#appPopUp").fadeOut(ANIM.speed);
	}
	var IEsucksHARD=setTimeout("removeAppFromDOM()",ANIM.speed);
}

function removeAppFromDOM() 
{
	$("#appPopUp").empty();
	$("#appPopUp").remove();
	pstatus = "clean";
}

//---------------- Validation Script--------------------//
function validate_email(field)
{
	with (field)
	{
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		if (apos<1||dotpos-apos<2){
			return false;
		}
		else {
			return true;
		}
	}
}

function WebForm_OnSubmit() 
{
	var c = $("body")[0].className;
	var theForm = document.getElementById("know");
	document.getElementById("errors").innerHTML = "";
	var d; 
	
	if(theForm.txtName.value.length == 0)
	{ 
		if(c.match("ES")){d= "Por favor ingrese su nombre"; }
		else if(c.match("FR")){d= "S'il vous pla&icirc;t entrer votre nom"; }
		else{d= "Please enter your name"; }
		document.getElementById("errors").innerHTML = d;
		return false;
	}
	else if(theForm.txtEmail.value.length == 0)
	{
		if(c.match("ES")){d= "Por favor ingrese su correo electr&oacute;nico"; }
		else if(c.match("FR")){d= "S'il vous pla&icirc;t entrer votre courriel"; }
		else{d= "Please enter your email"; }
		document.getElementById("errors").innerHTML = d;
		return false;
	}
	else if(validate_email(theForm.txtEmail) == false)
	{
		if(c.match("ES")){d= "Por favor ingrese un correo electr&oacute;nico v&aacute;lida"; }
		else if(c.match("FR")){d= "S'il vous pla&icirc;t entrer une courriel valide"; }
		else{d= "Please enter a valid email address"; }
		document.getElementById("errors").innerHTML = d;
		return false;
	}
	else if(theForm.txtCompany.value.length == 0)
	{ 
		if(c.match("ES")){d= "Por favor ingrese su empresa"; }
		else if(c.match("FR")){d= "S'il vous pla&icirc;t entrer votre soci&eacute;t&eacute;"; }
		else{d= "Please enter your company name"; }
		document.getElementById("errors").innerHTML = d;
		return false;
	}
	else if(theForm.txtStreet.value.length == 0)
	{ 
		if(c.match("ES")){d= "Por favor ingrese su calle"; }
		else if(c.match("FR")){d= "S'il vous pla&icirc;t entrer votre rue"; }
		else{d= "Please enter your street address"; }
		document.getElementById("errors").innerHTML = d;
		return false;
	}
	else if(theForm.txtState.value.length == 0)
	{ 
		if(c.match("ES")){d= "Por favor ingrese su estado"; }
		else if(c.match("FR")){d= "S'il vous pla&icirc;t entrer votre province"; }
		else{d= "Please enter your state name"; }
		document.getElementById("errors").innerHTML = d;
		return false;
	}
	else if(theForm.txtCity.value.length == 0)
	{
		if(c.match("ES")){d= "Please enter your ciudad"; }
		else if(c.match("FR")){d= "S'il vous pla&icirc;t entrer votre ville"; }
		else{d= "Please enter your city name"; }
		document.getElementById("errors").innerHTML = d;
		return false;
	}
	else if(theForm.txtZip.value.length == 0)
	{ 
		if(c.match("ES")){d= "Please enter your c&oacute;digo postal"; }
		else if(c.match("FR")){d= "S'il vous pla&icirc;t entrer votre code postal"; }
		else{d= "Please enter your zip cod"; }
		document.getElementById("errors").innerHTML = d;
		return false;
	}
	else
	{
		return true;
	}
}


//---------------------THANK YOU Redirect Script-----------------------//
function runTimer(hash) 
{
	var me=setTimeout("goHOME()",5000);
}

function goHOME() 
{
	window.location.replace("default.aspx");
}

