//////////////////////////////////////////////////////////////////////// 
//	
//	free people wholesale interface functions
//	created: 6.9.2008
//	author: WebLinc, LLC - James Van Arsdale III
//
//////////////////////////////////////////////////////////////////////// 

function clearValue(varObj,varValue) 
{
	if(varObj.val() == varValue) {
		varObj.val("");
	}
}

function testValue(varObj,varValue) 
{
	if(varObj.val() == "") {
		varObj.val(varValue);
	}
}

var msgLen = 8500;

function messageCloud(msgTitle,msgTxt,msgLen)
{
	// create msg containers
	var curDate = new Date();
	var msgID = "msg-"+curDate.getTime();		
	
	$("body").append("<div id=\""+msgID+"\" class=\"message-service\" style=\"display: none;\"></div>");
	$("#"+msgID).append("<div class=\"message-content\"><a href=\"#\" class=\"close\">close</a><div class=\"inner-msg clearfix\"></div></div>");
	
	// assign close button action
	$("#"+msgID+" .message-content a.close").click(function() {
		$("#"+msgID).remove();
		return false;
	});
	
	// write msg
	$("#"+msgID+" .message-content .inner-msg").html("<h3>"+msgTitle+"</h3><p>"+msgTxt+"</p>");
	
	// center in viewport
	$("#"+msgID).vCenter();
		
	// animate
	$("#"+msgID).fadeTo("fast", 0, function() { $("#"+msgID).css("display","block"); });
	$("#"+msgID).fadeTo("slow", 0.9);
	//$("#"+msgID+" .message-content .inner-msg").animate({opacity: 1});
	
	// remove item
	var temp = setTimeout("$('#"+msgID+"').remove()", msgLen);
}

/* new browser detection script */
var userAgent = navigator.userAgent.toLowerCase();
 
// Figure out what browser is being used
jQuery.browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1],
	chrome: /chrome/.test( userAgent ),
	safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};
/* end new browser detection script */

function browserSniffer()
{
	// IE versions < 7 
	if( $.browser.msie && parseInt($.browser.version) < 7 )
	{
		messageCloud("Browser Notice","We'd like to encourage you to upgrade your web browser to Internet Explorer 7 to make your shopping experience with us faster and more enjoyable. <a href=\"http://www.microsoft.com/windows/downloads/ie/getitnow.mspx\" target=\"_blank\">Upgrade to Internet Explorer 7</a>. However, your shopping experience will be even faster if you access this site using the latest versions of the Firefox or Safari browsers, which can be downloaded for free here: <a href=\"http://www.mozilla.com/en-US/firefox/\" target=\"_blank\">Firefox 3</a> | <a href=\"http://www.apple.com/safari/download/\" target=\"_blank\">Safari 3</a>",90000);
	}
	// IE version 7
	if( $.browser.msie && parseInt($.browser.version) == 7 )
	{
		messageCloud("Browser Notice","We'd like to encourage you to shop this site using either Firefox or Safari web browsers, which can be downloaded for free here: <a href=\"http://www.mozilla.com/en-US/firefox/\" target=\"_blank\">Firefox 3</a> | <a href=\"http://www.apple.com/safari/download/\" target=\"_blank\">Safari 3</a>. We've found that these browsers are much faster. We think you will be pleased with the switch.",90000);
	}
	// IE version 8
	if( $.browser.msie && parseInt($.browser.version) == 8 )
	{
		messageCloud("Browser Notice","We have not ensured the Free People Wholesale website is compatible with your Internet Explorer 8 browser.  We recommend shopping this website using <a href=\"http://www.mozilla.com/en-US/firefox/\" target=\"_blank\">Firefox 3</a>, or <a href=\"http://www.apple.com/safari/download/\" target=\"_blank\">Safari 3</a> to guarantee the best experience.",80000);
	}
	// Firefox/Mozilla version < 3
	if( $.browser.mozilla && $.browser.version.substr(0,3) < "1.9" )
	{
		messageCloud("Browser Notice","We'd like to encourage you to upgrade your web browser to Firefox 3 to make your shopping experience with us faster and more enjoyable. <a href=\"http://www.mozilla.com/en-US/firefox/\" target=\"_blank\">Upgrade to Firefox 3</a>.",80000);
	}
	// Safari version < 3
	if( $.browser.safari && parseInt($.browser.version) < 522 )
	{
		messageCloud("Browser Notice","We'd like to encourage you to upgrade your Safari browser to make your shopping experience with us faster and more enjoyable. <a href=\"http://www.apple.com/safari/download/\" target=\"_blank\">Upgrade to Safari 3</a>.",80000);
	}
	// Google Chrome, all versions
	/*
		if( $.browser.chrome )
		{
			messageCloud("Browser Notice","We have not ensured the Free People Wholesale website is compatible with your Google Chrome browser.  We recommend shopping this website using <a href=\"http://www.mozilla.com/en-US/firefox/\" target=\"_blank\">Firefox 3</a>, or <a href=\"http://www.apple.com/safari/download/\" target=\"_blank\">Safari 3</a> to guarantee the best experience.",80000);
		}
	*/
}

function updateFavoritesCount(count)
{
	var msg = count + ' list';
	if (parseInt(count) != 1){
		msg = msg + 's';
	}
	$("#utility-nav li.favorites span").html(msg);
}

function myPopup(url,windowname,w,h)
{
	myWin = window.open(url,windowname,"resizable=yes,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+w+",height="+h+",left=50,top=50");
	myWin.focus();
}

$(window).load(function() {
	$("#search-query").focus(function() {
		clearValue($(this), 'Search / Product #');
	});
	$("#search-query").blur(function() {
		testValue($(this), 'Search / Product #');
	});
	
	$("img").noContext();
});