// IE Styling Fixes
$(document).ready(function() {


	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		// Side Nav
		$("#side-nav li a").each(function(){				
			var css = {"display" : "block"}
			$(this).css(css);
		});
		
		// Quick View Button
		$(".stylesCasesIcon").css("top", "170px");
		
		// Next buttons
		$(".next-button input.button").css("right", "45px");	
		
		// Material Selections
		$("#bottomSection li").css("margin-right", "15px");
		
		// Product Price
		$(".productPrice").each(function() {
			$(this).css("top", "150px");
		});
		
		$(".product-item .padding").each(function() {
			$(this).css("height", "260px");
		});
			
		$(".stylesCasesIcon").each(function() {
			$(this).css("top", "200px");		
		});
		
		$(".productPrice").each(function() {
			$(this).css("top", "170px");
		});
		
//		$(".previous-button input.button").css("bottom", "-20px");
		
//		$(".item-row, .item-row2").each(function() {
//			$(this).css("margin-bottom", "-80px");
//		});
		
//		$(".item-row-name").each(function() {
//			$(this).css("width", "90px");		
//		});
		
//		$(".item-row img").each(function() {
//			$(this).css("margin-left", "-2px");
//		});
		
//		$(".item-row-name span").each(function() {
//			$(this).css("width", "120px");
//		});
		
//		$(".item-row-color").each(function() {
//			$(this).css("width", "70px");
//		});
		
		// Homepage
		$(".homepage-product").each(function() {
			$(this).css("width", "196px");
		});
		
		$("#global-header").each(function() {
			$(this).css("width", "955px");
		});
	}

});

$(document).ready(function(){

	$('#tabs .tabDivs').hide(); // Hide all divs
	//$('#tabs div:first').show(); // Show the first div
	//$('#tabs ul li:first').addClass('active'); // Set the class of the first link to active
	
	$('#tabs ul li a').click(function(){ //When any link is clicked
		$('#tabs ul li').removeClass('active'); // Remove active class from all links
		$("#topTabsList").css("display", "none");
		$("#topTabsList2").css("display", "block");
		$(this).parent().addClass('active'); //Set clicked link class to active
		var currentTab = $(this).attr('href'); // Set variable currentTab to value of href attribute of clicked link
		//var currentTab = '#' + currentTab;
		$("[href='" + currentTab + "']").parent().addClass('active');
		//alert("Test: " + currentTab);
		$('#tabs .tabDivs').hide(); // Hide all divs
		$(currentTab).show(); // Show div with id equal to variable currentTab
		return false;
	});
});
	

var foamSelected = false;
var foamPrice = 0.0;

var utilitySelected = false;
var utilityPrice = 0.0;


$("#design-own-case").live('click', function(){
	window.location = "/design-case.html";

});

$(document).ready(function(){  
	$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);  
	
	$(".item-row-price .button").attr("value", "");
	$("#search-bar .button").attr("value", "");
});  

$(document).ready(function() {

	var currentPage = 1;
	
	if(currentPage == 1)
	{
		$("#page1On").css("display", "block");
		$("#page2On, #page3On").css("display", "none");
	}

	
	$("#nextPage").click(function() {
		
		if(currentPage == 1)
		{
			$("#page2On").css("display", "block");
			$("#page1On, #page3On").css("display", "none");
			$("#page1").toggle();
			$("#page2").toggle();
			$("#prevPage").toggle();
			currentPage++;
			
			
		}
		else if( currentPage == 2)
		{
			$("#page3On").css("display", "block");
			$("#page2On, #page1On").css("display", "none");
			
			$("#page2").toggle();
			$("#page3").toggle();
			$("#nextPage").toggle();
			currentPage++;
		}
		else if (currentPage == 3)
		{
			
			
		}	
		
	});
	$("#prevPage").click(function() {
	
		
		if(currentPage == 2)
		{
			$("#page1On").css("display", "block");
			$("#page3On, #page2On").css("display", "none");
		
			$("#page1").toggle();
			$("#page2").toggle();
			$("#prevPage").toggle();
			currentPage--;
			
		}
		else if( currentPage == 3)
		{
			$("#page2On").css("display", "block");
			$("#page3On, #page1On").css("display", "none");
		
			$("#page2").toggle();
			$("#page3").toggle();
			$("#nextPage").toggle();
			currentPage--;
			
		
		}
		else{
			$("#nextPage").toggle();
			
		}
		
	});		
	
});


function displayProduct(product) {
	$(".itemHover").css("display", "none");
	$("#" + product).css("display", "block");	
}



// Close popup window by clicking anywhere on screen
$(document).ready(function() {



	$("#CTGYconsumer-bags").click(function() {
		
		var display = "";
		var isOpen = false;
		
		// Check to see if any are open
		$(".itemHover").each(function() {
			display = $(this).css("display");	
			
			//alert("Display: " + display);
			if( display == "block")
			{
				isOpen = true;
			}			
		});
		
		if(isOpen)
		{		

			$(".itemHover").each(function() {
				//$(this).css("display", "none");
			});
		}
	});
});

 
function closeProduct() {
	$(".itemHover").css("display", "none");	
}

$(document).ready(function() {
	var price = new Number($("#thePrice").text());
	price = price.toFixed(2);
	//$("#thePrice").text(price);

});

$(document).ready(function() {
	$(".basketButton input").attr("value", "");
});


function changePrice()
{
	var text = $("#productSelectConfiguration option:selected").text();
	var index = text.indexOf('$');
	var price = text.substring( (index + 1));
	var currentPrice = getPrice();
	
	var newPrice = parseFloat(currentPrice) + parseFloat(price);
	setNewPrice(newPrice);
}

function quantity()
{
	setQuanityPrice();
	updatePrices();
}

function setQuanityPrice()
{
	var itemPrice = $("#thePrice").text();
	itemPrice = itemPrice.substring(1);	
	var quantity = $("#priceBox").val();

	if(quantity < 1)
	{
		alert("You must enter a quantity of more than 0");
		$("#priceBox").val("1");
	}
	else if( quantity.indexOf('.') != -1)
	{
		alert("Please enter an integer.");
		$("#priceBox").val("1");
	}
	else
	{
		var quantityPrice = parseFloat(itemPrice) * parseInt(quantity );	
		$("#quantityPrice").text('$' + quantityPrice.toFixed(2));
	}
}

function changeConfigTotal(type)
{
	var quantity = $("#priceBox").val();
	var currentTotal = $("#configTotal").text();

	if( type != "Color")
	{
		if (type == "Configuration")
		{
			foamSelected = ! foamSelected;
			
			if (foamSelected)
			{		
				var text = $("#productSelectConfiguration option:selected").text();
				var index = text.indexOf('$');
				
				if (index != -1)
				{
					var price = text.substring( (index + 1));
					foamPrice = price;
				}
			}
			else
			{
				price = foamPrice * -1;			
			}				

		}
		else
		{
			utilitySelected = ! utilitySelected;
			
			if(utilitySelected)
			{			
				var text = $("#productSelectUTIL-Accessory option:selected").text();
				var index = text.indexOf('$');
				
				if (index != -1)
				{
					var price = text.substring( (index + 1));
					utilityPrice = price;
					
				}	
			}
			else
			{
				price = utilityPrice * -1;			
			}
		}
		
		newPrice = parseFloat(currentTotal) + ( parseFloat(price) * parseInt(quantity) );
		$("#configTotal").text(newPrice.toFixed(2));
		updatePrices();
	}
}

function updatePrices()
{
	// Get quanitity price
	var quantityPrice = $("#quantityPrice").text();
	quantityPrice = quantityPrice.substring(1);	
	
	// Get config sub total
	var configTotal = $("#configTotal").text()
	
	// Compute total
	var newPrice = parseFloat(quantityPrice) + parseFloat(configTotal);
	
	// Update price on page
	$("#priceShown").text("Price : $" + newPrice.toFixed(2));
}






$(document).ready(function() {

	$(".thePrice").each(function(index) {
	
		var price = parseFloat($(this).text());
		price = price.toFixed(2);
		//alert(price);
		$(this).text('$' + price);
		return true;
	});
	
});


$(document).ready(function (){

	$(".sideNavButton").each(function () {
		$(this).parent().css("border-bottom", "none");
	});
});
