(function($, undefined)
{
    $(function()
	{
		
		//All JS functions to be included in here, not the template files!
		
		//Cufon.replace('.item-information h1, .item-information p.price, h2.checkout, #order-summary h1'); 
		
		//Slideshow
		if ($('#slideshow').length)
        {
			//$('#slider').cycle({
			//	fx: 'fade'				
			//});
            $('#slideshow').orbit({
				directionalNav: false,
				bullets: true,
				animationSpeed: 1600
			});
		}
		
		//Dropdowns
		//$.simpledropdown(".sort");
		
		//Placeholders - Modernizr no worky :(
		$('#login-email').formhint();
		$('#password').formhint();
		$('#search').formhint();
		$('#search-field').formhint();
		$('#email-signup').formhint();
		
		// Item Tabs
		if ($('.tabs').length)
        {
			{
				var tabContainers = $('div.tabs > div');
				tabContainers.hide().filter(':first').show();
				
				$('div.tabs ul.description-nav a').click(function () {
						tabContainers.hide();
						tabContainers.filter(this.hash).show();
						$('div.tabs ul.description-nav a').removeClass('selected');
						$(this).addClass('selected');
						return false;
				}).filter(':first').click();
			}
		}
		
		//Checkout Page
		//Placeholder text
		$('#login-email').formhint();
		$('#password').formhint();
		
		
		//Hide Delivery address
		if ($("#shipping-address").is(":checked"))
		{
			$("#ship-address").css("display","none");
			$("#payment").show();
		}
		else
		{
			$("#ship-address").show();
			//$("#payment").hide();
		}
    
		
		$("#shipping-address").click(function()
		{
			if ($("#shipping-address").is(":checked"))
			{
				$("#ship-address").slideUp("slow");
				$("#payment").slideDown("fast");
			}
			else
			{     
				$("#ship-address").slideDown('slow');
				$("#payment").slideUp("fast");
			}       
		});
		
		//US States
		$('#us_bill_states').hide();
		$('#us_ship_states').hide();
		
		if($('#country').val()=='US')
		{
			$('#us_bill_states').show("slow");
		}
		
		if($('#ship-country').val()=='US')
		{
			$('#us_ship_states').show("slow");
		}     
		
		$('#country').change(function()
		{
			if($('#country').val()=='US')
			{
				$('#us_bill_states').slideDown();
			}
			if(($('#country').val()!='US')&&($('#us_bill_states').is(':visible')))
			{
				$('#us_bill_states').slideUp();
			}
		});
		
		$('#shipping_country').change(function()
		{
			if($('#shipping_country').val()=='US')
			{
				$('#us_ship_states').slideDown();
			}
			
			if(($('#shipping_country').val()!='US')&&($('#us_ship_states').is(':visible')))
			{
				$('#us_ship_states').slideUp();
			}
		});
		
		//IE6 Hover
		$('#bag-items tr').hover(function() 
		{
			$(this).addClass('table-hover');
		}, 
		function() 
		{
			$(this).removeClass('table-hover');
		});
		
		//Brand Pop ups
		
		$('.brands').each(function(i) {
			var child = $(".extra", this);
			$(child).animate(
					{bottom: '-40px'},
					{duration:100}
			);
			
			
			$(this).hover(function() {
				$(child).animate(
						{bottom: '0px'},
						{duration:300}
				);
			}, 
			function() {
				$(child).animate(
						{bottom: '-40px'},
						{duration:300}
				);	
			});
		});
		
		
		
		//Google Map
		if ($('#map').length)
        {
			var myLatlng = new google.maps.LatLng(56.460937,-2.968991);
			var myOptions = 
			{
				zoom: 15,
				center: myLatlng,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			}
			
			var map = new google.maps.Map(document.getElementById("map"), myOptions);
			
			var marker = new google.maps.Marker(
			{
				position: myLatlng, 
				map: map,
				title:"Shush"
			});
		}
		
	});
	
})(jQuery);
