	$(function(){
		
		$(".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" });
		
		var activeIndex = $("#clamAccount .open");
		activeIndex = $("#clamAccount .active").parent().parent().parent().prev();
		$("#clamAccount").accordion({ autoHeight: false, active: activeIndex});
		
		
		
		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: '-=207px'}, 'slow');
				iteration = iteration + 1;
			}
			return false;
		});
		
		
		$('#rewardSlider .leftArrow').click(function(){
			captureLinkOmni('Carousel');
			if (typeof(iteration) == "undefined"){
			
				iteration = 0;
				numberOfItems = $('#rewardSlider div').find('.rewardFrame').length-2;
			}
				
			if (iteration > 0){
			
				$('#rewardSlider .slider').stop(false, true).animate({left: '+=207px'}, '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);
	}
	
	
	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: "28px", lineHeight: "32px"}, 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);
}
