﻿
require("Scripts/jquery.easing.1.3.js");
require("Scripts/jquery.ui.core.min.js");
require("Scripts/jquery.ui.widget.min.js");
require("Scripts/jquery.ui.position.min.js");
require("Scripts/jquery.ui.tabs.min.js");
require("Scripts/jquery.formatCurrency-1.4.0.min.js");
require("Scripts/jquery.coda-slider-2.0.js");
require("Scripts/jquery.ui.accordion.js");
require("Scripts/jquery.colorbox-min.js");
require("Scripts/cloud-zoom.1.0.2.min.js");




$(document).ready(function () {


    //Remove outline from links
    $("a").click(function () {
        $(this).blur();
    });



    $("#tabs").tabs();


    // MENU

    $('.navigation_main > li').bind('mouseover', openSubMenu);
    $('#navigation_wrapper').bind('mouseout', closeSubMenu);


    // Sub Menu - Third Level

    Setup_ThirdLevel();


    //$('#product_thumbs > img').bind('mouseover', ThumbMouseOver);


});

$(window).load(function () {

    // PRODUCT IMAGES

    Setup_NoImage();
});

function openSubMenu() {
    $(".sub_menu").css("display", "none");

    // 500 is almost half the #navigation_wrapper
    intLeft = document.documentElement.clientWidth / 2 - 500;

    $(this).find(".sub_menu").css("left", intLeft + "px");
    $(this).find(".sub_menu").css("display", "block");

}

function closeSubMenu() {
    $('.sub_menu').css('display', 'none');
}


function ThumbMouseOver() {

    $(".product_picture").attr("src", $(this).attr("src") );
    
}



function Setup_NoImage() {

    SetNoImage(".product_medium");
    SetNoImage(".product_picture");
    SetNoImage(".product_image");

    SetNoImage(".search_results_image");


    SetNoImageCategory("#cphBody_imgCategoryPictureLarge");
    
    
    // products

    SetNoImage(".optionimg");
    SetNoImage("#product_thumbs img");
    SetNoImage(".product_relative");
    SetNoImage(".product_relative_thumb");
    SetNoImage(".optionimg_image");

    // Basket

    SetNoImage(".basket_thumb");
    

}

function require(jspath) {
    document.write('<script type="text/javascript" src="' + jspath + '"><\/script>');
}

function trim(s) {
    var l = 0;
    var r = s.length - 1;

    while (l < s.length && s[l] == ' ') {
        l++;
    }
    while (r > l && s[r] == ' ') {
        r -= 1;
    }

    return s.substring(l, r + 1);
}

function SetNoImage(strClassName) {

    $(strClassName).each(function () {
        if ($(this).context.naturalWidth == 0 || $(this).readyState == 'uninitialized') {
            $(this).unbind("error").attr("src", "http://images.house2homemegastore.co.uk/noimage.jpg");
        }
    });

}


function SetNoImageCategory(strClassName) {

    $(strClassName).each(function() {
        if ($(this).context.naturalWidth == 0 || $(this).readyState == 'uninitialized') {
            $(this).unbind("error").attr("src", "http://images.house2homemegastore.co.uk/noimage_category.jpg");
        }
    });

}


function Setup_ThirdLevel() {

    $(".third_menu").each(function () {

        var $CategoryName;
        var $ThirdLevel;

        $ThirdLevel = $(this);

        // find and highlight category with another level 

        $CategoryName = $ThirdLevel.parent().find(".sub_category");
        $CategoryName.css("font-weight", "bold");


        // show the menu

        $CategoryName.mouseover(function () {
            $CategoryName.css("height", "300px");
            $ThirdLevel.css("display", "block");
        });

        $CategoryName.mouseout(function () { $ThirdLevel.css("display", "none"); });

    });

}
