

$(document).ready(function () {
    // ColorBox
    $('.colorbox a, a.colorbox').colorbox({
        current: "{current} of {total}",
        initialHeight: '150px',
        initialWidth: '150px',
        maxHeight: '95%',
        maxWidth: '95%',
        opacity: 0.25,
        rel: 'colorbox',
        speed: 250,
        transition: "elastic"
    });
    $('a.colorbox2').colorbox({
        current: "{current} of {total}",
        initialHeight: '150px',
        initialWidth: '150px',
        maxHeight: '95%',
        maxWidth: '95%',
        opacity: 0.25,
        rel: 'colorbox2',
        speed: 250,
        transition: "elastic"
    });
    // Panel
    $('div.main_area div.panel ul.navigation ul').not('li.selected ul').hide();
    $('div.main_area div.panel ul.navigation a').not('ul ul a').click(function () {
        $('div.main_area div.panel ul.navigation li').removeClass('selected');
        $('div.main_area div.panel ul.navigation ul').hide();
        $(this).next('ul').show();
        $(this).parents('li').addClass('selected');
        return false;
    });
    // Product page tabs
    $('div.main_area_product_page div.details ul.tab_navigation').show();
    $('div.main_area_product_page div.details ul.tab_content h3.tab_title').hide();
    $('div.main_area_product_page div.details ul.tab_content li.tab_2').hide();
    $('div.main_area_product_page div.details ul.tab_navigation li.tab_2 a').click(function () {
        $('div.main_area_product_page div.details ul.tab_content li.tab_1').hide();
        $('div.main_area_product_page div.details ul.tab_content li.tab_2').show();
        $('div.main_area_product_page div.details ul.tab_navigation li.tab_1').removeClass('selected');
        $('div.main_area_product_page div.details ul.tab_navigation li.tab_2').addClass('selected');
        return false;
    });
    $('div.main_area_product_page div.details ul.tab_navigation li.tab_1 a').click(function () {
        $('div.main_area_product_page div.details ul.tab_content li.tab_2').hide();
        $('div.main_area_product_page div.details ul.tab_content li.tab_1').show();
        $('div.main_area_product_page div.details ul.tab_navigation li.tab_2').removeClass('selected');
        $('div.main_area_product_page div.details ul.tab_navigation li.tab_1').addClass('selected');
        return false;
    });
    // Social plugins
    $('div.facebook_like').html('<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.megavaux.co.uk%2F&amp;layout=standard&amp;show_faces=false&amp;width=350&amp;action=like&amp;font=arial&amp;colorscheme=light&amp;height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:350px; height:35px;" allowTransparency="true"></iframe>');
    $('div.addthis').html('<div class="addthis_toolbox addthis_default_style"><a href="http://www.addthis.com/bookmark.php?v=250&amp;username=xa-4d2708c50d325422" class="addthis_button_compact">Share</a></div><script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4d2708c50d325422"></script>');
    $('div.google_map').html('<iframe width="350" height="250" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=NG10+5AP&amp;sll=53.800651,-4.064941&amp;sspn=13.940309,35.727539&amp;ie=UTF8&amp;hq=&amp;hnear=Nottingham+NG10+5AP,+United+Kingdom&amp;ll=52.923135,-1.283855&amp;spn=0.012781,0.029955&amp;z=14&amp;output=embed"></iframe>');
    // Remove focus outline on click
    $('a, input').mousedown(function () {
        this.blur();
        this.hideFocus = true;
        this.style.outline = 'none';
    });
    // Rollovers
    $('img.rollover, input.rollover, .rollovers img, .rollovers input').hover(function () {
        $(this).attr('src', $(this).attr('src').replace(/\_off\./gi, '_on\.'));
    },
	function () {
	    $(this).attr('src', $(this).attr('src').replace(/\_on\./gi, '_off\.'));
	});
    $('img.rollover, input.rollover, .rollovers img, .rollovers input').each(function () {
        var rollover_image = $(this).attr('src').replace(/\_off\./gi, '_on\.');
        $('<img>').attr('src', rollover_image);
    });
    // Special actions
    $('div.main_area_car_list div.content ul.models').height($('div.main_area_car_list div.content ul.models').height() - 1);
    // Special classes
    $('div.header ul.navigation li:first').addClass('first');
    $('div.footer ul.navigation li:first').addClass('first');
    $('ul.categories ul.sub_categories li:last').addClass('last');
    $('ul.tab_content ul').each(function () {
        $(this).children('li:last').addClass('last');
    });
    //Pagination
    $('.pagination .previous').each(function () {
        if ($(this).html() === "") {
            $(this).remove();
        }
    });
    $('.pagination .next').each(function () {
        if ($(this).html() === "") {
            $(this).remove();
        }
    });
    // Scroll images
    $(".small_images li").hover(function () {
        //$('.large_images').stop().animate({ "left": "-" + ($(this).index() * $(".large_images img").eq($(this).index()).width()) + "px" }, 300);
        $('.large_images').stop().animate({ "left": "-" + ($(this).index() * 364) + "px" }, 300);
    });
});
