﻿function main_search_results() {
    j$(".navigations + div").addClass("row");
    j$(".row + div[class!=relax]").addClass("row bottom");
    j$(".row > div, .row.bottom > div").addClass("product");
    j$(".row > div:eq(0),.row.bottom > div:eq(0)").addClass("product first");
    j$(".row > div:eq(1),.row.bottom > div:eq(1)").addClass("product");
    j$(".row > div:eq(2),.row.bottom > div:eq(2)").addClass("product last");
}

function init_scripts_search_results() {
    if (typeof jQuery != 'undefined') {
        var j$ = jQuery.noConflict();
        j$(document).ready(main_search_results);
    }
}

function main_product() {    
    j$(".main-content").addClass("my-account");
    setupZoom();
}

function init_scripts_product() {
    if (typeof jQuery != 'undefined') {
        var j$ = jQuery.noConflict();
        j$(document).ready(main_product);
    }
}


function index() {
    j$("h1 + div").addClass("row");
    j$(".row + div[class!=relax]").addClass("row bottom");
    j$(".row > div, .row.bottom > div").addClass("product");
    j$(".row > div:eq(0),.row.bottom > div:eq(0)").addClass("product first");
    j$(".row > div:eq(1),.row.bottom > div:eq(1)").addClass("product");
    j$(".row > div:eq(2),.row.bottom > div:eq(2)").addClass("product last");
}

function init_index() {
    if (typeof jQuery != 'undefined') {
        var j$ = jQuery.noConflict();
        j$(document).ready(index);
    }
}

function latest() {
    j$("h1 + div").addClass("row");
    j$(".row + div[class!=relax]").addClass("row bottom");
    j$(".row > div, .row.bottom > div").addClass("product");
    j$(".row > div:eq(0),.row.bottom > div:eq(0)").addClass("product first");
    j$(".row > div:eq(1),.row.bottom > div:eq(1)").addClass("product");
    j$(".row > div:eq(2),.row.bottom > div:eq(2)").addClass("product last");
}

function init_latest() {
    if (typeof jQuery != 'undefined') {
        var j$ = jQuery.noConflict();
        j$(document).ready(latest);
    }
}


function brand() {
    j$(".navigations + div").addClass("row");
    j$(".row + div[class!=relax]").addClass("row bottom");
    j$(".row > div, .row.bottom > div").addClass("product");
    j$(".row > div:eq(0),.row.bottom > div:eq(0)").addClass("product first");
    j$(".row > div:eq(1),.row.bottom > div:eq(1)").addClass("product");
    j$(".row > div:eq(2),.row.bottom > div:eq(2)").addClass("product last");

    // if the bottom row has only one product then remove the border
    if (j$(".row.bottom > div[class*=product]").length == 1) {        
        j$(".row.bottom").css("border-top", "0px");
    }
}

function init_brand() {
    if (typeof jQuery != 'undefined') {
        var j$ = jQuery.noConflict();
        j$(document).ready(brand);
    }
}

function my_account() {
    j$(".main-content").addClass("my-account");
}
function init_my_account() {
    if (typeof jQuery != 'undefined') {
        var j$ = jQuery.noConflict();
        j$(document).ready(my_account);
    }
}

function basket_address() {
    if (j$("input[type='checkbox']").attr("checked") == true)
        j$("#deliveryAddress").show();
    else
        j$("#deliveryAddress").hide();
    j$(".delivery input[type='checkbox']").change(
        function() {
            if (j$(this).attr("checked") == true)
                j$("#deliveryAddress").show();
            else
                j$("#deliveryAddress").hide();
        }
    );
}

function init_basket_address() {
    if (typeof jQuery != 'undefined') {
        var j$ = jQuery.noConflict();
        j$(document).ready(basket_address);
    }
}

function subcategories() {
    j$("select[class='subcategory']").change(function() {
        var subcategory_id = j$(this).val();
        var subcategory = j$(this).children('option[value=\'' + subcategory_id + '\']:first').attr('rel');
        window.location = subcategory;
    });
}

function GetDeliveryAddress(callback) {
    j$.ajax({
        type: "POST",
        url: "ajax_door.aspx/DeliveryAddress",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            address = msg.d;            
            callback(address);
        },
        failure: function(msg) {
        }
    });
}

function search_form() {
    if (typeof jQuery != 'undefined') {
        var j$ = jQuery.noConflict();
        j$(document).ready(function() {
            subcategories();            
        });
    }
}


