var magento_status_complete;
var photo_tool_win = null;
var pricelist = null;

function loadPricelist() {
	if( pricelist == null ) {
		$.ajax( {async: false,
				 url: "/scripts/pricelist.json", 
				 dataType: 'json', 
				 success: function(json) {
					pricelist = json;
				 }
		});
	}
	
	return pricelist;
}

function hideOnFocus(label_id) {
	$('#' + label_id).hide();
}

function showOnBlur(field, label_id) {
	if (field.value == '') {
		$('#' + label_id).show();
	}
}

function hideLabelsOnFieldsWithValues(inputs) {
	inputs.each( function(i, input) {
		if( input.value != "" ) {
			$( "#" + input.id + "_label" ).hide();
		}
	});
}

jQuery.event.add(window, "load", manageLiveChat);
jQuery.event.add(window, "resize", manageLiveChat);

function manageLiveChat() 
{
	if( $(window).width() < 1000 ) {
		$('#_lpChatBtn').hide();
	}
	else {
		$('#_lpChatBtn').show();
	}
}

function cookie_fields() {
	if( $.cookie("memoryhub_temp") != null ) {
		return $.cookie("memoryhub_temp").split( '|' );
	}
	else {
		return null;
	}
}

function user_firstname() {
	var all_fields = cookie_fields();

	return all_fields == null ? null : all_fields[0];
}

function is_user_registered() {
	return user_firstname() != null;
}

function is_user_gold() {
	var all_fields = cookie_fields();

	return all_fields == null ? null : "true" == all_fields[1];
}

function user_whitech_url() {
	var whitech_url = null;
	
	$.ajax( {async: false, url: "/memories/order/index/whitechinfoasync", dataType: "json",
	         success: function(json) {
				var info = eval(json);
				if( info.logged_in ) {
					whitech_url = decodeURIComponent( info.tool_url);
				}
			 }
	});
	
	return whitech_url;
}

function cookie_timestamp() {
//	var all_fields = cookie_fields();

//	return (all_fields == null || all_fields.length < 3) ? null : new Date(1000 * all_fields[2]);
	return null;
}

function eraseCookie(name) {
	$.cookie(name, null);
}

function openPhotoTool()
{
	var whitech_url = user_whitech_url();
	if( whitech_url == null ) {
		return false;
	}
	if ("#" == whitech_url ) {
		alert('Please call Customer Service at 509-996-4281 and ask them to enable your Free Photo Tools.');
		return true;
	}
	else {
		if( photo_tool_win == null || photo_tool_win.closed ) {
			photo_tool_win = window.open(whitech_url,'mywin','left=20,top=20,width=1000,height=700,toolbar=0,resizable=0');		
		}
		
		if (window.focus) {
			photo_tool_win.focus();
		}
		
		return true;
	}
}

$(document).ready(function(){

	// nav formatting	
	$('#nav li:first').addClass('home');
	$('#nav li:eq(2) a').addClass('featured');
	$('#nav li:eq(3) a').addClass('featured');
	$('#nav li:eq(4) a').addClass('featured');
			
	// dynamically set current arrow on main nav
	$('#nav li.current').append($('<div id="nav-current">&nbsp;</div>'));

	
	$('.photo-link').click( function() {
		if(!openPhotoTool() ) {
			document.location = "/memories/my-account";
		}
		return false;
	});
	
});

function openLiveChat(){
window.open('http://server.iad.liveperson.net/hc/42621566/?cmd=file&file=visitorWantsToChat&site=42621566&imageUrl=http://server.iad.liveperson.net/hcp/Gallery/ChatButton-Gallery/English/General/1a/&referrer='+escape(document.location),'chat42621566','width=472,height=320,resizable=yes');
return false;
}

