$(document).ready(function() {

// $('#page > h1').prependTo('#content .main-content').css('background','none');
// $('body#checkout #page > h1').prependTo('#content').css('background','none');
// $('body#account #page > h1').prependTo('#content').css('background','none');

	// SLIDESHOWS
	$('a[rel*=fancybox]').fancybox(); 
	$('a.fancy').fancybox(); 
	$('#home-banner').cycle({
		timeout: 5000
	});
	 $('#gallery').cycle({
        fx:     'fade',
        speed:  'fast',
        timeout: 0,
        pager:  '#thumbs',
        pagerAnchorBuilder: function(idx, slide) {
            return '#thumbs li:eq(' + (idx) + ') a';
        }
    });

    // DROPDOWN
	$('#nav li').hover(
		function () {
			$('a:first', this).addClass('active-hover');
			$('ul', this).stop(true,true).slideDown(200);
		}, 
		function () {
			$('a:first', this).removeClass('active-hover');
			$('ul', this).stop(true,true).slideUp(100);			
		}
	);

	// Sidebar
	$('body#product div.sidebar,body#category div.sidebar').load( "/library/php/ajax.sidebar.php?productid=" + $('#productid').val() + "&catid=" + $('#catid').val() );
	$('body.faq hr:not(:first)').before('<p><a href="#">back to top</a></p>');
	
	// Category page items alignment
	$('#category #items-wrapper .item:nth-child(3n)').after('<br class="clear" />');
	$('#category-landing #items-wrapper .item:nth-child(4n)').after('<br class="clear" />');
	
	// EQUAL COL HEIGHT
	var max_height = 0;
	$("div.container").each(function(){
	if ($(this).height() > max_height) { max_height = $(this).height(); }
	});
	$("div.container").height(max_height);

	// CLICKABLE CONTAINER
	$('.item').css('cursor','pointer');
	$('.item').click(function() {
        var href = $(this).find("a").attr("href");
        if(href) {
            window.location = href;
        }
    });
	
	// STRIPED TABLES
	$("table.striped tr:odd").addClass("alt-row");
	
	// STYLE LINKS
	$("a[href$='.pdf']").addClass("pdf");
	$("a[href$='.zip'], a[href$='.rar']").addClass("zip"); 
	$("a[href^='mailto:']").addClass("email");
	$('a').filter(function() {
	    return this.hostname && this.hostname !== location.hostname;
	  }).addClass("external").attr("target", "_blank");


  });
