$('html').addClass('jsActive');
// SUPERFISH NAVIGATION

jQuery(function() {
    jQuery('.primary_nav ul').superfish({
        speed: 'fast',          // faster animation speed 
        autoArrows: false,      // disable generation of arrow mark-up 
        dropShadows: false      // disable drop shadows 
    });
});

// SUPERSIZED HOME PAGE
$(function() {
    $.fn.supersized.options = {
        transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
        startwidth: 640,
        startheight: 480,
        vertical_center: 1,
        slideshow: 1,
        navigation: 0,
        pause_hover: 0,
        slide_counter: 0,
        slide_captions: 0,
        slide_interval: 5000
    };
    $('.templateHome #ctl00_mainPageContent_mainContent_contentDiv').supersized();
});

$(document).ready(function() {
    if ($('.ps_wrapper').length <= 0) {
        //stop the flash of images in the slideshow in IE by hiding images with a 'js' class
        $('html').addClass('frontEnd');
    };

    // EXPANDING MOSAIC GALLERIES(WITH HOVERINTENT DELAY!) - NEW DESIGNS, FAVOURITES BY CATEGORY ImageGalleryLarge.aspx ImageGallerySmall.aspx
    $('.frontEnd ul.galleryMosaic li, .frontEnd ul.galleryMosaic li:hover').css({ "width": "193px", "height": "198px" });
    $('.frontEnd ul.galleryMosaic li .description, .frontEnd ul.galleryMosaic li:hover .description').css({ "-moz-opacity:": "0", "opacity": "0", "filter": "alpha(opacity=0)" });
    $(".frontEnd ul.galleryMosaic li").hoverIntent({
        over: makeTall,
        //timeout: 1,
        out: makeShort
    });
    function makeTall() {
        $(this).animate({ "height": 398, "width": 584 }, 400);
        $(this).children('div.description').animate({ "opacity": "0.8" }, "slow");
        $(this).removeClass('animationComplete').addClass('animating');
    }
    function makeShort() {
        $(this).animate({ "height": 198, "width": 193 }, 400);
        $(this).children('div.description').animate({ "opacity": "0" }, "slow");
        $(this).removeClass('animating').addClass('animationComplete');
    }

});   // close document.ready

$(window).load(function() {

    // THUMB FADE GALLERY (MANUFACTURERS PAGE)
    $('.thumbGallery.fade a.SmartListThumbnailLink img, .thumbGallery.fade a.SmartListThumbnailLink:link img, .thumbGallery.fade a.SmartListThumbnailLink:visited img, .thumbGallery.fade a.SmartListThumbnailLink:hover img, .thumbGallery.fade a.SmartListThumbnailLink:active img').css({ "-moz-opacity:": "1", "opacity": "1", "filter": "alpha(opacity=100)" });
    $(".thumbGallery.fade a.SmartListThumbnailLink img").hover(
		function() {
		    $(this).stop().animate({ "opacity": "0" }, "slow");
		},
	    function() {
	        $(this).stop().animate({ "opacity": "1" }, "slow");
	    });

    // FAVOURITES BY CATEGORY GALLERY Favourites.aspx #slideshowFavouriteCategories	
    $('#slideshowFavouriteCategories a.SmartListPageLink, #slideshowFavouriteCategories a.SmartListPageLink:link, #slideshowFavouriteCategories a.SmartListPageLink:visited, #slideshowFavouriteCategories a.SmartListPageLink:hover, #slideshowFavouriteCategories a.SmartListPageLink:active').css({ "-moz-opacity:": "0", "opacity": "0", "filter": "alpha(opacity=0)" });
    $("#slideshowFavouriteCategories li").hover(
		function() {
		    $(this).children("a.SmartListPageLink").stop().animate({ "opacity": "1" }, "slow");
		},
		function() {
		    $(this).children("a.SmartListPageLink").stop().animate({ "opacity": "0" }, "slow");
		});

	// FAVOURITES BY CATEGORY GALLERY SmartList3ColTemplate.aspx #smartList3ColTemplate
		$('#smartList3ColTemplate a.SmartListThumbnailLink, #smartList3ColTemplate a.SmartListThumbnailLink:link, #smartList3ColTemplate a.SmartListThumbnailLink:visited, #smartList3ColTemplate a.SmartListThumbnailLink:hover, #smartList3ColTemplate a.SmartListThumbnailLink:active').css({ "-moz-opacity:": "0.7", "opacity": "0.7", "filter": "alpha(opacity=70)" });
		$('#smartList3ColTemplate a.SmartListPageLink, #smartList3ColTemplate a.SmartListPageLink:link, #smartList3ColTemplate a.SmartListPageLink:visited, #smartList3ColTemplate a.SmartListPageLink:hover, #smartList3ColTemplate a.SmartListPageLink:active').css({ "-moz-opacity:": "0.7", "opacity": "0.7", "filter": "alpha(opacity=70)" });
		$("#smartList3ColTemplate a.SmartListThumbnailLink").hover(
		function() {
		    $(this).parent().siblings(".SmartListPageLink").stop().animate({ "opacity": "1" }, "slow");
		    $(this).stop().animate({ "opacity": "1" }, "slow");
		},
	    function() {
		$(this).parent().siblings(".SmartListPageLink").stop().animate({ "opacity": "0.7" }, "slow");
		$(this).stop().animate({ "opacity": "0.7" }, "slow");
	    });	
		

    // JCYCLE SLIDESHOWS  
    if ($('.heroGallery').length) { // First check the page contains the '.heroGallery' class before trying to run any of this code        
        //$('html').removeClass('flash'); //stop the flash of images in the slideshow in IE by hiding images with a 'js' class
        $('div#slideshow5Items').before('<ul id="nav">');
        $('div#slideshowImages').before('<ul id="nav">');

        // FAVOURITES
        //==============================
        $('.frontEnd #galleryImagesPlusDescription #slideshow5Items ul.slideshowItems').cycle({
            fx: 'fade',
            speed: '700',

            timeout: 5000,
            before: function(curr, next, opts) {
                // This function runs before each slide fades up so we remove the
                // caption div then re-insert it if the image has alt text.
                $('#caption').remove();
                if ($(next).find('img').attr('alt')) {
                    $('.frontEnd #galleryImagesPlusDescription ul.slideshowItems').after('<div id="caption">');
                }
                var alt = $(next).find('img').attr('alt');
                $('#caption').html(alt);
            },
            pager: '#nav'

        });
        // PROJECTS
        //==============================
        $('.frontEnd #galleryImagesSharedDescription #slideshowImages div#ctl00_mainPageContent_featuredCaseStudyImages_contentDiv').cycle({
            fx: 'fade',
            speed: '700',
            timeout: 5000,
            before: function(curr, next, opts) {
                // This function runs before each slide fades up so we remove the
                // caption div then re-insert it if the image has alt text.
                $('#caption').remove();
                if ($(this).attr('alt')) {
                    $('.frontEnd #galleryImagesSharedDescription div#ctl00_mainPageContent_featuredCaseStudyImages_contentDiv').after('<div id="caption">');
                }
                var title = $(this).attr('alt');
                $('#caption').html(title);
            },
            pager: '#nav'

        });

        // PROJECTS CHILD + MANUFACTURERS CHILD
        //==============================
        $('.frontEnd #galleryImages #slideshowImages div#ctl00_mainPageContent_heroImages_viewDiv div').cycle({
            fx: 'fade',
            speed: '700',
            timeout: 5000,
            before: function(curr, next, opts) {

                $('#caption').remove();

                if ($(this).attr('alt')) {
                    //$('.slideshow div#ctl00_mainPageContent_heroImages_viewDiv div').after('<div id="caption">');
                    $('.slideshow div#ctl00_mainPageContent_heroImages_viewDiv div').after('<div id="caption">');
                }

                var title = $(this).attr('alt');
                $('#caption').html(title);
            },
            pager: '#nav'
        });


        // INDIVIDUAL PRODUCT PAGE
        //==============================
        $('.frontEnd #galleryWithThumbs #slideshowWithThumbs').after('<div class="slideshowThumbsContainer"><div id="thumbsLeft">L</div><div id="thumbsRight">R</div><div class="slideshowThumbsWrapper"><ul class="slideshowThumbs" id="slideshowThumbs">');
        $('.frontEnd #galleryWithThumbs #slideshowWithThumbs ul').cycle({
            fx: 'fade',
            timeout: 0,
            delay: -2000,
            cleartypeNoBg: true, /* DO NOT REMOVE - PRODUCES BIZARRE BEHAVIOUR IN IE OTHERWISE */
            pager: '#slideshowThumbs',
            pagerAnchorBuilder: function(idx, slide) {
                return '<li><a href="#"><img src="' + $(slide).children('img').attr('src') + '" width="144" height="98"/></a></li>';
            }
        });

        // thumb nav
		var slideshowThumbsCount = $('#slideshowThumbs li').length;	
		var slideshowListItemWidth = $('#slideshowThumbs li').outerWidth();
		var slideshowScrollerWidth = slideshowThumbsCount * slideshowListItemWidth;
		var thumbClickAdvance = slideshowListItemWidth;
		$('#slideshowThumbs').css('width', slideshowScrollerWidth);

		$('#thumbsRight').click(function() {
			var slideshowScrollerRight = parseInt($('#slideshowThumbs').css('left')) + slideshowScrollerWidth;
			var slideshowContainerWidth = $('.slideshowThumbsContainer').width() + 20;	
			
			if (slideshowContainerWidth <= slideshowScrollerRight) {
				
				if ($("#slideshowThumbs:animated").length == 0) {
					$('#slideshowThumbs').animate({ left: '-=' + thumbClickAdvance }, 500);
				}	
			}
		});
		
		$('#thumbsLeft').click(function() {
			if ($('#slideshowThumbs').css('left') < '0px') {
				if ($("#slideshowThumbs:animated").length == 0) {
					$('#slideshowThumbs').animate({ left: '+=' + thumbClickAdvance }, 500);
				}
			}
		});
    };

    // Open links in other manufacturers page in a new window
    $('#otherManufacturersInfo ul li a').attr('target', '_blank');


}); //close window.load
	  




