﻿/// <reference path="Source/jquery-1.2.6-vsdoc.js" />
var Product;
var CountryIDDefault = 1;
$(document).ready(function() {
    CountrySetup();
    HeaderSetup();
    HomeTestimonialsSetup();
    TestimonialsSetup();
    if (location.pathname == "/" || location.pathname.toLowerCase() == "/default.aspx") {
        ContentSetup();
        ContactUsSetup();
        ProductsSetup();
    }
    else if (location.pathname.toLowerCase().indexOf("admin.aspx") == 1) {
        AdminSetup();
    }
    else if (location.pathname.toLowerCase().indexOf("content.aspx") == 1) {
        AdminContentSetup();
    }
    Initialize();
});
function Initialize() {

}
function CountrySetup() {
    $("#UCHeaderCountrySelect").change(function() {
        top.window.location = "http://" + $("#UCHeaderCountrySelect").val();
    });
}
$("#UCHeaderLanguageSelect").change(function() {
    top.window.location = "http://" + $("#UCHeaderLanguageSelect").val();
});
function HeaderSetup() {
    $('#UCHeaderImages').removeClass("Hidden");
    $('#UCHeaderImagesLeft').cycle({ timeout: 9000, speed: 500, before: null, after: null, height: 'auto', sync: 1, fit: 0, pause: 0, delay: 0, slideExpr: null });
    $('#UCHeaderImagesCenter').cycle({ timeout: 9000, speed: 500, before: null, after: null, height: 'auto', sync: 1, fit: 0, pause: 0, delay: 1000, slideExpr: null });
    $('#UCHeaderImagesRight').cycle({ timeout: 9000, speed: 500, before: null, after: null, height: 'auto', sync: 1, fit: 0, pause: 0, delay: 2000, slideExpr: null });
    $('#UCHeaderLogo').removeClass("Hidden");
    $('#UCHeaderLogo').hide();
    $('#UCHeaderLogo').slideDown('slow');
    $('#UCHeaderMenu').removeClass("Hidden");
    $('#UCHeaderMenu').hide();
    $('#UCHeaderMenu').slideDown('slow');
}
function ContentSetup() {
    $('.DivUCContent').removeClass("Hidden");
    $('.DivUCContent').hide();
    $('#DivUCHome').slideDown();
    $('.ContentUpdate').click(function() { ContentUpdate($(this).attr("content")); });
}
function ContentUpdate(content) {
    $('.DivUCContent[content!="' + content + '"]').slideUp('normal');
    $('.DivUCContent[content="' + content + '"]').slideDown('normal');
}
function ContactUsSetup() {
    $('#UCContactUsButtonSubmit').click(function() { ContactUsSubmit(); });
    $('#UCContactUsButtonReset').click(function() { ContactUsReset(); });
    $('#UCContactUsResults').hide();
}
function ContactUsSubmit() {
    var results = Email($('#UCContactUsInputName').attr("value"), $('#UCContactUsInputCompany').attr("value"), $('#UCContactUsInputPhone').attr("value"), $('#UCContactUsInputEmail').attr("value"), $('#UCContactUsInputCountry').attr("value"), $('#UCContactTextAreaComments').attr("value"));
    results = "success"
    if (true) {
        $('#UCContactUsForm').slideUp("normal");
        $('#UCContactUsResults').slideDown("normal");
    }
    else {
        alert(results);
    }
    $('#UCContactUsForm').slideUp("normal");
    $('#UCContactUsResults').slideDown("normal");
}
function ContactUsReset() {
    $('.UCContactUsInput').attr("value", "");
    $('#UCContactUsResults').slideUp("normal");
    $('#UCContactUsForm').slideDown("normal");
}

function ProductsSetup() {
    $("#ProductsMenu").treeview({
        animated: true,
        unique: true
    });
    $('.treeview span.File').click(function() {
        ProductSearch($(this).attr("productid"));
    });
}
function ProductSearch(productid) {
    $("#UCProductsProduct").slideUp('normal');
    $("#UCProductsIntro").slideUp('normal');
    var searchurl = "Services/MarketingArm.svc/Product?productid=" + productid;
    $.ajax({ type: "GET", url: searchurl, data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { ProductUpdate(msg.d); } });
}
function ProductUpdate(data) {
    Product = data;
    $("#UCProductsProductTitle").html(Product.title);
    $("#UCProductsProductImage").html("<image class='UCProductsProductImage' src='Assets/Images/Products/product" + Product.id + ".jpg' /><br><span id='UCProductsProductImageCaption' class='Small'>Roll over to enlarge</span>");
    $("#UCProductsProductDescription").html(Product.description);
    $(".UCProductsProductImage").mouseover(ProductZoom);
    $(".UCProductsProductImage").mouseout(ProductUnZoom);
    $("#UCProductsProduct").slideDown('normal');
}
function ProductZoom() {
    $(".UCProductsProductImage").unbind('mouseover', ProductZoom);
    $(".UCProductsProductImage").animate({ "width": "300px" }, "fast");
}
function ProductUnZoom() {
    $(".UCProductsProductImage").animate({ "width": "150px" }, "fast", function() {
        $(".UCProductsProductImage").mouseover(ProductZoom);
    });
}
function AdminSetup() {
    $("#ProductsMenu").treeview({
        animated: true,
        persist: "location",
        unique: true
    });
}
function TestimonialsSetup() {
    $("#UCTestimonialsNext").click(function() {
        var total = $(".UCTestimonialsItem").length;
        var selected = parseInt($(".UCTestimonialsItem:visible").attr("testimonialid"));
        $(".UCTestimonialsItem[testimonialid = " + selected.toString() + "]").hide('fast');
        selected = (selected % total) + 1;
        $(".UCTestimonialsItem[testimonialid = " + selected.toString() + "]").show('fast');
    });
    $(".TestimonialsUpdate").click(function() {
        TestimonialsChange($(this).attr("testimonialid"));
    });
}
function TestimonialsChange(testimonialid) {
    ContentUpdate("Testimonials");
    $(".UCTestimonialsItem").hide('fast');
    $(".UCTestimonialsItem[testimonialid = " + testimonialid.toString() + "]").show('fast');
}
function HomeTestimonialsSetup() {
    var date = new Date();
    date = date % $(".UCHomeRightBottomTestimonial").length;
    $("#UCHomeRightBottomTestimonial").cycle({ timeout: 7000, startingSlide: date });
}

function AdminContentSetup() {
    $(".AdminContentButtonEdit").click(function() { AdminContentEdit($(this).attr("itemname")); });
    $(".AdminContentButtonRevert").click(function() { AdminContentRevert($(this).attr("itemname")); });
    $(".AdminContentButtonSave").click(function() { AdminContentSave($(this).attr("itemname")); });
    $(".AdminContentButtonCancel").click(function() { AdminContentCancel($(this).attr("itemname")); });
    $(".AdminContentButtonUseDefault").change(function() { AdminContentUseDefault($(this).attr("itemname"), $(this).attr("checked")); });

    if ($(".AdminContentCountries").val() == CountryIDDefault) {
        $(".AdminContentButtonUseDefault").attr("disabled", "disabled");
    }

}
function AdminContentEdit(name) {
    $(".AdminContentEdit[itemname='" + name + "']").show();
    $(".AdminContentItem[itemname='" + name + "'] .AdminContentValue").hide();
}
function AdminContentRevert(name) {
    $(".AdminContentItem[itemname='" + name + "'] .AdminContentValueEdit").val($(".AdminContentItem[itemname='" + name + "'] .AdminContentValueOriginal").html());
    if ($(".AdminContentItem[itemname='" + name + "'] .AdminContentIsDefaultOriginal").html() == "True") {
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentValueEdit").attr("disabled", "disabled");
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentButtonUseDefault").attr("checked", " ");
    }
    else {
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentValueEdit").removeAttr("disabled");
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentButtonUseDefault").removeAttr("checked");
    }

}
function AdminContentSave(name) {

    $(".AdminContentItem[itemname='" + name + "'] .AdminContentValue").html($(".AdminContentItem[itemname='" + name + "'] .AdminContentValueEdit").val());
    if ($(".AdminContentItem[itemname='" + name + "'] .AdminContentButtonUseDefault").attr("checked") == true) {
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentIsDefault").html("True");
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentIsDefaultTextBox").val("True");
    }
    else {
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentIsDefault").html("False");
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentIsDefaultTextBox").val("False");
    }
    $(".AdminContentEdit[itemname='" + name + "']").hide();
    $(".AdminContentItem[itemname='" + name + "'] .AdminContentValue").show();
}
function AdminContentCancel(name) {

    $(".AdminContentItem[itemname='" + name + "'] .AdminContentValueEdit").val($(".AdminContentItem[itemname='" + name + "'] .AdminContentValue").html());
    if ($(".AdminContentItem[itemname='" + name + "'] .AdminContentIsDefault").html() == "True") {
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentValueEdit").attr("disabled", "disabled");
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentButtonUseDefault").attr("checked", " ");
    }
    else {
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentValueEdit").removeAttr("disabled");
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentButtonUseDefault").removeAttr("checked");
    }
    $(".AdminContentEdit[itemname='" + name + "']").hide();
    $(".AdminContentItem[itemname='" + name + "'] .AdminContentValue").show();
}
function AdminContentUseDefault(name, checked) {
    if (checked == true) {
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentValueEdit").val($(".AdminContentItem[itemname='" + name + "'] .AdminContentValueDefault").html());
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentValueEdit").attr("disabled", "disabled");

    } else {
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentValueEdit").val("");
        $(".AdminContentItem[itemname='" + name + "'] .AdminContentValueEdit").removeAttr("disabled");
    }
}

/******** START EMAIL *******/
function Email(name, company, phone, email, country, comments) {
    var results
    var searchurl = "http://marketingarm.com/Services/MarketingArm.svc/Email?name='" + name + "'&company='" + company + "'&phone='" + phone + "'&email='" + email + "'&country='" + country + "'&comments='" + comments;
    $.ajax({ async: false, type: "GET", url: searchurl, data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { results = msg.d.Email; } });
    return results;
}
/******** END EMAIL *******/
