$(document).ready(function() {
    
  	//Placeholder text
	if (!Modernizr.input.placeholder)
	{
		$('[placeholder]').focus(function()
		{
			var input = $(this);
			if (input.val() == input.attr('placeholder'))
			{
			  input.val('');
			  input.removeClass('placeholder');
			}
		}).blur(function()
		{
			var input = $(this);
			if (input.val() == '' || input.val() == input.attr('placeholder'))
			{
				input.addClass('placeholder');
				input.val(input.attr('placeholder'));
			}
		}).blur();
		
		$('[placeholder]').parents('form').submit(function()
		  {
			  $(this).find('[placeholder]').each(function()
			  {
				  var input = $(this);
				  if (input.val() == input.attr('placeholder'))
				  {
					  input.val('');
				  }	
			  })
		});
	}
	
	if ($('#featured').length)
	{
		
		$('#featured').cycle({
			fx: 'scrollHorz',
			prev: '#prev',
			next: '#next',
			pager: '#featurednav',
			speed: 3500,
			easing: 'easeOutQuart',
            pause: 1
		});
	}
	
	if ($('.featured-brands').length)
	{	
		//Brand Scroller
		$(".featured-brands").cycle({
			fx: 'scrollHorz',
			speed: 6000,
			next: '.brands-forward',
			prev: '.brands-back',
			easing: 'easeInOutQuad',
            pause: 1
		});
	}
	
	//Basket Preview
	$('#basket-preview').hide();
	$('#mini-basket').hover(function(event) {
		event.preventDefault();
		$('#basket-preview').stop(true, true).show();
		$('#basket-preview').animate({
			top: "68px"
		});
		easing: 'easeOutQuart'
	},
	function() {
		$('#basket-preview').stop(true, true).fadeOut(250);
		$('#basket-preview').animate({
			top: "0"
		});
		easing: 'easeOutQuart'
	});
	
    
	//Menu Fade
    $('.submenu .top-brands li a').css('color','#2e2e2e');
    $('.submenu .brands-list').hover(function(event) {
      $('.submenu .top-brands li a').css('color','#a0a0a0');
    },
    function() {
      $('.submenu .top-brands li a').css('color','#2e2e2e');
    });
    
	$('.submenu').hide();
	$('.submenu-list').hide();
	$('#nav li').hover(function(event) {
		event.preventDefault();
		$(this).find('.submenu').stop(true, true).fadeIn(500);	
		$(this).find('.submenu-list').stop(true, true).fadeIn(500);		
	},
	function() {
		$(this).find('.submenu').stop(true, true).fadeOut(500);
		$(this).find('.submenu-list').stop(true, true).fadeOut(500);
	});
    
	//Filter
	$('#filter input[type=checkbox]').checkBox();
	
	$(".itemsmall-image").hover(
		function () {
		  $curimg = $(this).find('.firstimg').attr('src');
		  $otherimg = $(this).find('.firstimg').attr('rel');
          $(this).find('.firstimg').attr('rel',$curimg);
          $(this).find('.firstimg').attr('src',$otherimg);
          //$(this).find('.firstimg').hide();
		  //$(this).find('.hoverimg').show();
		},
		function () {
		  $curimg = $(this).find('.firstimg').attr('src');
		  $otherimg = $(this).find('.firstimg').attr('rel');
          $(this).find('.firstimg').attr('rel',$curimg);
          $(this).find('.firstimg').attr('src',$otherimg);
		  //$(this).find('.firstimg').show();
		  //$(this).find('.hoverimg').hide();
		}
	  );

    
	//Browse Popups
	$('.item-details').colorbox({
	    iframe: true,
		title: false,
		close: "close x",
		opacity: 0.8,
		width: "594px",
		height: "359px"
	});
	
	$('a.size').colorbox({
	    iframe: true,
		title: false,
		close: "close x",
		opacity: 0.8,
		width: "594px",
		height: "329px"
	});
	$('a.size-guide').colorbox({
	    iframe: true,
		title: false,
		close: "close x",
		opacity: 0.8,
		width: "594px",
		height: "329px"
	});
	
	//Position Fixed
	if ($('.fixed-sort').length)
	{
		var $comment = $('.fixed-sort'),
		top = $comment.offset().top - parseFloat($comment.css('marginTop').replace(/auto/, 0)),
		$window = $(window);
			 
		$window.scroll(function (event)
		{
			// what the y position of the scroll is
			var y = $window.scrollTop();
			
			// whether that's below the form
			if (y >= top) {
			// if so, ad the fixed class
			$comment.addClass('fixed');
			} else {
			// otherwise remove it
			$comment.removeClass('fixed');
			}
		});
	}
	
	//Item Tabs
	$("#delivery").siblings(".panel").hide();
          
	$(".navigation a").click(function (event)
	{ 
		event.preventDefault(); 
  		$(".active").removeClass("active");  
  		$(this).addClass("active");  
  		$(".panel").fadeOut(400);  
		var content_show = $(this).attr("href");  
		$(content_show).fadeIn(400);   
	});  
	
	
	//Google Map
	if ($('#map').length){
	   var myLatlng = new google.maps.LatLng(56.462072,-2.96789);
	   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:"Arkive and Ozzys"
	   });
   } 
   
   // Search stuff
   if ($('#searchinput').length > 0) {
        $('#searchinput').bind('keyup', function () {
           if ($(this).val().length>2) {
                var data = $('#searchbox').serialize();
                $.ajax({
                    type: 'post',
                    url: '/get/search.php',
                    data: data,
                    success: function (html) {
                        $('#appendsearchresults').fadeIn(200);
                        $('#appendsearchresults').css('border','1px solid #ccc');
						$('#appendsearchresults').css('width','350px');
                        $('#appendsearchresults').html(html);
                    }
                });
            } else {
                $('#appendsearchresults').css('border','');
                $('#appendsearchresults').html('');
            }
       });
   }
   
   $('#searchbox').focusout(function() {
      $('#appendsearchresults').fadeOut(200);
   });

  
});
