$(window).load(
    function() {
		setTimeout(function(){
			 //$('h2').css({"visibility":"visible"});
			 //$('h1').css({"visibility":"visible"});
			 //$('h5').css({"visibility":"visible"});
			 //$('#primaryNavigation ul li a').css({"visibility":"visible"});
			 //$('h4 a').css({"visibility":"visible"});
			 //$('h4').css({"visibility":"visible"});
			 //$('h3').css({"visibility":"visible"});
			 //$('.secondaryNav li a').css({"visibility":"visible"});
	    }, 400);
    }
);
	
$(document).ready(function() {
     
    $('.homePageColumn').eq(0).css({"margin-left":"14px"});
    
    var agent = navigator.userAgent.toLowerCase();
	var is_iphone = ((agent.indexOf('iphone') != -1));
	var is_ipad = ((agent.indexOf('ipad') != -1));
	
	if (is_iphone) { 
		
	}	
	
	if (is_ipad) { 
		$('#primaryNavigation ul li a').css({"padding-left":"8px", "padding-right":"8px"});
	}
	
	var ie_version = getInternetExplorerVersion();
	
	if($('.menuItem').length > 0) {
		$('.menuItem').hover(function() {
			$('a', this).css({color: '#ff7e00'});
		}, function() {
			$('a', this).css({color: '#aa906c'});
		});
	}
	
	
	// Setup a default popup link binding
    $('a.popupLink').bind('click', function(e) { popupWindow($(this).attr('href'), $(this).attr('title').replace(/[^A-z]/ig, ''),'width=600, height=800, scrollbars'); e.preventDefault(); });

	//$('.secondaryNav li.selected').next().css({"background-image":"url(../images/common/sidebar-nav-shadow.png)"});
	//$('.secondaryNav li.selected').next().css({"background-image":"none"});
	$('.secondaryNav li.selected ul.tertiaryNav li.selected').next().css({"background-image":"none"});
	$('.secondaryNav li.selected').prev().css({"background-image":"none"});
	
	activeNav = $('#primaryNavigation ul li.selected a').width();
	//glowLeftPosition = Math.ceil(activeNav / 2);
	//console.log(activeNav);
	if(activeNav != null) {
		//$('#primaryNavigation ul').css({"background-image": "url(images/common/nav-glow.png)"});
		
	}
	//$('#primaryNavigation ul li.selected a').siblings('img').show();
	
	$(".menuList a").fancybox({
		'titleShow': true,
		'titlePosition': 'inside'
	});
	
	$('.recipeStep ol li').each(function(index) {
		$(this).append('<div class="recipeStepImage png">'+(index+1)+'</div>');
	});
	
	$('.ingredientsContentWrapper div.ingredientBlock').each(function(i) {
		if((i+1) % 2 == 1) {
			$(this).addClass('ingredientBlockBlue');
		} else {
			$(this).addClass('ingredientBlock');
		}
	});
	
	
});

function getInternetExplorerVersion() {
	var rv = -1;
	if (navigator.appName == 'Microsoft Internet Explorer') {
		var ua = navigator.userAgent;
		var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
		rv = parseFloat( RegExp.$1 );
	}
	return rv;
}

function popupWindow(url, name, attributes){
	// Append popup to the URL if it does not already exist
	var queryStringExists = false;
	if(url.match(/\?/)) {
		queryStringExists = true;
	}
	
	if(queryStringExists) {
		// Only append if we haven't already got the parameter popup defined
		if(!url.match(/(\?|&)popup=/)) {
			url = url + '&popup=true';
		}
	} else {
		url = url + '?popup=true';
	}
	
	var baseTags = document.getElementsByTagName('base');
	if(baseTags != undefined && baseTags.length > 0) {
		url = baseTags[0].href + url;
	}
	
	var newWindow = window.open(url, name.replace(/[^A-z]/ig, ''), attributes);
	newWindow.focus();
}

function storeCountryChange() {
	var countryLocation = $("#countryId option:selected").val();
	window.location=countryLocation;
}

function storeRegionChange() {
	var regionLocation = $("#regionId option:selected").val();
	window.location=regionLocation;
}

