$(document).ready(function () {
	
	// #big-menu hover stops slideshow
	$('#big-menu').hover(
		function() { $('#slideshow').cycle('pause'); },
		function() { $('#slideshow').cycle('resume'); }
	);
	
	// #home-center hover stops specials slideshow
	$('#home-center').hover(
		function() { $('#specials').cycle('pause'); },
		function() { $('#specials').cycle('resume'); }
	);
	
	// #nav click
	$('#nav li a').click(function() {
		resetAll(); // reset active state
		$('#slideshow').cycle('pause'); // stop slideshow, continues at hover out
		$(this).children('img').attr('src', $(this).children('input.c').val()); // replace img
	});
	
	// gallery thumbs scroll
	$('#g').jcarousel({ scroll: 3 });
	
	// form	
	$('.jqtransform').jqTransform({imgPath:'/js/jqtransformplugin/img/'});
	
	// Gallery
    $(function() {
        $('a.lightbox').lightBox({
            txtImage: '',
            txtOf: '/',
            imageLoading: '/img/lightbox/loading.gif',
            imageBtnClose: '/img/lightbox/closelabel.gif',
            imageBtnPrev: '/img/lightbox/prevlabel.png',
            imageBtnNext: '/img/lightbox/nextlabel.png'
        });
    });
    $(".popup").prettyPhoto({show_title: false});
	
    // product gallery
    $('.click').click(function() {
		var split = $(this).attr('class').split(" ");
		var id = split[1];
		$('.player').hide();
		$('#elem-' + id).show();
		return false;
	});
});

// Front banner slideshow
$(function() {
    $('#slideshow').cycle({
        fx:		'fade',
        speed:  1000,
        timeout: 1000,
        pager:  '#nav',
        pause: 1,
        activePagerClass: 'active',
        before: setActive,
        pagerAnchorBuilder: function(idx, slide) { return '#nav li:eq(' + (idx) + ') a'; }
    });
});  

// Specials slideshow
$(function() {
    $('#specials').cycle({
        fx:		'fade',
        speed:  1000,
        timeout: 1000,
        pager:  '#spec-nav',
        pause: 1,
        activePagerClass: 'active',
        pagerAnchorBuilder: function(idx, slide) { return '#spec-nav li:eq(' + (idx) + ') a'; }
    });
}); 

function setActive(currSlideElement, nextSlideElement, options, forwardFlag) {
	var prev_li = 'li-' + currSlideElement.id.replace('bm-',''); 
	var next_li = 'li-' + nextSlideElement.id.replace('bm-','');
	$('#'+prev_li+' a img').attr('src', $('#'+prev_li+' a input.bw').val());
	$('#'+next_li+' a img').attr('src', $('#'+next_li+' a input.c').val());
}

function resetAll() { $('#nav li a').each(function() { $(this).children('img').attr('src', $(this).children('input.bw').val()); }); }
