﻿$(document).ready(function() {
    // Open external links in new window
    // ************************************************
    $("a[href^='http://']")
    .not("a[href^='http://www.blastation.']")
    .not("a[href^='http://blastation.']")
    .attr({ target: "_blank" });

    // Toggle read more on product
    // ************************************************
    $("#moreInfo").hide();
    $("#moreInfoLink").click(function() {
        $("#foldoutIndicator").html() == '+' ? $("#foldoutIndicator").html('-') : $("#foldoutIndicator").html('+');
        $("#moreInfo").slideToggle(200);
    });

    // SubMenu classes
    // ************************************************    
    $("div.subMenu ul li ul").each(function() {
        $(this).parent().addClass("open");
    });

    // Hide last li in product menu if it contains a value in the href
    // ************************************************
    $('div#leftColumn .subMenu > ul li > a[href*="-0298"]').parent("li").hide();
    $('div#leftColumn .subMenu > ul li > a[href*="-0357"]').parent("li").hide();
    $('div#leftColumn').show();

    // Show Hide product tabs
    // ************************************************
    ToogleTab("div#product-tabs", "#fragment-3");
    ToogleTab("div#product-tabs", "#fragment-4");

    // Show Hide image tabs
    // ************************************************
    ToogleTab("div#product-images-tab", "#imageTab1");
    ToogleTab("div#product-images-tab", "#imageTab2");

    // Show Hide related products tabs
    // ************************************************
    if ($("#product-tabs div.six > a").size() > 0) {
        $("#product-tabs div.six").removeClass("hidden");
    }

    // Language select
    // ************************************************    
    $("div#selectedLanguage a").click(function() {
        $("#languageSelector").toggle();
    });

    // Award PopUp
    // ************************************************

    // Settings and which div that shoud be treated as modals
//    $("#awardPopups div.jqmWindow").jqm({ overlay: 0, trigger: false });

//    // Setup the show triggers
//    $("#awardPopups > a").click(function() {
//        $("#awardPopups > div.jqmWindow").jqmHide();
//        $(this).next().jqmShow();
//    });

//    // Setup the close triggers
//    $("#awardPopups a.close").click(function() {
//        $("#awardPopups > div.jqmWindow").jqmHide();
    //    });

    $(".awardBox").fancybox();

    //Setup emailaddressen from name
    $("a.emailAddress").each(function() {
        var emailDomain = "@blastation.se";
        var email = $(this).html() + emailDomain;
        $(this).attr("href", "mailto:" + email);
        $(this).html(email);
    });

});

// Show/hide a product tab if it got content
function ToogleTab(tabID, elemID) {
    if ($(tabID +" > " + elemID +" > ul").children().size() > 0) {
        $(tabID +" > ul li a[href=" + elemID + "]").parent("li").removeClass("hidden");
    }
}

