(function($, undefined)
{
    $(function()
	{
		
		//All JS functions to be included in here, not the template files!
		
		//Logo Fade
		$('.header a.logo').delay(100).fadeIn(2500);		
		
		//Slideshow
		if ($('#slideshow').length)
        {
			$('#slideshow ul')
			.after('<div id="slide-nav">') 
			.cycle({ 
				pager: '#slide-nav',
				prev: '#prev-featured',
				next: '#next-featured'
			});
		}
		
		//Placeholder text
		if (!Modernizr.input.placeholder)
		{
			$('#email-subscribe').formhint();
		}
		
		//Fancybox	
		function formatTitle(title, currentArray, currentIndex, currentOpts)
		{
			return '<div id="fancybox-ej-title">' + (title && title.length ?  title : '' )+ '</div>';
		}
		
		$("a.fancy").fancybox({
			'titlePosition'		: 'inside',
			'titleFormat'		: formatTitle
		});
		
		$("a.fancytable").fancybox({
			'titlePosition'		: 'inside',
			'transitionIn'		: 'none',
			'transitionOut'		: 'none'
		});
		
		//Brand Pop ups
		if ($('.extra').length)
        {
			$('.brands').slidepanel({
				slideID : '.extra',
				speed_in : 500,
				speed_out : 500				
			});
		}
		
		if ($('#slider').length)
        {
			// Tab Sliders
			var $panels = $('#slider .scrollContainer > div');
			var $container = $('#slider .scrollContainer');
			
			var horizontal = true;
			
			if (horizontal) {
				$panels.css({
					'float' : 'left',
					'position' : 'relative' // IE fix to ensure overflow is hidden
				});
				
				$container.css('width', $panels[0].offsetWidth * $panels.length);
			}
			
			var $scroll = $('#slider .scroll').css('overflow', 'hidden');
			
			function selectNav() {
				$(this)
				.parents('ul:first')
					.find('a')
						.removeClass('selected')
					.end()
				.end()
				.addClass('selected');
			}
			
			$('#slider .navigation').find('a').click(selectNav);
			
			function trigger(data) {
				var el = $('#slider .navigation').find('a[href$="' + data.id + '"]').get(0);
				selectNav.call(el);
			}
			
			if (window.location.hash) {
				trigger({ id : window.location.hash.substr(1) });
			} else {
				$('ul.navigation a:first').click();
			}
			
			var offset = parseInt((horizontal ? 
				$container.css('paddingTop') : 
				$container.css('paddingLeft')) 
				|| 0) * -1;
				
				
			var scrollOptions = {
				target: $scroll, // the element that has the overflow
		
				items: $panels,
		
				navigation: '.navigation a',
		
				prev: 'img.left', 
				next: 'img.right',
		
				axis: 'xy',
		
				onAfter: trigger, // our final callback
		
				offset: offset,
		
				duration: 500,
		
				easing: 'swing'
			};
		
			// apply 
			$('#slider').serialScroll(scrollOptions);
		
			$.localScroll(scrollOptions);
		
			scrollOptions.duration = 1;
			$.localScroll.hash(scrollOptions);
		}
		
		//Hide Delivery address
		$("#ship-address").css("display","none");
		$("#ship-payment").css("display","none");
		
		$("#shipping-address").click(function()
		{
			if ($("#shipping-address").is(":checked"))
			{
				$("#ship-address").hide("fast");
				$("#ship-payment").hide("fast");
				$("#payment").show("fast");
			}
			else
			{     
				$("#ship-address").show("fast");
				$("#ship-payment").show("fast");
				$("#payment").hide("fast");
			}       
		});
		
		//IE6 Hover
		$('#bag-items tr').hover(function() 
		{
			$(this).addClass('table-hover');
		}, 
		function() 
		{
			$(this).removeClass('table-hover');
		});
		
		//Fade In
		/*if (!Modernizr.csstransforms3d) 
        {
			$('.browse-item').hover(function()
			{
				$('.front-image').fadeTo('100', 0.5, function() {});
			});
			
			$('.category-items').mouseleave(function()
			{
				$('.front-image').fadeTo('1', 1, function() {});
			});	
		}*/
		
		//Google Map
		if ($('#map').length)
        {
			var myLatlng = new google.maps.LatLng(55.971349,-3.175821);
			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:"Cameron Taylor"
			});
		}
		
	});
	
})(jQuery);
