/* include any js files here */
$(document).ready(function()
	{
		$('div.thumbFade').hover(function(){
											var div = $('> div', this);
											if (div.is(':animated')) {
											div.next().stop().fadeTo(100,1);
											} else { div.fadeIn(250);}
											}, function() {
											var div = $('> div', this);
											if (div.is(':animated')) {
											div.next().stop().fadeTo(100,0);
											} else { div.fadeOut(250);}
											});
		var options = { zoomWidth: 343,zoomHeight: 434,xOffset: 5,yOffset: 0,position: "right"};
		$('#zoomPicture').jqzoom(options);
		
		// Use this to fix the IE bug with GMP's shank dropdown boxes
		// sets Select class to "AUTO" instead of 140px because IE 
		// doesn't automattically display the entire dropdown option
		if ($.browser.msie) $('select.wide')
        .bind('focus mouseover', function() { $(this).addClass('expand').removeClass('clicked'); })
        .bind('click', function() { $(this).toggleClass('clicked'); })
        .bind('mouseout', function() { if (!$(this).hasClass('clicked')) { $(this).removeClass('expand'); }})
        .bind('blur', function() { $(this).removeClass('expand clicked'); });
								
	});
	
function openPopUp (url,name,w,h) {
window.open(url, name, 'width=' + w + ', height=' + h + ', ' +'location=no, menubar=no, ' +'status=no, toolbar=no, scrollbars=no, resizable=no');
}
inc('/modalPopup.js');

function inc(filename){
	document.write('<script src="'+filename+'" type="text/javascript"></script>');
	
}

// JavaScript Document
function searchBoxSubmit(searchValue) {
	if(searchValue!="" && searchValue!="Enter search term or catalog style #") {
		return(true);
	}
	else {
		return(false);
	}
}
function change(ID, setting)
{	
	var div = $("#"+ID+"");
	if (setting ==1)
	{
		if (div.is(':animated')) {
			div.stop().fadeTo(300,0);
		}
		else
		{
		div.fadeOut(300);
		}
	}
	else
	{
		if (div.is(':animated')) {
			div.stop().fadeTo(300,1);
		}
		else
		{
			div.fadeIn(300);	
		}
	}
	
	
}

function exchangePhoto(NAME,ID){
	$('#thumb_'+ID+'').css('border','solid 1px black');
	document.getElementById('mainProductPhoto').innerHTML="<a id='zoomPicture' href='/image/zoom/"+NAME+"' style='border:0px solid #fff;'><img src='/image/327x436/"+NAME+"' border=0 width=327 height=436></a>";

	//document.getElementById('mainProductPhoto').innerHTML="<img src='/image/327x436/"+NAME+"' border=0 width=327 height=436>";

	var options = { zoomWidth: 343,zoomHeight: 434,xOffset: 5,yOffset: 0,position: "right"};
	$('#zoomPicture').jqzoom(options);
}
function popUpColor(url, color, e){
	e = $.event.fix(e);
	var x = e.pageX; 
	var y = e.pageY;
	object = document.getElementById("colorPopUp");
	mainPhoto = document.getElementById("mainProductPhoto");	
	pheight=mainPhoto.offsetHeight;
	pwidth=mainPhoto.offsetWidth;
	object.style.visibility = "visible";
	//object.style.top = "" + y -190+ "px";
	//object.style.left = "600px";
//	pheight=pheight+68;
//	pwidth=pwidth-36;	
	pheight=pheight+100;
	pwidth=pwidth-250;	
	object.style.top = "" + pheight +  "px";
	object.style.left = "" + pwidth +  "px";	
	object.innerHTML = "<img src='" + url + "' width=100 height=100>";
}
function popHideColor()
{	
	object = document.getElementById("colorPopUp");
	object.style.visibility = 'hidden';
}
function selectColor(color)
{
	document.getElementById("" + color + "").selected = true;
}
function openInventory(partNumber,insertNo)
{
	var position = $("#stockCheck"+partNumber).offset();
	var browserWidth = $(document).width();
	var browserHeight = $(document).height();	
		
	$("#enlargePhotoDiv").css({
							  'width' : "100%", 
							  'height' : browserHeight, 
							  'background-color' : '#ffffff',
							  "opacity" : 0,
							  'display' : 'block'
							  });
	$("#enlargePhotoDiv").animate({ opacity: .75 },500);
	$.ajax({type: "POST", url: "/showStock.php", data: {product: partNumber, insert: insertNo, width: browserWidth, height: browserHeight, position: position}, success: displayPopUp });
}
function openSizeChart(partNumber,insertNo)
{
	var sizeSelect = 'sizeSelect'+partNumber;
	var position = $("#sizeSelect"+partNumber).offset();	
	var browserWidth = $(document).width();
	var browserHeight = $(document).height();	
		
	$("#enlargePhotoDiv").css({
							  'width' :"100%", 
							  'height' : browserHeight, 
							  'background-color' : '#ffffff',
							  "opacity" : 0,
							  'display' : 'block'
							  });
	$("#enlargePhotoDiv").animate({ opacity: .75 },500);	
	$.ajax({type: "POST", url: "/showSizes.php", data: {product: partNumber, insert: insertNo, width: browserWidth, height: browserHeight, position: position}, success: displayPopUp });
}
function openSelectSizeChart(partNumber)
{
	var sizeSelect = 'sizeSelect'+partNumber;
	var position = $("#sizeSelect"+partNumber).offset();
	var check = document.getElementById(sizeSelect).value;
	var browserWidth = $(document).width();
	var browserHeight = $(document).height();	
	
	if(check == "sizeChart"){
				
		$("#enlargePhotoDiv").css({
							  'width' : "100%", 
							  'height' : browserHeight, 
							  'background-color' : '#ffffff',
							  "opacity" : 0,
							  'display' : 'block'
							  });
		$("#enlargePhotoDiv").animate({ opacity: .75 },500);
		$.ajax({type: "POST", url: "/showSizes.php", data: {product: partNumber, width: browserWidth, height: browserHeight, position: position}, success: displayPopUp }); 
		
	}
}
function openReadReviews(partNumber)
{
	var browserWidth = $(document).width();
	var browserHeight = $(document).height();	
	$("#enlargePhotoDiv").css({
							  'width' : '100%', 
							  'height' : browserHeight, 
							  'background-color' : '#ffffff',
							  "opacity" : 0,
							  'display' : 'block'
							  });
	$("#enlargePhotoDiv").animate({ opacity: .75 },500);
	$.ajax({type: "POST", url: "/getReviews.php", data: {product: partNumber, width: browserWidth, height: browserHeight}, success: displayPopUp });
}
function openSubmitReviews(partNumber, url)
{
	var browserWidth = $(document).width();
	var browserHeight = $(document).height();		
	$("#enlargePhotoDiv").css({
							  'width' : '100%', 
							  'height' : browserHeight, 
							  'background-color' : '#ffffff',
							  "opacity" : 0,
							  'display' : 'block'
							  });
	$("#enlargePhotoDiv").animate({ opacity: .75 },500);
	$.ajax({type: "POST", url: "/submitReviews.php", data: {product: partNumber, url: url, width: browserWidth, height: browserHeight}, success: displayPopUp });
}
function insertRollover(imageName, url)
{
	$("#largePhoto").html("<img src='"+url+"/image/zoom/"+imageName+"' height=560/>");	
}

function enlargePhoto(partNumber)
{
	
	var browserWidth = $(document).width();
	var browserHeight = $(document).height();	
	$("#enlargePhotoDiv").css({
							  'width' : '100%', 
							  'height' : browserHeight, 
							  'background-color' : '#ffffff',
							  "opacity" : 0,
							  'display' : 'block'
							  });
	$("#enlargePhotoDiv").animate({ opacity: .75 },500);
	$.ajax({type: "POST", url: "/displayProductDiv.php", data: {product: partNumber}, success: displayPopUp });
}
function displayPopUp(data, status) {

	var new_data=data.split("|");	
	var position = new_data[1];
	if(position==""){
		position="40%";
	}
	$("#popUpWindow").html(new_data[0]);
	
if(navigator.appName == 'Microsoft Internet Explorer'){ //fix the top-margin in IE
	$("#popUpWindow").css({
						  'margin-top' : -(150) + 'px'
						  });
	
}else{
	$("#popUpWindow").css({
						  'margin-top' : -(150) + 'px'
						  });
}
	$("#popUpWindow").css({
						  'position': 'absolute',
						  'left' : '50%',
		                  'top' : ""+(position)+"px",
						  'margin-left' : -(550 / 2) + 'px',
						  'width' : 560 + 'px',
						  'height' : 670 + 'px',
						  'visibility': 'visible'
						  });
	
	
}
function closePhoto()
{
	$("#popUpWindow").css("visibility","hidden");
	$("#enlargePhotoDiv").css({
							  'width' : '0%', 
							  'height' : '0%', 
							  'background-color' : '#FFFFFF',
							  'opacity' : 0,
							  'display' : 'none'
							  });
}
function nextStep(distance) {
	$("#checkoutCover").animate({ marginTop: ""+distance+"" });
}
function isblank(s)
{
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}
function reportAddress(data,status){
	if (data=="NO") 
						{
							var element = document.getElementById('AddrName');
							element.style.backgroundColor="#ffffcc";
							element.style.borderColor="#ff4040";
							element.style.borderWidth="1px";
							element.style.borderStyle="solid";
							msg  = "______________________________________________________\n\n";
							msg += "You already have a location saved with that name.\n\n";
							msg += "Please select a unique name to describe this address.\n\n";
							msg += "______________________________________________________\n\n";
							element.value="";
							alert(msg);
							
							return false;
						}
						else
						{
							var element = document.getElementById('AddrName');
							element.style.backgroundColor="#FFFFFF";
							element.style.borderColor="#999999";
							element.style.borderWidth="1px";
							element.style.borderStyle="solid";	
						}
	
	
}
function reportProblem(xhr){
	alert(xhr);
}
function checkName(){
	var customer = document.getElementById('customer').value;
	var addressName = document.getElementById('AddrName').value;
		$.ajax({
				   type: "GET", 
				   url: "/nameCheck.php", 
				   data: {addressName: ""+addressName+"", customer: customer}, 
				   success: reportAddress,
				   error: reportProblem
				   });	
}
function verify(f)
{
    var msg;
    var empty_fields = "";
    var errors = "";
	var formElements = f;
	
			for(var i = 0; i < formElements.length; i++) 
				{
        			var e = formElements.elements[i];
        			if (((e.type == "text") || (e.type == "textarea") || (e.type == "password") || (e.type == "select-one") ) && !e.optional) 
						{
            				if (e.type!="select-one") 
								{
									if ( (e.value == null) || (e.value == "") || isblank(e.value)) 
										{
											e.style.backgroundColor="#ffffcc";
											e.style.borderColor="#ff4040";
											e.style.borderWidth="1px";
											e.style.borderStyle="solid";
											empty_fields += "\n          " + e.name;
											continue;
										}
	   							}	
	   							else 
								{
									if(e.selectedIndex == 0) 
											{
												e.style.backgroundColor="#ffffcc";
												e.style.borderColor="#ff4040";
												e.style.borderWidth="1px";
												e.style.borderStyle="solid";
												empty_fields += "\n          " + e.name;
												continue;
											}
	   							}
       					}
						else 
						{
	       					e.style.background="#ffffff";
							e.style.borderColor="#999";
							e.style.borderWidth="1px";
							e.style.borderStyle="solid";
						}
   				}
    				if (!empty_fields && !errors) 
						{ 
							if (typeof f.email != 'undefined') 
								{
									if(f.email.value!=f.confirmemail.value) 
										{
											alert("Your e-mail address does not match the confirmation field,\nplease correct and try again");
											return false;
										}
								}
							if(typeof f.pwd != 'undefined') 
								{
									if(f.pwd.value!=f.cpwd.value) 
										{
											alert("Your password does not match the confirmation field,\nplease correct and try again");
											return false;
										}
								}
							if(typeof f.Agree != 'undefined') 
								{
									if(f.Agree.checked==false) 
										{
											alert("You must agree to the terms & conditions when you submit your application.");
											return false;
										}
								}
									return true;
    					}	
   							msg  = "______________________________________________________\n\n"
    						msg += "Some required fields are missing. To successfully\n";
    						msg += "complete this form you must provide the information\n";
   							msg += "requested.\n";
    						msg += "\n";
    						msg += "Please verify that you have completed the form and\n";
    						msg += "re-submit. Thank You\n";
    						msg += "\n";
    						msg += "Required fields have an \"*\" next to them.\n";
    						msg += "______________________________________________________\n\n"
							//refreshAddressDropDowns(customer);
    						alert(msg);
    						return false;
}
function optIn(f) 
{	
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;
	if(((f.NewEmail.value.search(exclude) != -1)||(f.NewEmail.value.search(check)) == -1)||(f.NewEmail.value.search(checkend) == -1)) 
		{
			alert("Please enter a valid email address before trying to subscribe.");
			return false;
		}
		else 
		{
			return true;
		}
}
function clearField(text, id){
	field = document.getElementById(""+id+""); fieldContents = field.value;
	if (fieldContents == text) { field.value=""; }
}
// build the banner

products = new Array("Baltogs","Bloch","BodyWrapper","Capezio","Eurotard","Huggalugs", "laid-back-kids", "stephen-joseph", "heart-soul", "GAYNOR","Grishko","mud-pie","Mirella","Natalie","Sansha","SoDanca","Harmonie","Twenty10");

function randOrd(){
return (Math.round(Math.random())-0.5); }

products.sort(randOrd);
var arrayLinkText ="";
links = new Array();
var size = products.length;

for (q=0; q<size; q++)
	{
		links[q] = "http://www.allaboutdance.com/search/"+products[q]+"?NewSortOrder=P'";
	}
	
function slide(direction)
	{
		productArraySize = products.length;
		if (direction=='right')
			{
				$("#container").animate({marginLeft: "-200px"}, 'swing');
				var holder = products[0]; 
				var linksHolder=links[0];
				for (s=0; s<(productArraySize); s++)
					{
						products[s] = products[s+1];
						links[s] = links[s+1];
					}
				products[productArraySize-1] = holder; links[productArraySize-1]=linksHolder;
			} else {
				$("#container").animate({marginLeft: "0px"}, 'swing');
				var holder = products[productArraySize-1]; var linksHolder=links[productArraySize-1];
				for (s=(productArraySize-1); s>0; s--)
					{
						products[s] = products[s-1];
						links[s] = links[s-1];
					}
				products[0] = holder; links[0]=linksHolder;
			}
		setTimeout("redraw()", 500);
	}
function redraw()
	{
		var newHTML="";
		productArraySize = products.length;
		
		for (loop=0; loop<(productArraySize+1); loop++)
			{
				newHTML +="<span class='sliderImage'><a onClick=\"_gaq.push(['_trackEvent', 'AAD_Home_Page_Brand_Slider', '"+products[loop]+"-logo', 'clicked']);\" href='"+links[loop]+"'><img src='brands/images/"+products[loop]+".png' border='0'></a></span>";
			}
		$("#container").css("margin-left","-100px");
		$("#container").html(newHTML);
	}




