

	$(function(){
		var spanishSwitch = 0;
		if ($("#content .triPanel .top h2:contains('PARA')").length > 0){spanishSwitch++; }
		if ($("#content .triPanel .middle h2:contains('DORADA')").length > 0){spanishSwitch++; }
		if ($("#content .triPanel .bottom h2:contains('SALDO')").length > 0){spanishSwitch++; }
		if ($("#maintainer ul.subnav span:contains('Encontrar')").length > 0){spanishSwitch++; }
		if (spanishSwitch > 0){ $('body').addClass('spanish'); }		   

		$('.leaveSite').click(function(){
			$.openDOMWindow({
				borderSize: 0,
				width: 750,
				height: 500,
				windowSourceID:'#confirmationMessage2', 
				windowBGColor: 'none'
			});
			
			$('#manageAccountButton').focus();
		});
		

		$('.triPanel .maximized').hide();
		$('.triPanel .minimized').hide();
		$('.triPanel .top .maximized').show();
		$('.triPanel .middle .minimized').show();
		$('.triPanel .bottom .minimized').show();
		
		animateTopPanel();
		$('.triPanel .active').single_double_click(function(){
			if (!$(this).parent().parent().hasClass('open')){
				
				$('.triPanel .panels').removeClass('open');
				$('.triPanel .panels').removeClass('stay');
				
				if($(this).parent().hasClass('top')){
					animateTopPanel();
				} else if($(this).parent().hasClass('middle')){
					animateMiddlePanel();
				} else {
					animateBottomPanel();
				}
				
			} else {
				defaultPosition();
			}											
		}, function(){ }, 200);
		
	$('.triPanel .active a').click(function(evt){
				evt.stopPropagation();
			});
		

		function defaultPosition(){
			$('.triPanel .maximized').stop(true, true).hide();
			$('.triPanel .minimized').stop(true, true).hide();
			$('.triPanel .default').stop(true, true).show();
			
			$('.triPanel .top').stop(true, true).animate({
					height: 136
				}, 'slow');
			$('.triPanel .middle').stop(true, true).animate({
					height: 111
				}, 'slow');
			$('.triPanel .bottom').stop(true, true).animate({
					height: 110
				}, 'slow');
			$('.triPanel .panels').addClass('stay');
			$('.triPanel .panels').removeClass('open');
		}
		

		function animateTopPanel(){
			$('.triPanel .maximized').stop(true, true).hide();
			$('.triPanel .default').stop(true, true).hide();
			$('.triPanel .minimized').stop(true, true).hide();
			
			$('.triPanel .middle').stop(true, true).animate({
				height: 73
			}, 'fast');
			$('.triPanel .bottom').stop(true, true).animate({
				height: 73
			}, 'fast', function(){
				$('.triPanel .top').stop(true, true).animate({
					height: 211
				}, 'slow');
				$('.triPanel .minimized').stop(true, true).fadeIn();
				$('.triPanel .top .minimized').stop(true, true).hide();
				$('.triPanel .top .maximized').stop(true, true).fadeIn();
			});
			$('.triPanel .top').parent().addClass('open');
		}
		

		function animateMiddlePanel(){
			$('.triPanel .maximized').stop(true, true).hide();
			$('.triPanel .default').stop(true, true).hide();
			$('.triPanel .minimized').stop(true, true).hide();
			
			$('.triPanel .top').stop(true, true).animate({
				height: 105
			}, 'fast');
			$('.triPanel .bottom').stop(true, true).animate({
				height: 73
			}, 'fast', function(){
				$('.triPanel .middle').stop(true, true).animate({
					height: 178
				}, 'slow');
				$('.triPanel .minimized').stop(true, true).fadeIn();
				$('.triPanel .middle .minimized').stop(true, true).hide();
				$('.triPanel .middle .maximized').stop(true, true).fadeIn();
			});
			$('.triPanel .middle').parent().addClass('open');
		}
		

		function animateBottomPanel(){
			$('.triPanel .maximized').stop(true, true).hide();
			$('.triPanel .default').stop(true, true).hide();
			$('.triPanel .minimized').stop(true, true).hide();
			
			$('.triPanel .top').stop(true, true).animate({
				height: 105
			}, 'fast');
			$('.triPanel .middle').stop(true, true).animate({
				height: 73
			}, 'fast', function(){
				$('.triPanel .bottom').stop(true, true).animate({
					height: 178
				}, 'slow');
				$('.triPanel .minimized').stop(true, true).fadeIn();
				$('.triPanel .bottom .minimized').stop(true, true).hide();
				$('.triPanel .bottom .maximized').stop(true, true).fadeIn();
			});
			$('.triPanel .bottom').parent().addClass('open');
		}		
		$('.languageDrop').hide();
		$('.languageSelect, .languageDrop a').click(function(){
			$('.languageDrop').toggle();
			return false;
		});
		
		$(".panel").show();

		$("#content .accordion").accordion({ collapsible: true, active: false, autoHeight:false });
		
		
		
		accordInit();
		
		
		$("#content .accordion").bind('accordionchangestart', function(event, ui) {
			
			var initState = true;
			
			if ($("#content h3").hasClass("ui-state-active")){ 
				initState = false;
			
			}
			
			if ($("#SignInHit").hasClass("ui-state-active")){ 
			    document.getElementById('captchaPlaceHolder2').appendChild(document.getElementById('captchaSource'));
				initSigninClamShell();
				captureLinkOmni('SignInCl');
			}
			if ($("#regInHit").hasClass("ui-state-active")){ 
				captureLinkOmni('RegInCl');
				initRegClamShell();
				
			}
			if ($("#learnMoreHit").hasClass("ui-state-active")){ 
				captureLinkOmni('LeranMoreCl');	
			}
			if ($("#signUpHit").hasClass("ui-state-active")){ 
				captureLinkOmni('SignUpCl');
			}
			
			
			if (initState){
				accordInit();
			} else {
				accordDeInit();
			}
		});
		
		$(".tooltip").hide();
		$("a.rel").each(function(i) {
			$(this).bind("click", function() {
				$("#rec_"+(i+1)).show();
				return false;
			});
		});
		
		$(".tooltipButton").click(function() {
			$(this).parent().parent().hide();
			return false;
		});
		
		
		$("#regUsername").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#regPassword").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#regPasswordText").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#regGoldcardNum").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#regEmail").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#regCaptcha").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#regAddress").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#regCity").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#regZip").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		
		$("#logUsername").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#logPassword").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#logCaptcha").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#captchaId").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#captchaSignInId").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		
		$("#accountMobile").toggleVal({ populateFrom: "custom", removeLabels: false, focusClass: "hasFocus", changedClass: "isChanged", text: "(xxx) xxx-xxxx" });
		$("#accountPhone").toggleVal({ populateFrom: "custom", removeLabels: false, focusClass: "hasFocus", changedClass: "isChanged", text: "(xxx) xxx-xxxx" });
		
		var activeIndex = $("#clamAccount .open");
		activeIndex = $("#clamAccount .active").parent().parent().parent().prev();
		$("#clamAccount").accordion({ autoHeight: false, active: activeIndex});
		
					$(function(){
						var tabindex = 1;
						$('input,select').each(function() {
							if (this.type != "hidden") {
							var $input = $(this);
							$input.attr("tabindex", tabindex);
							tabindex++;
								}
						});
					});	
		
		
		window.scrollAmountArray = [];
		if(($(this).find('.slider').find('> img').length)-3 > 0){
		
				$(".scrollbar").slider({value: 0, min: 0, max: (($(this).find('.slider').find('> img').length)-4), step: 1, animate: true,
					change: function(e, ui){
						handleSliderChange(e, ui, this);
					}
		});
		
		}
		$(".next").click(function(){
		
			captureLinkOmni('Carousel');
			pid = $(this).parent().parent().attr("id");
			$('#' + pid + ' .scrollbar').slider("value", $('#' + pid + ' .scrollbar').slider("value") + 1);
			return false;
		});
		
		
		$(".previous").click(function(){
			captureLinkOmni('Carousel');
			pid = $(this).parent().parent().attr("id");
			$('#' + pid + ' .scrollbar').slider("value", $('#' + pid + ' .scrollbar').slider("value") - 1);
			return false;
		});
		
		
		$(".maxleft").click(function(){
			captureLinkOmni('Carousel');
			pid = $(this).parent().parent().attr("id");
			$('#' + pid + ' .scrollbar').slider("value", 0);
			return false;
		});
		
		
		$(".maxright").click(function(){
			captureLinkOmni('Carousel');
			pid = $(this).parent().parent().attr("id");
			$('#' + pid + ' .scrollbar').slider("value", 9999999);
			return false;
		});
		
		
		$('#rewardSlider .rightArrow').click(function(){
			captureLinkOmni('Carousel');
			if (typeof(iteration) == "undefined"){
				iteration = 0;
				numberOfItems = $('#rewardSlider div').find('.rewardFrame').length-2;
			}
			
			if (iteration >= 0 && iteration < numberOfItems){
				$('#rewardSlider .slider').stop(false, true).animate({left: '-=128px'}, 'slow');
				iteration = iteration + 1;
			}
			return false;
		});
		
		
		$('#rewardSlider .leftArrow').click(function(){
			captureLinkOmni('Carousel');
			if (typeof(iteration) == "undefined"){
			
				iteration = 0;
				numberOfItems = $('#rewardSlider div').find('.rewardFrame').length-3;
			}
				
			if (iteration > 0){
			
				$('#rewardSlider .slider').stop(false, true).animate({left: '+=128px'}, 'slow');
				iteration = iteration - 1;
			}
			return false;
		});
		
		
		$("#countrySelect").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#city").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#state").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });
		$("#zip").toggleVal({ populateFrom: "label", removeLabels: true, focusClass: "hasFocus", changedClass: "isChanged" });

		
		$('.captchaLink').openDOMWindow({ 
			eventType:'click',
			borderSize: 0,
			width: 750,
			height: 500,
			windowBGColor: 'none'
		});
		
		
		$('.privacyLink').openDOMWindow({ 
			eventType:'click',
			borderSize: 0,
			width: 750,
			height: 500,
			windowBGColor: 'none'
		});
		
	
		$('.confirmationButton').openDOMWindow({ 
			eventType:'click',
			borderSize: 0,
			width: 750,
			height: 500,
			windowSourceID:'#confirmationMessage', 
			windowBGColor: 'none'
		});
		$('#registerBtn').openDOMWindow({ 
			eventType:'click',
			borderSize: 0,
			width: 750,
			height: 500,
			windowSourceID:'#confirmationMessage2', 
			windowBGColor: 'none'
		});
	});
	
	function handleSliderChange(e, ui, tar, scrollAmountArray)
	{
		pid = $(tar).parent().parent().attr("id");
		if (isNaN(window.scrollAmountArray[pid]))
			window.scrollAmountArray[pid] = 0;
		
		var scrollAmount = ($('#' + pid + ' .scrollbar').slider("value")) - window.scrollAmountArray[pid];
		$('#' + pid + ' .slider').stop(false, true).animate({'right': '+=' + 198 * scrollAmount + 'px'}, 'slow');
		window.scrollAmountArray[pid] = $('#' + pid + ' .scrollbar').slider("value");
	}
	
	
	function accordInit(){

		$("#content .accordion h3").animate({height: "92px", lineHeight: "94px"}, 600);
		
		$("#content .accordion .ui-icon-triangle-1-e").css({top: "40%"});
		$("#content .accordion #signUpHit .ui-icon-triangle-1-e").css({top: "41%"});
		$("#content .accordion #learnMoreHit .ui-icon-triangle-1-e").css({top: "42%"});
		
		$(".h3fix").animate({height: "91px", lineHeight: "94px"}, 0);
		
		if (jQuery.browser.version.substr(0,3)=="6.0") {
			$(".h3fix").animate({height: "90px", lineHeight: "91px"}, 0);
		}
	}
	
	
	function accordDeInit(panelAct){
	
		$("#content .accordion h3").animate({height: "30px", lineHeight: "34px"}, 310);
		
		$("#content .accordion .ui-icon-triangle-1-s").css({height: "16px"});
		$("#content .accordion .ui-icon-triangle-1-e").css({height: "16px"});
		$("#content .accordion .ui-icon-triangle-1-e").css({top: "8px"});
		
		
		opacity = true;
		jQuery.each(jQuery.browser, function(i) {
			if(i=="msie"){
				if (jQuery.browser.version.substr(0,3) == "6.0" || jQuery.browser.version.substr(0,3) == "7.0"){
				
				
					$("#content .accordion .ui-icon-triangle-1-s").css({height: "18px"});
					$("#content .accordion .ui-icon-triangle-1-e").css({height: "18px"});
				}
				if (jQuery.browser.version.substr(0,3)=="6.0") {
				
					$("#content .accordion h3").animate({height: "28px", lineHeight: "31px"}, 310);
					$("#content .accordion .h3fix").animate({height: "31px", lineHeight: "35px"}, 310);
					opacity = false;
				}
			}
		});
	}
	
function refreshRegCaptcha(){
	document.getElementById("regimagecpt").src="captcha?" + Math.random();
}	
	
function refreshCaptcha(){
	document.getElementById("imagecpt").src="captcha?" + Math.random();
}
function captureLinkOmni(crName){
	if($('#pname') != null)
		crName = $('#pname').val() + crName;
	setOmnitureDetail(crName);
}
function showHideHelpMe(msgName,state){
	if (state==1){
		document.getElementById(msgName).style.display = "block";
	}else{
		document.getElementById(msgName).style.display = "none";
	}
} 
jQuery.fn.single_double_click = function(single_click_callback, double_click_callback, timeout) {
return this.each(function(){
	var clicks = 0, self = this;
		jQuery(this).click(function(){
			clicks++;
			if (clicks == 1) {
				setTimeout(function(){
			if(clicks == 1) {
				single_click_callback.apply(self);
			} else {
				double_click_callback.apply(self);
			}
				clicks = 0;
			}, timeout || 300);
			}
		});
	});
}

