(function($, undefined)
{
    $(function()
	{
		
		$("a#item-enlarge").fancybox();
		
		//Font Replacement 
		//Cufon.replace('ul#sub-nav li a, .main-nav, p.delivery, h1, h2, h3, h4, p.enquiries, .strapline-banner p', {hover: true});
		
		//Item Page Tabs
		$(function () 
		{
			var tabContainers = $('div.tabs > div');
			
			$('div.tabs ul.item-info a').click(function () 
			{
				tabContainers.hide().filter(this.hash).show();
				
				$('div.tabs ul.item-info a').removeClass('selected');
				$(this).addClass('selected');
				
				return false;
			}).filter(':first').click();
			
		});
		
		//Item Description
		$('#extended-desc').hide();
		$('#less').hide();
		
		$("#more").click(function()
		{
			$("#extended-desc").show("slow");
			$('#more').hide();
			$('#less').show();
		});
		
		$("#less").click(function()
		{
			$('#more').show();
			$('#less').hide();
			$("#extended-desc").hide("slow");
		});

		
		//Placeholder text
		if (!Modernizr.input.placeholder)
		{
			$('#search').formhint();
			$('#login-email').formhint();
			$('#password').formhint();
			$('#personalise_dob').formhint();
		}
		
		
		// Homepage Reviews
		if ($('#reviews').length)
        {
			$('#reviews').cycle({
				fx: 'scrollUp',
				speed: 2500 
			});
		}
		
		// Brandscroller
		// Related
		$('#related').brandscroll(
		{
			autoplay : false,
			autoheight: false
		});
		
		$('.related-right').brandscroll_button(
		{
			el : '#related',
			direction : 'right',
			force : 690
		});
		
		$('.related-left').brandscroll_button(
		{
			el : '#related',
			direction : 'left',
			force : 690
		});
		
		// Complete
		$('#complete').brandscroll(
		{
			autoplay : false,
			autoheight: false
		});
		
		// Complete
		$('#completefull').brandscroll(
		{
			autoplay : false,
			autoheight: false
		});
		
		$('.complete-right').brandscroll_button(
		{
			el : '#complete',
			direction : 'right',
			force : 690					
		});
		
		$('.complete-full-right').brandscroll_button(
		{
			el : '#completefull',
			direction : 'right',
			force : 828					
		});
		
		$('.complete-left').brandscroll_button(
		{
			el : '#complete',
			direction : 'left',
			force : 690
		});
		
		$('.complete-full-left').brandscroll_button(
		{
			el : '#completefull',
			direction : 'left',
			force : 828
		});
		
		
		//Centering text on promotional boxes
		$('.promotional-text p').centerscreen({
			parent : 1,
			horizontal : 0,
			animate : 0,
			onresize : 0
		});
		
		
		//Homepage Slideshow
		if ($('#accordion-container').length)
        {
			$(function() {
				$('a').focus(function(){$(this).blur();})
				slider_acc.setup('#accordion-container');
			});
			
			slider_acc.auto_play = true;
			slider_acc.auto_close = true;
			slider_acc.auto_close_after_time = false;
		}
		
		/*//Map
		//Google Map
		if ($('#map').length)
        {
			
			var myLatlng = new google.maps.LatLng(56.459046,-2.971279);
			var myOptions = 
			{
				zoom: 14,
				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:"Simply Rooms"
			});
		}*/
		
		//Checkout
		
		//Hide Delivery address
		/*if ($("#shipping-address").is(":checked"))
		{
           $("#ship-address").css("display","none");
           $("#ship-payment").css("display","none");
		} else		
		{
			$("#payment").hide("fast");
			$(".billing-basket-terms").hide("fast");
		}
		*/
		
		
		
		$("#shipping-address").click(function()
		{
			if ($("#shipping-address").is(":checked"))
			{
				$("#ship-address").hide("fast");
				$("#ship-payment").hide("fast");
				$("#payment").show("fast");
				$(".billing-basket-terms").show("fast");
			}
			else
			{     
				$("#ship-address").show("fast");
				$("#ship-payment").show("fast");
				$("#payment").hide("fast");
				$(".billing-basket-terms").hide("fast");
			}       
		});
		
		//US States
		$('#us_bill_states').hide();
		$('#us_ship_states').hide();
		
		if($('#country').val()=='US')
		{
			$('#us_bill_states').slideDown();
		}
		
		if($('#country').val()=='GB')
		{
			$('.uk-county').slideDown();
		}
		
		if($('#shipping_country').val()=='US')
		{
			$('#us_ship_states').slideDown();
		}     
		
		$('#country').change(function()
		{
			if($('#country').val()=='US')
			{
				$('#us_bill_states').slideDown();
			}
			if(($('#country').val()!='US')&&($('#us_bill_states').is(':visible')))
			{
				$('#us_bill_states').slideUp();
			}
			
			//UK Counties
			if($('#country').val()=='GB')
			{
				$('.uk-county').slideDown();
			}
			if(($('#country').val()!='GB')&&($('.uk-county').is(':visible')))
			{
				$('.uk-county').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();
			}
			
			//UK Counties
			if($('#shipping_country').val()=='GB')
			{
				$('#ship-address .uk-county').slideDown();
			}
			
			if(($('#shipping_country').val()!='GB')&&($('#ship-address .uk-county').is(':visible')))
			{
				$('#ship-address .uk-county').slideUp();
			}
		});
		
	});
	
})(jQuery);
