// Contains custom objects for The WildSide.
// Written by Stephen Topsy of TopsyDesigns.com

// Global ---------------------------------------------------------- //
var itemBackgrounds = new Array
	itemBackgrounds["web00"] = "#804812"
	itemBackgrounds["web01"] = "#204736"
	itemBackgrounds["web02"] = "#ADA687"
	itemBackgrounds["web03"] = "#B10E23"
	itemBackgrounds["web04"] = "#C79316"
	itemBackgrounds["web05"] = "#502D7F"
	itemBackgrounds["web06"] = "#FFE000"
	itemBackgrounds["web07"] = "#41667B"
	itemBackgrounds["web08"] = "#892634"
	itemBackgrounds["web09"] = "#412800"
	itemBackgrounds["web10"] = "#9B243E"
	itemBackgrounds["web11"] = "#4e421c"
	itemBackgrounds["web12"] = "#2E0303"
	itemBackgrounds["web13"] = "#000"
	itemBackgrounds["web14"] = "#DED3B0"
	itemBackgrounds["web15"] = "#EEF761"
	itemBackgrounds["web16"] = "#70D651"
	itemBackgrounds["web17"] = "#97C5EB"
	itemBackgrounds["web18"] = "#FCC7D5"
	itemBackgrounds["web19"] = "#94A599"
	itemBackgrounds["web20"] = "#CCCCFF"
	itemBackgrounds["web21"] = "#666699"
	itemBackgrounds["web22"] = "#F27EB2"
	itemBackgrounds["web23"] = "#009A3D"
	itemBackgrounds["web24"] = "#5381AC"
	itemBackgrounds["standardThumbWhite"] = "#fff"
	itemBackgrounds["standardThumbBlack"] = "#000"
	itemBackgrounds["standardThumbGray"] = "#333"
	itemBackgrounds["standardThumbLightGray"] = "#CCC"

var itemTexture = new Array
	itemTexture["none"] = 'none'
	itemTexture["camo"] = 'url(/themes/wildsidegothic/images/fabric/fab_camouflage.png)'
	itemTexture["tiedye"] = 'url(/themes/wildsidegothic/images/fabric/fab_tiedye.png)'
	itemTexture["denim"] = 'url(/themes/wildsidegothic/images/fabric/fab_denim.png)'
	
var progressBar = "<img src='/themes/wildsidegothic/images/gui/progress/indeterminant.gif' id='progressIndeterminant' />";
var progressDot = "<img src='/themes/wildsidegothic/images/gui/progress/progressDot.gif' id='progressDot' />";

	
var notificationOkay = function(action) {
		notification.hide();
		return;
	}
	
var notificationStop = function() {
		notification.hide();
		return false;
	}
	
	
function notify(iconId, heading, message, position){
	
			
var icon = new Array
	icon["warn"] = YAHOO.widget.SimpleDialog.ICON_WARN
	icon["help"] = YAHOO.widget.SimpleDialog.ICON_HELP
	icon["info"] = YAHOO.widget.SimpleDialog.ICON_INFO
	icon["alarm"] = YAHOO.widget.SimpleDialog.ICON_ALARM
	icon["tip"] = YAHOO.widget.SimpleDialog.ICON_TIP
	icon["block"] = YAHOO.widget.SimpleDialog.ICON_BLOCK
	
	notification = new YAHOO.widget.SimpleDialog("notification", { 
	width: "425px", 
	underlay: "matte",
	zIndex: 250,
	effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.3}, 
	modal: true,
    visible:false,
	fixedcenter: true,
	draggable:true });
	
	if (position != null){
		notification.cfg.setProperty("context",position);
		notification.cfg.setProperty("modal",false);
	}		  
	
	notification.setHeader(heading);
	notification.setBody(message);
	notification.cfg.setProperty("icon",icon[iconId]);
	notification.cfg.queueProperty("buttons", [ { text:"Okay", handler:notificationOkay, isDefault:true }]);
	
	//replace open notification. One instance of this object at a time!!
	if (document.getElementById('notification')){
		notification.hide();
	}
		
	notification.render(document.body);
	notification.show();
	}
	
	
function submitContact(username, userid){
		
		var contactDetails = {
				
			startTransaction:function() {
				
				YAHOO.util.Dom.setStyle('contactUs', 'visibility', 'visible');
				
				var companyName = document.contact.companyName.value;
				if (document.contact.yourName.value != ''){
					var yourName = document.contact.yourName.value;
					YAHOO.util.Dom.setStyle(document.contact.yourName, 'backgroundColor', '#FFF');
				}else{
					alert('What is your name?\r\nPlease provide your name before sending this form.');
					YAHOO.util.Dom.setStyle(document.contact.yourName, 'backgroundColor', '#FFCC66');
					document.contact.yourName.focus();
					return;
				}
				if (document.contact.email.value != ''){
					var email = document.contact.email.value;
						//validation
					   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
					   if(reg.test(email) == false) {
						  alert('Improper E-mail\r\nPlease enter a valid e-mail address. The WildSide does not send solicitations without your consent. We will not sell your email to a third party.');
						  YAHOO.util.Dom.setStyle(document.contact.email, 'backgroundColor', '#FFCC66');
						  document.contact.email.focus();
						  return false;
					   }
					YAHOO.util.Dom.setStyle(document.contact.email, 'backgroundColor', '#FFF');
				}else{
					alert('Missing E-mail\r\nPlease enter an e-mail address. The WildSide does not send solicitations without your consent. We will not sell your email to a third party.');
					YAHOO.util.Dom.setStyle(document.contact.email, 'backgroundColor', '#FFCC66');
					document.contact.email.focus();
					return;
				}
				if (document.contact.phone.value != ''){
					var phone = document.contact.phone.value;
					YAHOO.util.Dom.setStyle(document.contact.phone, 'backgroundColor', '#FFF');
				}else{
					alert('Missing Phone Number\r\nPlease enter a call-back number. We will not sell your phone number to a third party.');
					YAHOO.util.Dom.setStyle(document.contact.phone, 'backgroundColor', '#FFCC66');
					document.contact.phone.focus();
					return;
				}
				if (document.contact.custIdInput.value != ''){
					var custIdInput = document.contact.custIdInput.value;
					YAHOO.util.Dom.setStyle(document.contact.custIdInput, 'backgroundColor', '#FFF');
				}else{
					alert('Missing Customer ID\r\nPlease enter your WildSide Customer ID');
					YAHOO.util.Dom.setStyle(document.contact.custIdInput, 'backgroundColor', '#FFCC66');
					document.contact.custIdInput.focus();
					return;
				}
				if (document.contact.question.value != ''){
					var question = document.contact.question.value;
					//replace breaks with newline chars
					function doublenewlines(question) { question = text.replace(/(\r\n|\r|\n)/g, '\n'); return question.replace(doublenewlinesRE, "$1\n\n$2"); }
					YAHOO.util.Dom.setStyle(document.contact.question, 'backgroundColor', '#FFF');
				}else{
					alert('What is your message?\r\nPlease provide questions or commentary before sending this form.');
					YAHOO.util.Dom.setStyle(document.contact.question, 'backgroundColor', '#FFCC66');
					document.contact.question.focus();
					return;
				}
				if (companyName != ''){
					var subject = "The WildSide: NEW MESSAGE from " + yourName + " of " + companyName;
				}else{
					var subject = "The WildSide: NEW MESSAGE from " + yourName;
				}
				var recip = "The WildSide <info@thewildside.com>";
				
				notify('info', 'Sending your message...', '<br />' + progressBar, 'okaycancel');
				notification.cfg.setProperty("modal", "true");
												
				YAHOO.util.Dom.setStyle('contactUs', 'cursor', 'wait');
				YAHOO.util.Connect.asyncRequest('GET', '/themes/wildsidegothic/database_access/sendmail.php?username=' + username + '&userid=' + userid + '&recip=' + recip + '&subject=' + subject + '&question=' + question + '&email=' + email + '&phone=' + phone + '&name=' + yourName + '&company=' + companyName, callback, null);
				
				},
			  
			responseSuccess:function(o){
				
				notification.hide();
				
				YAHOO.util.Dom.setStyle('contactUs', 'visibility', 'hidden');
				changeSize('contactUs', '', '0', 1);
				
				YAHOO.util.Dom.setStyle('contactUs', 'cursor', 'auto');
				notify('info', 'Message Result', '<div style="background-color: #FFF; padding: 10px 20px; margin: 10px;">' + o.responseText +'</div>');
						
				},
			  
			responseFailure:function(o){
				
				YAHOO.util.Dom.setStyle('contactUs', 'cursor', 'auto');
				notify('alarm', 'Message Could Not Be Sent', 'Accept our apologies, we could not send your message. The server responded with:' + o.statusText +'    /    '+o.responseText);
				
				}
		}
		
		
		var callback =
		{
		  success:contactDetails.responseSuccess,
		  failure:contactDetails.responseFailure,
		  scope:contactDetails
		};
		
		
		contactDetails.startTransaction();
}

function submitOrder(){
	
	//validate form
	if (document.sendOrder.name.value != ''){
		YAHOO.util.Dom.setStyle(document.sendOrder.name, 'backgroundColor', '#FFF');
	}else{
		alert('What is your name?\r\nPlease provide your name before sending this order.');
		YAHOO.util.Dom.setStyle(document.sendOrder.name, 'backgroundColor', '#FFCC66');
		document.sendOrder.name.focus();
		return;
	}
	if (document.sendOrder.email.value != ''){
		var email = document.sendOrder.email.value;
			//validation
		   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		   if(reg.test(email) == false) {
			  alert('Improper E-mail\r\nPlease enter a valid e-mail address. The WildSide does not send solicitations without your consent. We will not sell your email to a third party.');
			  YAHOO.util.Dom.setStyle(document.sendOrder.email, 'backgroundColor', '#FFCC66');
			  document.sendOrder.email.focus();
			  return false;
		   }
		YAHOO.util.Dom.setStyle(document.sendOrder.email, 'backgroundColor', '#FFF');
	}else{
		alert('Missing E-mail\r\nPlease enter an e-mail address. The WildSide does not send solicitations without your consent. We will not sell your email to a third party.');
		YAHOO.util.Dom.setStyle(document.sendOrder.email, 'backgroundColor', '#FFCC66');
		document.sendOrder.email.focus();
		return;
	}
	if (document.sendOrder.phone.value != ''){
		YAHOO.util.Dom.setStyle(document.sendOrder.phone, 'backgroundColor', '#FFF');
	}else{
		alert('Missing Phone Number\r\nPlease enter a call-back number. We will not sell your phone number to a third party.');
		YAHOO.util.Dom.setStyle(document.sendOrder.phone, 'backgroundColor', '#FFCC66');
		document.sendOrder.phone.focus();
		return;
	}
	if (document.sendOrder.address.value != ''){
		YAHOO.util.Dom.setStyle(document.sendOrder.address, 'backgroundColor', '#FFF');
	}else{
		alert('Missing Billing Address\r\nPlease provide a billing address before sending this order.');
		YAHOO.util.Dom.setStyle(document.sendOrder.address, 'backgroundColor', '#FFCC66');
		document.sendOrder.address.focus();
		return;
	}
	if (document.sendOrder.shippingaddress.value != ''){
		YAHOO.util.Dom.setStyle(document.sendOrder.shippingaddress, 'backgroundColor', '#FFF');
	}else{
		alert('Missing Billing Address\r\nPlease provide a shipping address before sending this order or use "Same as billing".');
		YAHOO.util.Dom.setStyle(document.sendOrder.shippingaddress, 'backgroundColor', '#FFCC66');
		document.sendOrder.shippingaddress.focus();
		return;
	}
	if (document.sendOrder.city.value != ''){
		YAHOO.util.Dom.setStyle(document.sendOrder.city, 'backgroundColor', '#FFF');
	}else{
		alert('Missing Billing City/State and/or zip\r\nPlease provide a billing city and/or zip before sending this order. Residents of the US must also include the billing state.');
		YAHOO.util.Dom.setStyle(document.sendOrder.city, 'backgroundColor', '#FFCC66');
		document.sendOrder.city.focus();
		return;
	}
	if (document.sendOrder.country.value != ''){
		YAHOO.util.Dom.setStyle(document.sendOrder.country, 'backgroundColor', '#FFF');
	}else{
		alert('Missing Billing Country\r\nPlease provide a billing country before sending this order.');
		YAHOO.util.Dom.setStyle(document.sendOrder.country, 'backgroundColor', '#FFCC66');
		document.sendOrder.country.focus();
		return;
	}
	if (document.sendOrder.item_1.value != ''){
		YAHOO.util.Dom.setStyle(document.sendOrder.country, 'backgroundColor', '#FFF');
	}else{
		alert('Missing Stock ID\r\nPlease provide at least one stock ID before sending this order.');
		YAHOO.util.Dom.setStyle(document.sendOrder.item_1, 'backgroundColor', '#FFCC66');
		document.sendOrder.item_1.focus();
		return;
	}
	
	notify('info', 'Sending your message...', '<br />' + progressBar, 'okaycancel');
					
	document.sendOrder.submit();
}

var appendToCart = function(itemId, cartURL){
	
			
			var appendItem = {
				
			startTransaction:function() {
				
				YAHOO.util.Dom.setStyle('itemDisplayDialog', 'cursor', 'wait');
				if (document.getElementById('photoContainerShowOn')){
				  document.getElementById('photoContainerShowOn').innerHTML = "<div id='itemLoader'>"+progressBar+"</div>";
				}
				YAHOO.util.Connect.asyncRequest('GET', cartURL, callback, null);
				
				},
			  
			responseSuccess:function(o){
				YAHOO.util.Dom.setStyle('viewCartButtonAccepted', 'display', 'block');
				
				YAHOO.util.Dom.setStyle('itemDisplayDialog', 'cursor', 'auto');
				
				document.getElementById('photoContainerShowOn').innerHTML = "";
				var x = document.getElementById('cartCountAlbum').innerHTML;
				if (x == 'zero'){
					x = 0;
				}
				x = (Number(x) + 1);
				document.getElementById('cartCountAlbum').innerHTML = x;
				
				if (x > 1){
				  document.getElementById('cartCountLabelAlbum').innerHTML = "items";
				}else if (x == 1){
				  document.getElementById('cartCountLabelAlbum').innerHTML = "item";
				}
					
				
				},
			  
			responseFailure:function(o){
				
				YAHOO.util.Dom.setStyle('itemDisplayDialog', 'cursor', 'auto');
				notify("warn", "I could not access your cart", "The server response was: <br />" + o.responseText);
					
				
				}
		}
		
		
		var callback =
		{
		  success:appendItem.responseSuccess,
		  failure:appendItem.responseFailure,
		  scope:appendItem
		};
		
		appendItem.startTransaction();
		

		
}
	
	

function removeFromCart(itemId, checked){

	alert(checked);
	YAHOO.util.Dom.setStyle('checkoutThumb_'+itemId, 'opacity', '50%');
	
}
	
	
	
	
	
	

// BrowserDetect ---------------------------------------------------------- //
// from Quirksmode. http://www.quirksmode.org/js/detect.html


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();





// Globals ---------------------------------------------------------- //


// global function used to change the size of any object with animation
// 'containerId' is the container's id, obviously
// 'newWidth' animate the container to this new width
// 'newHeight' animate the container to this new height
// 'time' duration in seconds until the animation completes
function changeSize(containerId, newWidth, newHeight, time){
	
	var currentWidth = YAHOO.util.Dom.getStyle(containerId, 'width');
		currentWidth = currentWidth.replace(/px/i, "");
	var currentHeight = YAHOO.util.Dom.getStyle(containerId, 'height');
		currentHeight = currentHeight.replace(/px/i, "");

	//animate to reveal new width
	if (newWidth != (null || '')){
		var changeWidth = new YAHOO.util.Anim(containerId, {width: { to: newWidth }}, time, YAHOO.util.Easing.easeBothStrong);
		changeWidth.animate();
	}else{
		var changeWidth = new YAHOO.util.Anim(containerId, {width: { to: currentWidth }}, time, YAHOO.util.Easing.easeBothStrong);
		changeWidth.animate();
	}

	//animate to reveal new height
	if (newHeight != (null || '')){
		var changeHeight = new YAHOO.util.Anim(containerId, {height: { to: newHeight }}, time, YAHOO.util.Easing.easeBothStrong);
		changeHeight.animate();
	}else{
		var changeHeight = new YAHOO.util.Anim(containerId, {height: { to: currentHeight }}, time, YAHOO.util.Easing.easeBothStrong);
		changeHeight.animate();
	}
}


function changeXY(containerId, newX, newY, time){
	var currentX = YAHOO.util.Dom.getX(containerId);
	var currentY = YAHOO.util.Dom.getY(containerId);
	if (newX == ''){
		newX = currentX;
	}
	if (newY == ''){
		newY = currentY;
	}
	
	if (time == ('' || null)){
		time = .4;
	}
	var photoOptionsAnim = new YAHOO.util.Motion(containerId, {points: { to: [newX, newY] }}, time, YAHOO.util.Easing.backOut);
	photoOptionsAnim.animate();
}


// Photo Page --------------------------------------------------------------- //


// Fabric Functions ---------------------------------------------------------- //
// changes current fabric background element
// 'itemTexture' denotes the png texture to be placed on top of the chosen color ('hexcolor'). Values are cotton, camo, plaid.

		

//button controls
function activeButton(button) {
	YAHOO.util.Dom.setStyle(button, 'backgroundPosition', '-316px');
	YAHOO.util.Dom.setStyle(button,  'textShadow', ' #none');
	YAHOO.util.Dom.setStyle(button,  'color', '#EEE');
	YAHOO.util.Dom.setStyle(button, 'display', 'block');
}

function resetButtons (){
	YAHOO.util.Dom.setStyle(['photoContainerButton_shirtdisable','photoContainerButton_teeMale','photoContainerButton_teeFemale','photoContainerButton_teeFemaleFit','photoContainerButton_teechild'], 'backgroundColor', 'transparent');
	YAHOO.util.Dom.setStyle(['photoContainerButton_shirtdisable','photoContainerButton_teeMale','photoContainerButton_teeFemale','photoContainerButton_teeFemaleFit','photoContainerButton_teechild'], 'backgroundPosition', '0');
	YAHOO.util.Dom.setStyle(['photoContainerButton_shirtdisable','photoContainerButton_teeMale','photoContainerButton_teeFemale','photoContainerButton_teeFemaleFit','photoContainerButton_teechild'], 'color', '#3b1c0f');
	YAHOO.util.Dom.setStyle(['photoContainerButton_shirtdisable','photoContainerButton_teeMale','photoContainerButton_teeFemale','photoContainerButton_teeFemaleFit','photoContainerButton_teechild'], 'textShadow', '#CCC 0 1px 1px');
	YAHOO.util.Dom.setStyle(['photoContainerButton_shirtdisable','photoContainerButton_teeMale','photoContainerButton_teeFemale','photoContainerButton_teeFemaleFit','photoContainerButton_teechild'], 'display', 'block');
}
	
//change textures
function changeItemTexture(itemTextureValue, itemContainer){
	
	if (itemContainer == null){
		itemContainer = 'photoContainerTexture';
	}
		
	YAHOO.util.Dom.setStyle(itemContainer, 'backgroundImage', itemTexture[itemTextureValue]);

}
	
//change color
function changeItemBgColor (itemBgColor, time, obj){
	
	if (time == null){
		time = ".4";
	}
	
	//update custom field if available
	if ($('[name="g2_form[fields][CustomThumbBg]"]')){
		$('input[name="g2_form[fields][CustomThumbBg]"]').attr('value', itemBgColor );
		$('[name="g2_form[fields][StandardThumbBg]"]').attr('value', null );
	}
	
	var itemBgColorCheck = YAHOO.util.Cookie.get("itemBgColor");
	
	if (itemBgColor == "toggle"){
		if (itemBgColorCheck == "off"){
			YAHOO.util.Cookie.set("itemBgColor", "on", { expires: new Date("January 12, 2025"), path: "/" });
			YAHOO.util.Dom.setStyle('toggleColor', 'backgroundPosition', '0');
			itemBgColor = document.getElementById('cfv_StandardThumbBg').innerHTML;
				if (itemBgColor == "custom"){
				  itemBgColor = document.getElementById('cfv_CustomThumbBg').innerHTML;
				}else{
					itemBgColor = itemBackgrounds[itemBgColor];
				}
		}else if (itemBgColorCheck == "on"){
			YAHOO.util.Cookie.set("itemBgColor", "off", { expires: new Date("January 12, 2025"), path: "/" });
			YAHOO.util.Dom.setStyle('toggleColor', 'backgroundPosition', '-61px');
			itemBgColor = "#DDD";
		}else if (itemBgColorCheck == null){
			YAHOO.util.Cookie.set("itemBgColor", "off", { expires: new Date("January 12, 2025"), path: "/" });
			YAHOO.util.Dom.setStyle('toggleColor', 'backgroundPosition', '-61px');
			itemBgColor = "#DDD";
		}
		var changeBgColor = new YAHOO.util.ColorAnim('photoContainerTexture', {backgroundColor: { to: itemBgColor }}, .8);
		changeBgColor.animate();
			
	}else{
	
		if (itemBgColorCheck == "off"){
			itemBgColor = "#DDD";
			YAHOO.util.Dom.setStyle('toggleColor', 'backgroundPosition', '-61px');
		}else if  (itemBgColorCheck == "on"){
			YAHOO.util.Dom.setStyle('toggleColor', 'backgroundPosition', '0');
		}else if  (itemBgColorCheck == null){
			YAHOO.util.Cookie.set("itemBgColor", "on", { expires: new Date("January 12, 2025"), path: "/" });
			YAHOO.util.Dom.setStyle('toggleColor', 'backgroundPosition', '0');
		}
		
		if (obj == null){
		var changeBgColor = new YAHOO.util.ColorAnim('photoContainerTexture', {backgroundColor: { to: itemBgColor }}, time);
		}else{
		var changeBgColor = new YAHOO.util.ColorAnim(obj, {backgroundColor: { to: itemBgColor }}, time);
		}
		changeBgColor.animate();
	}
	
}

// we may scroll any container that has overflow. 'Math' is either '-' or '+'.
// 'leftscroll' and 'topscroll' values must be a number or one of the folowing: 'left', or 'top'
function scrollThis(containerId, leftscroll, topscroll, math, maxscroll){
	
	//we get the current scroll values of 'containerId'
	var currentScroll = YAHOO.util.Cookie.get("scrollThis" + containerId);
	
	//if the cookies do not exist, set the current values to 0, else updates values based on cookie
	if (currentScroll != null){
		currentScroll = currentScroll.split(":");
		var currentScrollLeft = currentScroll[0];
		var currentScrollTop = currentScroll[1];
	}else{
		var currentScrollLeft = 0;
		var currentScrollTop = 0;
	}
	
	//determines whether to scroll to a positive or negative value
	if (math == '+'){
		leftscroll = Number(leftscroll)+Number(currentScrollLeft);
		if (leftscroll > maxscroll){
			alert('You are at the end.');
			return;
		}
		topscroll = Number(topscroll)+Number(currentScrollTop);
		if (topscroll > maxscroll){
			alert('You are at the end.');
			return;
		}
	}else if (math == '-'){
		leftscroll = Number(currentScrollLeft)-Number(leftscroll);
		if (leftscroll < 0){
			alert('You are at the beginning.');
			return;
		}
		topscroll = Number(currentScrollTop)-Number(topscroll);
		if (topscroll < 0){
			alert('You are at the beginning.');
			return;
		}
	}
		
	//set the new scroll value in the cookie
	YAHOO.util.Cookie.set("scrollThis" + containerId, leftscroll+':'+topscroll, { expires: new Date("January 12, 2025"), path: "/" });
	
	//initiate the scroll
	var element = document.getElementById(containerId);
	var scrollAnim = new YAHOO.util.Scroll(element, {
	   scroll: { to: [leftscroll, topscroll] } 
	});
	
	scrollAnim.method = YAHOO.util.Easing.easeBoth;
	scrollAnim.animate();
}


//change texture, shirt, and color
function changeDisplayOptions(itemBgColor, itemShowOn, itemTexture){
	
	if (itemBgColor == 'clear'){
		YAHOO.util.Dom.setStyle('photoContainerButton_reset', 'display', 'none');
		document.getElementById('teeModuleNotice').innerHTML = '<div style="padding:4px;"><strong>Show this on a shirt</strong><div>choose a size bellow:</div></div>';
		YAHOO.util.Dom.setStyle('photoContainerShowOn', 'backgroundImage', 'none');
		photoPosition('0','0');
		itemDimensions = YAHOO.util.Cookie.get("itemDimensions");
		itemDimensions = itemDimensions.split("x");
		changeSize("photoTransfer", itemDimensions[0], itemDimensions[1], .3);
	}
	
	if (itemBgColor != null){
	  changeItemBgColor(itemBgColor);
	}
	if (itemShowOn != null){
	  photoSize(null, itemShowOn);
	}
	if (itemTexture != null){
	  changeItemTexture(itemTexture);
	}
}

function photoSize(info, itemShowOn, originalSize){
	
	  //Set shirt
				
	  //take out 'fit' shirt since it never worked
	  if (itemShowOn == 'teeFemaleFit'){
		  itemShowOn = 'teeFemale';
	  }
	  
	  if (itemShowOn != 'nothing'){
		YAHOO.util.Dom.setStyle('photoContainerShowOn', 'backgroundImage', 'url(/themes/wildsidegothic/images/fabric/'+itemShowOn+'.png)');
	  }
		
	  if (originalSize){
		
		var toggle = document.getElementById('photoContainerSwatchButton_shirt_options').innerHTML;
		if (toggle == 'show on shirt'){
			document.getElementById('photoContainerSwatchButton_shirt_options').innerHTML = 'hide shirt';
			loadItem(info);
			return;
		}
		var origSize = YAHOO.util.Cookie.get("itemDimensions");
		origSize = origSize.split("x");
		changeSize("photoTransfer", origSize[0], origSize[1], .3);
		var marginx = (325 - origSize[0]) / 2;
		var marginy = (325 - origSize[1]) / 2;
		YAHOO.util.Dom.setStyle('photoTransfer', 'margin', marginy + 'px ' + marginx +'px');
		document.getElementById('photoContainerSwatchButton_shirt_options').innerHTML = 'show on shirt';
		  
	  }else{

			var currentWidth = YAHOO.util.Dom.getStyle("photoTransfer", "width");
				currentWidth = currentWidth.replace(/px/i, "");
			var currentHeight = YAHOO.util.Dom.getStyle("photoTransfer", "height");
				currentHeight = currentHeight.replace(/px/i, "");
			YAHOO.util.Cookie.set("itemDimensions", currentWidth + "x" + currentHeight, { expires: new Date("January 12, 2025"), path: "/" });
			
			if ((currentWidth == 252) && (currentHeight == 252)){
				currentWidth = 325;
				currentHeight = 325;
				YAHOO.util.Dom.setStyle('photoTransfer', 'width', '325px');
				YAHOO.util.Dom.setStyle('photoTransfer', 'height', '325px');
			}
				
	
			if (info != 'full'){
				
				//base is the distance between armpits on a small male or female tee.
				var base = 20;
				
				if (itemShowOn == 'teeFemale'){
					base = 18;
				} else if (itemShowOn == 'teeBaby'){
					base = 12;
				} else if (itemShowOn == 'teeChild'){
					base = 18;
				}
				
					  
				  //get shirt dimension from meta data
				  info = info.split(" - ");
				  var dimensions = info[0];
				  var description = info[1];
				  
				  dimensions = dimensions.split("x");
				  
				  var width = dimensions[0];
				  if (dimensions[1]){
					  var height = dimensions[1];
				  }else{
					  var height = dimensions[0];
				  }
					  
				  
				  //325 is the default image size (in pixels) for products in the database.
				  var newWidth = (width * 325) / base; 
				  var newHeight = (height * 325) / base;
				  
				  var y = (325 - newHeight) / 2;
				  var x = (325 - newWidth) / 2;
				  
				  /*by default, set a minimal y position so that art doesnt draw on the neck (overridden by ShiftY in meta data)
				  if (y < 44){
					  y = 44;
				  }*/
				  
				  
				  
				  var x1 = (Number(x));
				  var x2 = (Number(x));
				  var y1 = (Number(y));
				  var y2 = 0;
				  
				  //auto-positioning. depending on shirt, make default adjustments to ensure art is centered on shirt
				  if (itemShowOn == 'teeBaby'){
					  y1 = y1 - 30;
				  } else if (itemShowOn == 'teeChild'){
					  y1 = y1 - 20;
				  }
				  
				  
				  
				  if (document.getElementById('cfv_ShiftX')){
					  var xShift = document.getElementById('cfv_ShiftX').innerHTML;
						  x1 = x - (Number(xShift));
						  x2 = x + (Number(xShift));
				  }
				  
				  if (document.getElementById('cfv_ShiftY')){
					  var yShift = document.getElementById('cfv_ShiftY').innerHTML;
					  y1 = y + (Number(yShift));
				  }
							  
				  YAHOO.util.Dom.setStyle('photoTransfer', 'margin', y1 + 'px ' + x1 +'px ' + y2 +'px ' + x2 + 'px');
				  
			  }else{
				  
				  var y = (325 - currentHeight) / 2;
				  YAHOO.util.Dom.setStyle('photoTransfer', 'margin', y + 'px auto');
				  
			  }
	  }
				
		//if item is pocket, show at full size.
		/*if ((width <= 4) && (height <= 4)){
			
			var y = (325 - currentHeight) / 2;
			YAHOO.util.Dom.setStyle('photoTransfer', 'margin', y + 'px auto');
			//YAHOO.util.Dom.setStyle('photoTransfer', 'margin', '0 auto');
			
			return;
		}*/
		
		//set shirt size, unless disabled in meta data
		if (info != 'full'){
		changeSize("photoTransfer", newWidth, newHeight, .3);
		}
	
			
		
		
	}





// Page scripts ---------------------------------------------------------- //

						  
function pageData(){
			if (document.getElementById('stockId')){
				var stockId = document.getElementById('stockId').innerHTML;
				pageDisplayDialog.setHeader("<h3 id='newStockId'>"+stockId+"</h3>");
			}else{
				pageDisplayDialog.setHeader("<h3 id='newStockId'>Catalog Page is null</h3>");
			}
			YAHOO.util.Dom.setStyle('swatches', 'display', 'none');
			YAHOO.util.Dom.setStyle('photoContainer', 'display', 'block');
			changeSize('naviBlock', '', '30', .6);
			
			YAHOO.util.Dom.setStyle('photoContainerTexture', 'display', 'none');
			YAHOO.util.Dom.setStyle('stockIdModule', 'display', 'none');
			YAHOO.util.Dom.setStyle('moduleShirt', 'display', 'none');
			YAHOO.util.Dom.setStyle('photoContainerOptions', 'width', '150px');
			YAHOO.util.Dom.setStyle('photoContainerOptions', 'text-align', 'left');
			YAHOO.util.Dom.setStyle('photoContainerPhoto', 'text-align', 'left');
			YAHOO.util.Dom.setStyle('photoContainerPhoto', 'width', '325px');
			YAHOO.util.Dom.setStyle('photoContainerShowOn', 'backgroundImage', 'url(/themes/wildsidegothic/images/fabric/nothing.png)');
			
			window.document.getElementById('photoContainerOptions').innerHTML = "<h3 style='border-bottom: 1px solid #CCC'>Pricing</h3><ul><li>Oversize (P17 +): $0.35</li><li>Adult (P9 - P16): $0.25</li><li>Youth (P8 - P6): $0.15</li><li>Pocket (P5 -): $0.05</li></ul><h3 style='border-bottom: 1px solid #CCC; margin-top: 10px;'>To Order</h3><p>To purchase, use our <a href='http://betatest.thewildside.com/main.php?g2_view=html.Forms' target='_blank'>write-in order-form</a> or call <span style='white-space: nowrap;'>(800) 421-3130</span> or <span style='white-space: nowrap;'>(818) 837-5000.</span></p><p>Minimum order of 100 dozen for above pricing.";
			
			var vpHeight = YAHOO.util.Dom.getViewportHeight();
			if (vpHeight < 600){
				vpHeight = vpHeight - 40;
				pageDisplayDialog.cfg.setProperty("height", vpHeight+"px");
				vpHeight = vpHeight - 100;
				YAHOO.util.Dom.setStyle('photoContainerPhoto', 'height', vpHeight+"px");
				YAHOO.util.Dom.setStyle('photoContainerPhoto', 'overflow', 'scroll');
			}else{
				YAHOO.util.Dom.setStyle('photoContainerPhoto', 'height', YAHOO.util.Dom.getStyle('photoTransfer', 'height')	);
			}
			
			YAHOO.util.Dom.setStyle('photoContainerOrderInfo', 'margin', YAHOO.util.Dom.getStyle('photoContainerPhoto', 'height') + ' 0 0 0');
			YAHOO.util.Dom.setStyle('photoContainerOrderInfo', 'width', YAHOO.util.Dom.getStyle('photoContainerPhoto', 'width'));
			
			if (BrowserDetect.browser == "Explorer"){
				  pageDisplayDialog.cfg.setProperty("fixedcenter", "true");
				if (BrowserDetect.version <= 6){
				  //remove stock id module
				  var x = document.getElementById('photoContainer');
				  var y = document.getElementById('photoContainerOptions');
				  x.removeChild(y);
				}
			}
}

function setFavorite(itemId, userId, toggle){
					
	  var favToggle = null;
	  if (toggle == "verify"){
		  
		  $.ajax({
			  url: "/themes/wildsidegothic/database_access/myFavsVerify.php?userId=" + userId +"&itemId=" + itemId,
			  context: document.body,
			  success: function(data){
					if (data.match(itemId)){
						$("#favBadge-button").css("display","none");
						$("#favBadgeRemove-button").css("display","block");
					}else{
						$("#favBadge-button").css("display","block");
						$("#favBadgeRemove-button").css("display","none");
					}
			  }
		  });
	  
	  }else if (toggle == "add"){
		  
		  if (document.getElementById('photoContainerShowOn')){
			document.getElementById('photoContainerShowOn').innerHTML = "<div id='itemLoader'>"+progressBar+"</div>";
		  }
		  
		  var favItemCount = $("#favItemCount").html();
		  favItemCount = favItemCount * 1;
	  
		  $.ajax({
			  url: $("#favBadge-button").attr("href"),
			  context: document.body,
			  success: function(data){
					$("#favBadge-button").css("display","none");
					$("#favBadgeRemove-button").css("display","block");
					favItemCount = favItemCount +1;
					$("#favItemCount").html(favItemCount);
					if (document.getElementById('photoContainerShowOn')){
					  document.getElementById('photoContainerShowOn').innerHTML = null;
					}
			  }
		  });
		  
	  }else if (toggle == "remove"){
		  
		  if (document.getElementById('photoContainerShowOn')){
			document.getElementById('photoContainerShowOn').innerHTML = "<div id='itemLoader'>"+progressBar+"</div>";
		  }
	  
		  $.ajax({
			  url: $("#favBadgeRemove-button").attr("href"),
			  context: document.body,
			  success: function(data){
					$("#favBadge-button").css("display","block");
					$("#favBadgeRemove-button").css("display","none");
					favItemCount = favItemCount -1;
					$("#favItemCount").html(favItemCount);
					if (document.getElementById('photoContainerShowOn')){
					  document.getElementById('photoContainerShowOn').innerHTML = null;
					}
			  }
		  });
		  
	  }
	  
}


function itemData(itemId, userId){
	
			//navigator
			if (document.getElementById('breadcrumbLink_2')){
			var location = document.getElementById('breadcrumbLink_2').innerHTML;
			if (!location.match('Favorites')){
				if (!location.match('Keyword')){
					changeSize('naviBlock', '', '30', .6);
				}
			}
			}
	
			//make cart buttons
			//Show Favorites Button
			setFavorite(itemId, userId, "verify");
			
			
			//Add To Cart Button
			if ($('#addToCartButton-button')){
				var cartURL = $('#addToCartButton-button').attr('href');
				$('#addToCartButton-button').attr('href','#');
				
				$('#addToCartButton-button').click(function() {
					appendToCart(itemId, cartURL);
				});
						
			}
							
			
			//set stock id title
			if (document.getElementById('stockId')){
			  var stockId = document.getElementById('stockId').innerHTML;
				if (stockId != null){
				itemDisplayDialog.setHeader("<h3 id='newStockId'>"+stockId+"</h3>");
				}else{
				itemDisplayDialog.setHeader("<h3 id='newStockId'>Item</h3>");
				}
			}
				
			
			//get other meta data
			if (document.getElementById('cfv_AllowPrice')){
				var prices = YAHOO.util.Dom.getElementsByClassName('itemPrice', 'div'); 
				YAHOO.util.Dom.setStyle(prices, 'display', 'block');
			}
			
			if (document.getElementById('cfv_ShowOn')){
				var itemShowOn = document.getElementById('cfv_ShowOn').innerHTML;
			}else{
				var itemShowOn = "nothing";
			}
			
			if (document.getElementById('cfv_PressOn')){
				var itemPressOn = document.getElementById('cfv_PressOn').innerHTML;
			}else{
				var itemPressOn = null;
			}
			
			if (document.getElementById('cfv_Texture')){
				var itemTexture = document.getElementById('cfv_Texture').innerHTML;
				changeItemTexture(itemTexture);
			}else{
				YAHOO.util.Dom.setStyle('photoContainerTexture', 'backgroundImage', 'none');
			}
			
			 if (document.getElementById('cfv_TransferType')){
				var transferType = document.getElementById('cfv_TransferType').innerHTML;
				if (transferType == 'sleeves'){
					document.getElementById('teeModuleNotice').innerHTML = '<p class="smallNotice">This item is a set of <strong>SLEEVES</strong>.</p>';
					var stockId = document.getElementById('newStockId').innerHTML;
					document.getElementById('newStockId').innerHTML = stockId;
				}else if (transferType == 'pocket'){
					document.getElementById('teeModuleNotice').innerHTML = '<p class="smallNotice">This item is a <strong>POCKET</strong>.</p>';
					var stockId = document.getElementById('newStockId').innerHTML;
					document.getElementById('newStockId').innerHTML = stockId;
				}else if (transferType == 'included_pocket'){
					document.getElementById('teeModuleNotice').innerHTML = '<p class="smallNotice">This <strong>FREE POCKET</strong> is included with the purchase of specific transfers. This item cannot be purchased seperately.</p>';
					var stockId = document.getElementById('newStockId').innerHTML;
					document.getElementById('newStockId').innerHTML = stockId;
					YAHOO.util.Dom.setStyle('addToCartButton', 'display', 'none');
					YAHOO.util.Dom.setStyle('favoritesModule', 'display', 'none');
					YAHOO.util.Dom.setStyle('naviBlock', 'display', 'none');
				}else if (transferType == 'cut-a-part'){
					document.getElementById('teeModuleNotice').innerHTML = '<p class="smallNotice">This is a <br /><strong>CUT-A-PART</strong> sheet, containing several designs on each transfer.</p>';
					var stockId = document.getElementById('newStockId').innerHTML;
					document.getElementById('newStockId').innerHTML = stockId;
				}else if (transferType == 'child'){
					document.getElementById('teeModuleNotice').innerHTML = '<p class="smallNotice">This item is sized for <strong>CHILDREN</strong>.</p>';
					var stockId = document.getElementById('newStockId').innerHTML;
					document.getElementById('newStockId').innerHTML = stockId;
				}else if (transferType == 'oversize'){
					document.getElementById('teeModuleNotice').innerHTML = '<p class="smallNotice">This item is <strong>OVERSIZED</strong>.</p>';
					var stockId = document.getElementById('newStockId').innerHTML;
					document.getElementById('newStockId').innerHTML = stockId;
				}else if (transferType == 'pant_legs'){
					document.getElementById('teeModuleNotice').innerHTML = '<p class="smallNotice">This item conains <strong>PANT LEGS</strong>.</p>';
					var stockId = document.getElementById('newStockId').innerHTML;
					document.getElementById('newStockId').innerHTML = stockId;
				}else if (transferType == 'namedrop'){
					document.getElementById('teeModuleNotice').innerHTML = '<p class="smallNotice">This item is a <strong>NAME DROP</strong>.</p>';
					var stockId = document.getElementById('newStockId').innerHTML;
					document.getElementById('newStockId').innerHTML = stockId;
				}
			} 
			
			if (document.getElementById('cfv_StandardThumbBg')){
				var itemStandardBgColor = document.getElementById('cfv_StandardThumbBg').innerHTML;
			}else{
				var itemStandardBgColor = '#AAA';
			}
			if (document.getElementById('cfv_CustomThumbBg')){
				itemBgColor = document.getElementById('cfv_CustomThumbBg').innerHTML;
			}else{
				itemBgColor = itemBackgrounds[itemStandardBgColor];
			}
			
			//change bg color
			changeItemBgColor(itemBgColor);	
				
			if (document.getElementById('cfv_DefaultSize')){
				var itemDefaultSize = document.getElementById('cfv_DefaultSize').innerHTML;
			}else{
				var itemDefaultSize = "full";
			}
						
			//Ignore size if item is not shown on shirt
			if (itemShowOn == "nothing"){
				itemDefaultSize = "full";
			}
			
			
			photoSize(itemDefaultSize, itemShowOn);
			
			
			//Lights or Darks check. Allows colors to	 change dynamically when going from Lights Only to Lights and Darks.
			if (document.getElementById('cfv_PressOn')){
			var itemPressOn = document.getElementById('cfv_PressOn').innerHTML;
				if (itemPressOn == "LightsOnly"){
					var x = YAHOO.util.Selector.query('#swatches .dark');
					YAHOO.util.Dom.setStyle(x, 'display', 'none');
				}else if (itemPressOn == "DarksOnly"){
					var x = YAHOO.util.Selector.query('#swatches .light');
					YAHOO.util.Dom.setStyle(x, 'display', 'none');
				}else if (itemPressOn == "BlackOnly"){
					document.getElementById('swatches').innerHTML = "<p>This item is designed for <strong>Black</strong> garments only.</p>";
				}else if (itemPressOn == "Disable"){
					document.getElementById('swatches').innerHTML = "<p>Color previewing is not available for this item.</p>";
				}else{
					var x = YAHOO.util.Selector.query('#swatches .light');
					var y = YAHOO.util.Selector.query('#swatches .dark');
					YAHOO.util.Dom.setStyle(x, 'display', 'block');
					YAHOO.util.Dom.setStyle(y, 'display', 'block');
				}
					
			}
			 
}

function loadItem(itemId, userId){
	
	changeItemBgColor ('#666');
	
	var loadItemDetails = {
			
		startTransaction:function() {
			
			YAHOO.util.Dom.setStyle('photoContainerTexture', 'backgroundImage', 'none');
							  
			YAHOO.util.Connect.asyncRequest('GET', '/main.php?g2_itemId=' + itemId, callback, null);
			document.getElementById('photoContainerShowOn').innerHTML = "<div id='itemLoader'>"+progressBar+"</div>";
			
			},
		  
		responseSuccess:function(o){
			
			document.getElementById('photoWrapper').innerHTML = o.responseText;
			
			YAHOO.util.Dom.setStyle('photoContainer', 'display', 'block');
					  
						  
			if (document.getElementById('cfv_FullPage')){
				pageData();
			}else{
				if (userId){
				  itemData(itemId, userId);
				}else{
				  itemData(itemId);
				}
			}
			
			
			},
		  
		responseFailure:function(o){
			
			notify('warn', o.statusText, o.responseText);
			
			
			}
	}
	
	var callback =
	{
	  success:loadItemDetails.responseSuccess,
	  failure:loadItemDetails.responseFailure,
	  scope:loadItemDetails
	};
	
	
	loadItemDetails.startTransaction();
}

function printThis(container){

var printItems = YAHOO.util.Dom.getElementsByClassName('printLink', 'div');
				
		for (var i=0;i<printItems.length;i++)	{
			YAHOO.util.Dom.setStyle(printItems[i], 'display', 'none');
		}
		
		var divToPrint=document.getElementById(container);
		newWin= window.open("printPae");
		newWin.document.write(divToPrint.outerHTML);
		newWin.print();
				
		for (var i=0;i<printItems.length;i++)	{
			YAHOO.util.Dom.setStyle(printItems[i], 'display', 'block');
		}
		newWin.close();
}

function getBg(itemId, itemContainer){
	
var imageBlockImageDetails = {
			
		startTransaction:function() {
			
			YAHOO.util.Connect.asyncRequest('GET', '/themes/wildsidegothic/database_access/getBg.php?itemId=' +itemId, callback, null);
			
			},
		  
		responseSuccess:function(o){
			
			if (itemContainer == null){
				itemContainer = 'imageBlockImage_'+itemId;
			}
			
			var items = YAHOO.util.Dom.getElementsByClassName(itemContainer, 'li');
			var data = o.responseText.split(", ");
				if (data[1] != null){
							  
				  for (var i=0;i<items.length;i++)	{
					  YAHOO.util.Dom.setStyle(items[i], 'backgroundColor', data[1]);
				  }
				  
				}
				if (data[0] != "custom"){
				  if (data[0] != null){
					data = data[0];
					for (var i=0;i<items.length;i++)	{
					  YAHOO.util.Dom.setStyle(items[i], 'backgroundColor', itemBackgrounds[data]);
					}
				  }
				}
				if (data[2] != null){
				  changeItemTexture(data[2], itemContainer);
				}
					
			},
		  
		responseFailure:function(o){
			
			return;
			
			}
	}
	
	
	var callback =
	{
	  success:imageBlockImageDetails.responseSuccess,
	  failure:imageBlockImageDetails.responseFailure,
	  scope:imageBlockImageDetails
	};
	
	
	imageBlockImageDetails.startTransaction();
	
}



var getProfile = function(userName, email){
  
	var id = {
			
		startTransaction:function() {
			
			notify('none', 'Locating user profile...', '<br />' + progressBar);
			if (email == null){
			YAHOO.util.Connect.asyncRequest('GET', 'http://thewildside.com/themes/wildsidegothic/database_access/getUserIdByUserName.php?user='+userName, idCallback, null);
			}else{
			YAHOO.util.Connect.asyncRequest('GET', 'http://thewildside.com/themes/wildsidegothic/database_access/getUserIdByEmail.php?email='+email, idCallback, null);
			}
			
			},
		  
		responseSuccess:function(o){
				
				window.location = "/main.php?g2_view=members.MembersProfile&g2_userId="+o.responseText;
						
			},
		  
		responseFailure:function(o){
			
			notificationStop();
			notify('warn', 'The user profile could not be opened', '<br />' + o.responseText);
				
			
			}
	}
	
	
	var idCallback =
	{
	  success:id.responseSuccess,
	  failure:id.responseFailure,
	  scope:id
	};
	
	
	id.startTransaction();

}



var getCustId = function(userId){
	
  
	var custId = {
			
		startTransaction:function() {
			
			YAHOO.util.Connect.asyncRequest('GET', 'http://thewildside.com/themes/wildsidegothic/database_access/getCustIdByUserId.php?userId='+userId, custIdCallback, null);
			
			},
		  
		responseSuccess:function(o){
				
				document.getElementById('custIdInput').value = o.responseText;
						
			},
		  
		responseFailure:function(o){
				
				
				document.getElementById('custIdValue').innerHTML = o.responseText;
			
				
			
			}
	}
	
	
	var custIdCallback =
	{
	  success:custId.responseSuccess,
	  failure:custId.responseFailure,
	  scope:custId
	};
	
	
	custId.startTransaction();

}



var getCustCompany = function(userId){
	
  
	var custCompany = {
			
		startTransaction:function() {
			
			YAHOO.util.Connect.asyncRequest('GET', 'http://thewildside.com/themes/wildsidegothic/database_access/getCustCompanyByUserId.php?userId='+userId, custCompanyCallback, null);
			
			},
		  
		responseSuccess:function(o){
				
				document.getElementById('custCompanyInput').value = o.responseText;
						
			},
		  
		responseFailure:function(o){
				
				
				document.getElementById('custCompanyValue').innerHTML = o.responseText;
			
				
			
			}
	}
	
	
	var custCompanyCallback =
	{
	  success:custCompany.responseSuccess,
	  failure:custCompany.responseFailure,
	  scope:custCompany
	};
	
	
	custCompany.startTransaction();

}

var addCustId = function(userId, custId, custCompany){
	
  
	var addCustId = {
			
		startTransaction:function() {
			notify('none', 'Profile Update...', '<br />' + progressBar);
			YAHOO.util.Connect.asyncRequest('GET', 'http://thewildside.com/themes/wildsidegothic/database_access/addCustId.php?custId='+custId+'&userId='+userId+'&custCompany='+custCompany, addCustIdCallback, null);	
			},
		  
		responseSuccess:function(o){
			notificationStop();
			},
		  
		responseFailure:function(o){
			notificationStop();
			notify('warn', 'Could Not Update', '');
			}
	}
	
	
	var addCustIdCallback =
	{
	  success:addCustId.responseSuccess,
	  failure:addCustId.responseFailure,
	  scope:addCustId
	};
	
	
	addCustId.startTransaction();

}


var getSession = function(userName){
  
	var sess = {
			
		startTransaction:function() {
			notify('none', 'Locating open user sessions...', '<br />' + progressBar);
			YAHOO.util.Connect.asyncRequest('GET', 'http://thewildside.com/themes/wildsidegothic/database_access/getSessionsByUserName.php?user='+userName, sessCallback, null);
			},
		  
		responseSuccess:function(o){
			
			if (o.responseText == ""){
				notificationStop();
				notify('warn', 'No Open Sessions', 'This user has not added any items to their shopping cart and/or all previous orders have been removed from our system for normal maintenance.');
			}else{
				window.location = "/main.php?g2_view=core.SiteAdmin&g2_subView=checkout.AdminOrder&g2_transactionId="+o.responseText;
			}
						
			},
		  
		responseFailure:function(o){
			notificationStop();
			notify('warn', 'The user profile could not be opened', '<br />' + o.responseText);
			}
	}
	
	
	var sessCallback =
	{
	  success:sess.responseSuccess,
	  failure:sess.responseFailure,
	  scope:sess
	};
	
	
	sess.startTransaction();

}

//Video modal
function youTube(title, id, obj){
	if (obj == null){
		obj = '#youtube_';
	}
	
	$(obj+id).qtip(
	 {
		content: {
		   title: {
			  text: title,
			  button: 'Close'
		   },
		   text: '<iframe width="720" height="405" src="http://www.youtube.com/embed/'+id+'" frameborder="0" allowfullscreen></iframe>'
		},
		position: {
		   target: $(document.body), // Position it via the document body...
		   corner: 'center' // ...at the center of the viewport
		},
		show: {
		   when: 'click', // Show it on click
		   solo: true // And hide all other tooltips
		},
		hide: false,
		style: {
		   width: 765,
		   height: 405,
		   padding: '14px',
		   border: {
			  width: 9,
			  radius: 9,
			  color: '#666666'
		   },
		   name: 'light'
		},
		api: {
		   beforeShow: function()
		   {
			  // Fade in the modal "blanket" using the defined show speed
			  $('#qtip-blanket').fadeIn(this.options.show.effect.length);
		   },
		   beforeHide: function()
		   {
			  // Fade out the modal "blanket" using the defined hide speed
			  $('#qtip-blanket').fadeOut(this.options.hide.effect.length);
		   },
		   onHide: function()
		   {
			  // Fade out the modal "blanket" using the defined hide speed
			  $(obj+id).qtip("destroy");
		   }
		}
	 });
	
	 // Create the modal backdrop on document load so all modal tooltips can use it
	 $('<div id="qtip-blanket">')
		.css({
		   position: 'absolute',
		   top: $(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
		   left: 0,
		   height: $(document).height(), // Span the full document height...
		   width: '100%', // ...and full width
	
		   opacity: 0.7, // Make it slightly transparent
		   backgroundColor: 'black',
		   zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
		})
		.appendTo(document.body) // Append to the document body
		.hide(); // Hide it initially
	
}


function runSearch(query){
	//if string, run keyword search
	if (isNaN(query)){
		window.location = "http://thewildside.com/main.php?g2_view=keyalbum.KeywordAlbum&g2_keyword="+query;
	}else{
		window.location = "http://thewildside.com/main.php?g2_view=title.Contain&g2_chars="+query;
	}
}


function pageDefaults (userId){

//Automatically display item popup window
if (YAHOO.util.Cookie.get("itemDisplay")){
var itemId = YAHOO.util.Cookie.get("itemDisplay");
  if (itemId != 'skip'){
	  if (BrowserDetect.browser == 'Explorer'){
		if (BrowserDetect.version <= '6'){
		  return;
		}else{
		  itemDisplay(itemId);
		}
	  }else{
		  itemDisplay(itemId);
	  }
  }
YAHOO.util.Cookie.remove("itemDisplay", { expires: new Date("January 12, 2025"), path: "/" });
}


//update 'members online' counter
if (document.getElementById('menuMembersOnline')){
	var parent = document.getElementById('menuMembersOnline');
	var onlineCount = parent.getElementsByTagName('li').length;
	onlineCount = (onlineCount - 3);
	document.getElementById('onlineCount').innerHTML = onlineCount;
	
}

//update 'item in basket' counter
if (document.getElementById('cartCountAlbum')){
	if (document.getElementById('cartCountAlbum').innerHTML != 0){
		YAHOO.util.Dom.setStyle('viewCartButton', 'border', '2px #266d88 solid');
		YAHOO.util.Dom.setStyle('viewCartButtonAccepted', 'display', 'block');
	}
}

//update rhinestone package button
if ($(".buythis")){
	var itemId = $(".buythis").attr("rel");
	$(".buythis").click(function() {
	  itemDisplay(itemId);
	});
}

//update 'favorites' counter
$.ajax({
	url: "/themes/wildsidegothic/database_access/myFavsCount.php?userId="+userId,
	context: document.body,
	success: function(data){
			if (document.getElementById('favItemCount')){
			  document.getElementById('favItemCount').innerHTML = data;
			}
	}
});

//Logic based on URL, not ideal but works reliably and quickly

//if doing a seearch, focus cursor in search box
var loc = String(window.location);
if (loc.match("title")){
	document.getElementById("giFormTitle").focus();
}else if (loc.match("keyalbum")){
	document.getElementById("searchKWCriteria").focus();
}else if (loc.match("core.ItemAdmin")){
	itemId = loc.split("&g2_itemId=");
	getBg(itemId[1], "itemThumb");
}

}
