﻿//Get the screen width
//-------------------------------------------------------------------------------------
// first we'll split this cookie up into name/value pairs
// note: document.cookie only returns name=value, not the other components
var a_all_cookies = document.cookie.split(';');
var cookie_name = '';
var b_cookie_found = false; // set boolean t/f default f

for (i = 0; i < a_all_cookies.length; i++) {
    // now we'll split apart each name=value pair
    cookie_name = a_all_cookies[i].split('=');
    // if cookie name not match the cooki_name + "?ColorDepth=" + screen.colordepth
    if (cookie_name == "SitePublicCookie45874555887#$#")
        b_cookie_found = true;
}

if (!b_cookie_found)
    SetCookie();


//Setting the cookie
function SetCookie(expires, path, domain, secure) {
    var today = new Date();
    var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
    var value = "ScreenWidth:" + screen.width + ";ScreenHeight:" + screen.height;
    document.cookie = "SitePublicCookie45874555887#$#" + "=" + escape(value) +
                          ((expires) ? "; expires=" + expiry.toGMTString() : "") +
                          ((path) ? "; path=" + path : "; path=/") +
                          ((domain) ? "; domain=" + domain : "") +
                          ((secure) ? "; secure" : "");
}
//-------------------------------------------------------------------------------------

//Search filter menu collabsible panel and arrows
//-------------------------------------------------------------------------------------
jQuery.fn.fadeSliderToggle = function (settings) {
    settings = jQuery.extend({
        speed: 300,
        easing: "swing"
    }, settings)

    headingsearchfilter = this;
    contentsearchfilter = this.next(".contentsearchfilter");
    if ($(contentsearchfilter).css("display") == "none") {
        $(contentsearchfilter).animate({
            opacity: 1,
            height: 'toggle'
        }, settings.speed, settings.easing);

        headingsearchfilter.find("div.ArrowExpandsearchfilter").attr("class", "ArrowClosesearchfilter");
    } else {
        $(contentsearchfilter).animate({
            opacity: 0,
            height: 'toggle'
        }, settings.speed, settings.easing);

        $(headingsearchfilter).find("div.ArrowClosesearchfilter").attr("class", "ArrowExpandsearchfilter");
    }
};


$(document).ready(function () {
    //toggle the componenet
    $(".headingsearchfilter").click(function () {
        $(this).fadeSliderToggle()
        return false;
    });
});
//-------------------------------------------------------------------------------------

//Eliminate Email Spam
//-------------------------------------------------------------------------------------
function InsertMailToTag(userName, domainName) {
    var EmailId;
    var atSign = "&#64;"
    var fullStop = "&#46";

    EmailId = userName;
    EmailId = "" + EmailId + atSign;
    EmailId = EmailId + domainName;

    document.write("<a href='mail" + "to:" + EmailId + "'>" + EmailId + "</A>");
}
//-------------------------------------------------------------------------------------


//Open popup
//-------------------------------------------------------------------------------------
function OpenPopup(url, w, h) {
    w += 34;
    h += 131;

    var win = window.open(url, 'NewWindow', 'width=' + w + ', height=' + h + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=no, resizable=no');
    win.resizeTo(w, h);
    if (window.focus) win.focus()
}

function OpenPopupScroll(url, w, h) {
    w += 34;
    h += 131;

    var win = window.open(url, 'NewWindow', 'width=' + w + ', height=' + h + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');
    win.resizeTo(w, h);
    if (window.focus) win.focus()
}
//-------------------------------------------------------------------------------------


// Print
//-------------------------------------------------------------------------------------
function printpage() {
    window.print();
}
//-------------------------------------------------------------------------------------

//Random Testimonials
//-------------------------------------------------------------------------------------
//function randomTestimonial() { 

//    var pause = 5000; // define the pause for each tip (in milliseconds)
//    var length = $("#testimonials li").length;
//    var temp = -1;

//    function getRan() {
//        // get the random number
//        var ran = Math.floor(Math.random() * length) + 1;
//        return ran;
//    };
//    function show() {
//        var ran = getRan();
//        // to avoid repeating
//        while (ran == temp) {
//            ran = getRan();
//        };
//        temp = ran;
//        $("#testimonials li").hide();
//        $("#testimonials li:nth-child(" + ran + ")").fadeIn("slow");
//    };
//    show(); setInterval(show, pause);
//}
//-------------------------------------------------------------------------------------

////Old Slidshow
//function InitSlideShow() {
//    //Show Image Description and Set Transparency on Block
//    //$(".main_image .desc").show(); //Show Banner
//    //$(".main_image .block").animate({ opacity: 0.85 }, 1); //Set Opacity

//    //Click and Hover Events for Image List
//    $(".image_thumb ul li:first").addClass('active'); //Add the active class (highlights the very first list item by default)
//    $(".image_thumb ul li:first img").attr({ src: $(".image_thumb ul li:first img").attr('src').replace('_g.jpg', '.jpg') });


//    $(".image_thumb ul li")
//    .hover(function () {
//        //Set Variables
//        var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
//        var imgTitle = $(this).find('a').attr("alt"); //Get Main Image URL
//        var imgLink = $(this).find('a').attr("href"); //Get Main Image URL
//        var imgDesc = $(this).find('.block p').html();  //Get HTML of the "block" container
//        var imgDescHeight = $(".main_image").find('.block').height(); //Find the height of the "block"

//        if ($(this).is(".active")) {  //If the list item is active/selected, then...
//            return false; // Don't click through - Prevents repetitive animations on active/selected list-item
//        } else { //If not active then...
//            $(".main_image a").attr({ href: imgLink });
//            $(".main_image img").attr({ src: imgTitle, alt: imgAlt });
//        }
//        //Reset Thumbs
//        $('.image_thumb ul li').each(function (index) {
//            $(this).find('img').attr({ src: $(this).find('img').attr("src").replace('_hover.jpg', '_th.jpg') });
//        });
//        //Set the thumbnail for the active section
//        $(this).find('img').attr({ src: $(this).find('img').attr("src").replace('_th.jpg', '_hover.jpg') });
//        //Show active list-item
//        $(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all list-items
//        $(this).addClass('active');  //Add class of 'active' on the selected list
//        return false;
//    });

//    //Toggle the Hide/Show Option
//    $("a.collapse").click(function () {
//        $(".main_banner .block").slideToggle(); //Toggle the description (slide up and down)
//        $("a.collapse").toggleClass("show"); //Toggle the class name of "show" (the hide/show tab)
//    });
//}


//
//-----------------------------------------------------------------------------------------

//$(document).ready(function () {
//Verify IE version IE6 Warning
//-------------------------------------------------------------------------------------
// Artin : No where using =>
//    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
//        if ($.cookie('ie6Warning') == null || $.cookie('ie6Warning') == '') {
//            $("#ie6-updgrade").slideToggle();
//            $.cookie('ie6Warning', 'true', { path: '/' });
//        }
//    }
//}

//CMS search menu Hover
//-------------------------------------------------------------------------------------
//On hover in
$(document).ready(function () {
    function megaHoverOver() {
        $(this).find(".sub").stop().fadeTo('fast', 0.95).show(); //Find sub and fade it in
        (function ($) {
            //Function to calculate total width of all ul's
            jQuery.fn.calcSubWidth = function () {
                rowWidth = 0;
                //Calculate row
                $(this).find("ul").each(function () { //for each ul...
                    rowWidth += $(this).width() + 12; //Add each ul's width together
                });
            };
        })(jQuery);

        if ($(this).find(".row").length > 0) { //If row exists...

            var biggestRow = 0;

            $(this).find(".row").each(function () {	//for each row...
                $(this).calcSubWidth(); //Call function to calculate width of all ul's
                //Find biggest row
                if (rowWidth > biggestRow) {
                    biggestRow = rowWidth;
                }
            });

            $(this).find(".sub").css({ 'width': biggestRow }); //Set width
            $(this).find(".row:last").css({ 'margin': '0' });  //Kill last row's margin

        } else { //If row does not exist...

            $(this).calcSubWidth();  //Call function to calculate width of all ul's
            $(this).find(".sub").css({ 'width': rowWidth }); //Set Width

        }
    }
    //On Hover Out
    function megaHoverOut() {
        $(this).find(".sub").stop().fadeTo('fast', 0, function () { //Fade to 0 opactiy
            $(this).hide();  //after fading, hide it
        });
    }

    //Set custom configurations
    var config = {
        sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
        interval: 0, // number = milliseconds for onMouseOver polling interval
        over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
        timeout: 0, // number = milliseconds delay before onMouseOut
        out: megaHoverOut // function = onMouseOut callback (REQUIRED)
    };

    $("ul#mainnav li .sub").css({ 'opacity': '0' }); //Fade sub nav to 0 opacity on default
    $("ul#mainnav li").hoverIntent(config); //Trigger Hover intent with custom configurations

});

//top search menu (old)
//-------------------------------------------------------------------------------------
//$(document).ready(function () {    

//show the user menu if cookie is active on page load
//-------------------------------------------------------------------------------------
// Artin: No where using =>
//    if ($.cookie('ActiveUserMenu') != null && $.cookie('ActiveUserMenu') != '') {
//        var menuPanelID = $.cookie("ActiveUserMenu");
//        $(".TopMenuPanel").show();
//        $("#" + menuPanelID + "Panel").show();
//        $("#" + menuPanelID).css("color", "#237DC1");
//    }
//--------------------------------------------------------------------------------------
//Show Menu on click
//-------------------------------------------------------------------------------------
//    $('.Menu1 ul li > a.UserLinkMenu').click(function () {
//        var menuPanelID = $(this).attr('id');
//        if ($(".TopMenuPanel").is(":visible") == true) {
//            HidePanel();
//        }
//        $(".TopMenuPanel").slideToggle("slow", function () {
//            $("#" + menuPanelID + "Panel").show();
//            $("#" + menuPanelID).css("color", "#237DC1");
//            $('#divCloseBtn').show();
//        });
//        $.cookie('ActiveUserMenu', menuPanelID, { path: '/' });
//        return false;
//    });

//    //Hide Menu Panel
//    $('#divCloseBtn').click(function () {
//        HidePanel();
//        $.cookie('ActiveUserMenu', '', { path: '/' });
//    });

//    function HidePanel() {
//        $('#divCloseBtn').hide();
//        $(".hide").hide();
//        $(".TopMenuPanel").slideToggle("slow");
//        $('.Menu1 ul li > a').css("color", "#999999");
//    }
//    
//});
