$(document).ready(function () {
  //$("body").gradient({from: '400463', to: '300349', length:  (parseInt($("body").height())-200), position: 'bottom'});
  $("#SearchTerm").click(function() {
    if($(this).val()=="Search for...")$(this).val("");
  }); 
  $("input").focus(function(){$(this).css("background", "#535353")});
  $("input").blur(function(){$(this).css("background", "#535353")});
    $("a[rel='external']").click( function() {
      h = ($(this).attr('href').indexOf("AddToCart") > 0) ? 200 : 600;
      w = ($(this).attr('href').indexOf("AddToCart") > 0) ? 300 : 800;
      s = ($(this).attr('href').indexOf("AddToCart") > 0) ? "no" : "yes";
      r = ($(this).attr('href').indexOf("AddToCart") > 0) ? "no" : "yes";
      window.open( $(this).attr('href'),'MyWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + s + ',resizable=' + r + ',width=' + w + ',height=' + h );
      return false;
  });
  //PimpMyVinyl page - add classes to year boxes to space them out
  $("td.numericTextBox select").each(function() {
    if($(this).attr("id").indexOf("Year")>-1) {
      $(this).addClass("year");
    }
  })





//Tim

$('.drop_item_cont').each(function(){
					var numberOfChildren = $(this).children('.child').size();
					if (numberOfChildren == 1){
						$(this).children('.child').hide();
					}
				})

$.fn.infiniteCarousel = function () {

    function repeat(str, num) {
        return new Array( num + 1 ).join( str );
    }
  
    return this.each(function () {
        var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),
            
            singleWidth = $single.outerWidth(), 
            visible = Math.ceil($wrapper.innerWidth() / singleWidth), // note: doesn't include padding or border
            currentPage = 1,
            pages = Math.ceil($items.length / visible);            


        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }

        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect
        
        // 3. Set the left position to the first 'real' item
        $wrapper.scrollLeft(singleWidth * visible);
        
        // 4. paging function
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;
            
            $wrapper.filter(':not(:animated)').animate({
                scrollLeft : '+=' + left
            }, 500, function () {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    // reset back to start position
                    page = 1;
                } 

                currentPage = page;
            });                
            
            return false;
        }
        
        $wrapper.after('<a class="arrow back">&nbsp;</a><a class="arrow forward">&nbsp;</a>');
        
        // 5. Bind to the forward and back buttons
        $('a.back', this).click(function () {
            return gotoPage(currentPage - 1);                
        });
        
        $('a.forward', this).click(function () {
            return gotoPage(currentPage + 1);
        });
        
        // create a public interface to move to a specific page
        $(this).bind('goto', function (event, page) {
            gotoPage(page);
        });
    });  
};
$('.infiniteCarousel').infiniteCarousel();


//Drop Down Columns

var numberOfDrops = $('#header .drop_new a').size();
var numberOfCols = 4;
var numberPerCol = numberOfDrops/numberOfCols;

var count = 0;

$('#header .drop_new a').each(function(){
	
});

$('#top-nav #new_drop').appendTo('#top-nav #main-nav li:nth-child(3)');

$('#top-nav .under_fiver').appendTo('#top-nav #main-nav li:nth-child(4)');

$('#top-nav .drop_new').appendTo('#top-nav #main-nav li:nth-child(2)');



$('#top-nav #main-nav li:nth-child(3)').hover(function(){

$('#top-nav #main-nav li:nth-child(3) #new_drop').fadeIn('fast');

},function(){

$('#top-nav #main-nav li:nth-child(3) #new_drop').fadeOut('fast');

});

$('#top-nav #main-nav li:nth-child(4)').hover(function(){

$('#top-nav #main-nav li:nth-child(4) #new_drop').fadeIn('fast');

},function(){

$('#top-nav #main-nav li:nth-child(4) #new_drop').fadeOut('fast');

})

$('#top-nav #main-nav li:nth-child(2)').hover(function(){

$('#top-nav #main-nav li:nth-child(2) #new_drop').fadeIn('fast');

},function(){

$('#top-nav #main-nav li:nth-child(2) #new_drop').fadeOut('fast');

});



$('.test_more').hide();
$('.test_see_less').hide();

$('.test_see_more').click(function(){
	$(this).parent('div').children('.test_more').slideDown('fast');
	$(this).parent('div').children('.test_see_less').show();
	$(this).hide();
	return false;
});

$('.test_see_less').click(function(){
	$(this).parent('div').children('.test_more').slideUp('fast');
	$(this).parent('div').children('.test_see_more').show();
	$(this).hide();
	return false;
});

$('.row').hover(function(){
	$(this).css('backgroundColor','#eee');
},function(){
	$(this).css('backgroundColor','#fff');

});

$('.row_top').click(function(){
	var dad = $(this).parent();
	var brother = $(dad).children('.row_bottom');
	$(brother).slideDown('fast');
});

$('.closeRow').click(function(){
	$(this).parent().parent().slideUp('fast');
	});

});

;
       
function loadHeaderStyles() {
 //$("#header").liquidCanvas("[shadow{width:2; color:'#666'; shiftX:-1; shift:2 } fill{color:#400463}] => ecken{tl:20; bl:0; br:0; tr:20}");
  //$("#user-bar ul").liquidCanvas("[fill{color:#111}] => ecken{tl:0; bl:10; br:10; tr:0}");
  
  $("#top-nav").gradient({ from: 'ffffff', to: 'c0c0c0' , length: 75, position: 'top'}); 
 
}


















