$(function($) {
    /*
        Tabs
    */
    $('ul.tabNav a').click(function(event) {
        var curChildIndex = $(this).parent().prevAll().length + 1;
        $(this).parent().parent().children('.current').removeClass('current');
        $(this).parent().addClass('current');
        $(this).parent().parent().next('.tabContainer').children('.current').show('fast', 
        function() {
			var div = $(this).parent().children('div:nth-child(' + curChildIndex + ')');
			
			if (div.attr('id') == 'tab-faq') {
				$('#tab-details, #tab-specifications, #tab-pricing').addClass('no-print');
			}
			else
			{
				$('#tab-details, #tab-specifications, #tab-pricing').removeClass('no-print');
			}
			
            $(this).parent().children('div:nth-child(' + curChildIndex + ')').hide('fast', 
            function() {
                $(this).addClass('current');

            });
            $(this).removeClass('current');
        });
        return false;
    });
    
    /*
        Tooltips
    */
	$('.products>li>a>span').wrap('<span></span>').each(function(i, el) {
		if ($(el).height() < 30) {
			$(el).css({
				'padding-top': '7px',
				'padding-bottom': '8px'
			})
		}
	});
    $('.products>li>a').append('<span class="mask"></span>');
    $('.products>li>a').tooltip({
        position: 'center right',
        relative: true,
        offset: [4,-14],
        predelay: 50,
        events: {
          def:     "mouseenter,mouseleave",    // default show/hide events for an element
          input:   "focus,blur",               // for all input elements
          widget:  "focus mouseenter,blur mouseleave",  // select, checkbox, radio, button
          tooltip: ""     // the tooltip element
        }
    });
    
    /*
        Our range
    */
    if ($('#our-range').length > 0) {
        var itemHovered = false,
            ddHovered = false,
            position = $('#our-range').position();
        
        $('#dropdown').css({
            top: position.top + 26,
            left: position.left + 17,
            display: 'block'
        }).hide();
        $('#our-range').hover(function(e) {
            itemHovered = true;
            showDD();
        },function(e) {
            itemHovered = false;
            setTimeout(hideDD, 200);
        });
        $('#dropdown').hover(function(e) {
            ddHovered = true;
        },function(e) {
            ddHovered = false;
            setTimeout(hideDD, 200);
        });
        function showDD() {
            $('#dropdown').show(300);
        };
        function hideDD() {
            if (!ddHovered && !itemHovered) {
                $('#dropdown').hide(300);
            }
        };
    }
	
    /*
        Galleries
    */
   
    if ($('#gallerific').length > 0) {
        var itemHovered = false,
            ddHovered = false,
            position = $('#gallerific').position();
        
        $('#dropdown-gallery').css({
            top: position.top + 26,
            left: position.left + 17,
            display: 'block'
        }).hide();
        $('#gallerific').hover(function(e) {
            itemHovered = true;
            showGD();
        },function(e) {
            itemHovered = false;
            setTimeout(hideGD, 200);
        });
        $('#dropdown-gallery').hover(function(e) {
            ddHovered = true;
        },function(e) {
            ddHovered = false;
            setTimeout(hideGD, 200);
        });
        function showGD() {
            $('#dropdown-gallery').show(300);
        };
        function hideGD() {
            if (!ddHovered && !itemHovered) {
                $('#dropdown-gallery').hide(300);
            }
        };
    } 
    
    /*
        Sections
    */
    var max_section_height = 0;
    $('.block-large > .section').each(function(i,el) {
        if (max_section_height < $(el).height()) {
            max_section_height = $(el).height();
        }
    });
    $('.block-large > .section').css('height', max_section_height);
});
/*
    Sliders
*/
jQuery(function($) {
    $('.slideshow').each(function(i,el) {
        
        if ($(el).find('img').length < 2) {
            return;
        }
        
        var offset = Math.floor(Math.random() * $(el).find('img').length);
        var capOpacity = 1;
        
        /*@cc_on
           /*@if (@_jscript_version >= 5)
                capOpacity = 0.85;
           @else @*/
                capOpacity = 1;
           /*@end
        @*/
        
        if ($(el).hasClass('block-large')) {
            $(el).nivoSlider({
                effect: 'slideInRight',
                controlNav: !$(el).hasClass('alt'),
                directionNav: $(el).hasClass('alt'),
                directionNavHide: false,
                captionOpacity: capOpacity,
                pauseTime: 4500 + i*100,
                startSlide: offset
            });
        } else {
            $(el).nivoSlider({
                effect: 'fade',
                manualAdvance: true,
                controlNav: false,
                directionNav: true,
                directionNavHide: false,
                captionOpacity: capOpacity,
                pauseTime: 3000 + i*500,
                startSlide: offset
            });
        }        
    });
});

