$(document).ready(function () {
    $('#main-menu li:not(:has(a>br))').addClass('single');
    $('#main-menu li:last,#service-menu li:last,#top-menu li:last, #products article:nth-child(3n),.pagination li:last, .companies li:nth-child(5n)').addClass('last');
    $('#breadcrumbs br').remove();
    $('#main-menu li').hover(function () {
        $(this).addClass('hover');
    }, function () {
        var elem = $(this);
        //setTimeout(function(){
        $(elem).removeClass('hover');
        //}, 200);
    });

    $('#main-menu li ul').each(function () {
        $(this).find('li:last').addClass('last-sub');
    });

    $('<div id="band" />').insertBefore('#content');

    if ($('.product-detail img').length == 0) {
        $('.product-detail').addClass('no-img');
    }

    $('.products li').each(function () {
        if ($(this).find('img').length == 0) {
            $(this).addClass('no-img');
        }
    });


    // ---- Thank you popup  ----------------------------------------------------------------------------------------------------------

    $(".add").click(function () {
        $('	<div class="thank-you" style="display:none"><div class="thank-you-aux"><h3>Thank you</h3><p class="message">Your item has been added to your quote list</p><p class="nav"><a href="/Your-Quote-Basket" id="view-quote">View Quote List</a></p></div></div>').insertAfter(this);
        $(this).colorbox({ width: "340px", inline: true, href: ".thank-you-aux", opacity: 0.6, onClosed: function () {
            $('.thank-you').remove();
        }
        });
    });


    // ---- External Links  ----------------------------------------------------------------------------------------------------------

    $("#footer a")
		.addClass("external")
		.attr("target", "_blank")
		.attr("title", "Opens new window");


    // ---- Slider  ----------------------------------------------------------------------------------------------------------

    /*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
    ***/

    var currentID = $('#slideshow article.active').attr('id');
    $('#slideshow-nav a[href$=' + currentID + ']').addClass('active');

    slideSwitch = function () {
        var $active = $('#slideshow article.active');
        if ($active.length == 0) $active = $('#slideshow article:last');
        var $next = $active.next().length ? $active.next() : $('#slideshow article:first');
        $active.addClass('last-active');
        $next.css({ opacity: 0.0 })
				.addClass('active')
				.animate({ opacity: 1.0 }, 1000, function () {
				    $active.removeClass('active last-active');
				    //$active.css({opacity: 0.0});
				});
        $('#slideshow-nav a').removeClass('active');
        var currentID = $next.attr('id');
        $('#slideshow-nav a[href$=' + currentID + ']').addClass('active');
    }

    $('#slideshow-nav a').click(function () {
        clearInterval(sliderIntervalID);
        $('#slideshow-nav a').removeClass('active');
        $(this).addClass('active');
        var clickedSlide = $(this).attr('href').replace("#", "");
        var $active = $('#slideshow article.active');
        $('#slideshow article.active').removeClass('active').addClass('last-active');
        $('#slideshow article').each(function () {
            if ($(this).attr('id') == clickedSlide) {
                $(this).css({ opacity: 0.0 }).addClass('active').animate({ opacity: 1.0 }, 1000, function () {
                    $active.removeClass('active last-active');
                    //$active.css({opacity: 0.0});
                });
            }
        });

        return false;
    });

    var sliderIntervalID = setInterval("slideSwitch()", 6000);

});
