$(document).ready(function(){

	$("#contact input[type='submit']").addClass('submit');
	$(".event_content .event td b:first").addClass('contact_h');	
	
	// set the cufon elements
	Cufon.replace(
		'.picks_box h3, h3.expert_picks_h, #featured h1, .event_content .event td b:first, h1.title, h2.title, p.copyright, .product_box h3, #jumpto span.jump, #favorite_product_h, #product_grid h2, #results_nav a, #optin .event_content h1, .also_try_box h3, #where_to_buy .logos h2, #top_promo h2, .new_product_box h3, .special_offers_box h3, #noflash p, #not_found p'
	);

	// activate superfish nav
	$("ul.sf-menu").superfish({
		animation: {height:'show', opacity:'show'},   // slide-down effect without fade-in
		delay:     200,  
		autoArrows:    false,
		dropShadows: false,
		pathClass:  'current'
	});
	
	// have meet luigi call the set subnav function in case you're already on the our experts section
	$("#meet_luigi a").click(function(){setTimeout(setExpertsSubnav, '100');});
	
	// set config and activate 'jump to' product dropdown
	var config = {
		timeout: 200,
		over: function(){$("#jumpto li#trigger ul").slideDown('fast'); $("#jumpto").addClass('over');},
		out: function(){$("#jumpto li#trigger ul").slideUp('fast');$("#jumpto").removeClass('over');}
	};
	
	$("#jumpto li#trigger").hoverIntent(config);
	
	
	// activate tabs for product detail page
	if (  $('#product_detail_tabs').length > 0 ) {  
		var $tabs = $('#product_detail_tabs').tabs();
		
		SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);
		
		// set up swfaddress so the back button works
		$("#product_detail_tabs li a").click(function(){
			var theHash = this.hash.replace("#", "");
			SWFAddress.setValue(theHash);
		});
	}	
	
	// open in a new window
	$("a[rel='external']").click(function(event){
		window.open( $(this).attr('href') );
        event.preventDefault();
	});
	
	// set up our_heritage scrollpane
	if ( $(".our_heritage").length > 0 ){
		$(function(){
			$('.our_heritage .scroll-pane').jScrollPane({scrollbarWidth: 8, dragMinHeight: 61, dragMaxHeight: 61 });
		});
	}
});

function handleChange(event){
	// show the correct tab, based on the hash value from swfaddress
	switch(event.path){
		case "/how_it_works":
			$("#product_detail_tabs").tabs("select", 0);
		break;
		case "/how_to_use":
			$("#product_detail_tabs").tabs("select", 1);
		break;
		case "/also_try":
			$("#product_detail_tabs").tabs("select", 2);
		break;
		default :
			$("#product_detail_tabs").tabs("select", 0);
		break;
	}
}

/* Flash Tracking */
function goToPage(pg) {
	dcsMultiTrack('DCS.dcsuri',pg,'DCS.dcsqry','','WT.ti',pg); 
	firstTracker._trackPageview(pg);
	secondTracker._trackPageview(pg);
}

function setCookie(c_name,value,expiredays, path){
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	document.cookie=c_name+ "=" +escape(value)+
	(( path ) ? ";path=" + path : "" ) +
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function getCookie(c_name)
{
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) { c_end=document.cookie.length }
			return unescape(document.cookie.substring(c_start,c_end))
		} 
	}
	return "";
}

function setExpertsSubnav(){
	setTimeout(function(){
		switch (document.location.hash){
			case "#/Intro/":
				$('body').attr('class', 'intro');		
				break;
			case "#/Meet2--luigi/":
				$('body').attr('class', 'luigi');
				break;
			case "#/Meet2--harry/":
				$('body').attr('class', 'harry');	
				break;
			case "#/Meet2--kerry/":
				$('body').attr('class', 'kerry');	
				break;
			case "#/Salon/":
				$('body').attr('class', 'salons');
				break;
		}
	}, '50');
}

function checkIfSafari3_1() {
	n = navigator;
	nua = n.userAgent;
	if (nua.indexOf('Version/3.1') != -1 && nua.indexOf('Safari') != -1) return true;
	else return false;
}

safari_3_1_mac_popup_block_msg = 'You are using Safari 3.1 and it has blocked our Pop-Up Window.\nTo view the Pop-Up Window:\n1) disable your Pop-Up blocker by going into the Safari menu in your browser\'s menu bar and unselecting the Block Pop-Up Windows option\n2) then click on the link again';
safari_3_1_win_popup_block_msg = 'You are using Safari 3.1 and it has blocked our Pop-Up Window.\nTo view the Pop-Up Window:\n1) disable your Pop-Up blocker by going into the Edit menu in your browser\'s menu bar and unselecting the Block Pop-Up Windows option\n2) then click on the link again';

function popUpNoScroll(filename) {
	popup2=window.open(filename,"popup2","height=770,width=800,resizable=yes,status=no,toolbar=no,directories=no,menubar=no,scrollbars=yes,location=no");
}

function popUpNoScrollReturnStatus(filename) {
	popup2=window.open(filename,"popup2","height=770,width=800,resizable=yes,status=no,toolbar=no,directories=no,menubar=no,scrollbars=yes,location=no");
	if (!popup2) {
		if (checkIfSafari3_1()) {
			n = navigator;
			na = n.appVersion;
			if ( na.indexOf( 'Mac' ) != -1 ) {alert(safari_3_1_mac_popup_block_msg);} 
			else {alert(safari_3_1_win_popup_block_msg);}
		}
		return false;
	}
	else return true;
}