/*lighbox(); Corporate Profile Press Releases section PR links popup
PRslider();
*/
var col_1_width = 0;
var col_2_width = 0;
var ShowToolkit = 3;
function template1() {
    var outer = $("#outer").width();
    var msli_length = $(".msum_top_horz ul li").length;
    var paddpage = $("#outer div:first-child").css("padding-left");
    var out_width = outer - (parseInt(paddpage) * 2);
    var page_col = 2;
    var padding_leftright = 22; //add extra 2px with left right padding ie if padding-left and padding-right value is 10 -> (10x2)+2 = 22
    var padding_topbtm = 6;
    var margin_gap = 10;
    col_1_width = Math.round(((out_width * 7) / 10) - padding_leftright);
    col_2_width = Math.round(((((out_width - col_1_width) - padding_leftright) - margin_gap) - parseInt(paddpage)));

    $("#msum_top_horz").css({
        padding: "3px 3px 3px 10px",
        float: "right",
        "margin-top": "10px",
        clear: "right",
		display:"none"
    });
    
	$(".msum_top_horz ul").css({
        width: col_2_width + "px"
    });
    
	
    $(".msum_top_horz ul li").css("width", "100%");
    $(".msum_top_horz ul li span:first-child").css("width", "70px");
    $("#search_section").css({
        margin: "0 0 0 10px",
        padding: "3px 10px"
    });
    $("#invtool_top_horz").css({
        padding: "3px 10px",
        margin: "0 0 0 10px",
        background: "none"
    });
    
    $("#ir_desc").css({
        width: "100%",
        clear: "none",
        float: "left"
    });
    $(".ir_desc").css({
        width: "100%"
    });
    
    $("#graph").css({
        width: col_1_width + "px"
    });
    
    $("#prime_rate").css({
        width: col_2_width + "px"
    });
    
    if ($("#graph").length > 0) {
        $("#press_rel").css({
            width: col_1_width + "px"
        });
        $("#CorpEvent").css({
            width: col_2_width + "px",
            "word-wrap": "break-word"
        });
        $("#contact_info").css({
            width: col_2_width + "px",
            "word-wrap": "break-word",
			display:none
        });
    } else {
        $("#press_rel").css({
            width: "100%"
        });
        $("#CorpEvent").css({
            width: (out_width - (padding_leftright)) + "px",
            "margin-top": "10px",
            "word-wrap": "break-word"
        });
        $("#contact_info").css({
            width: (out_width - (padding_leftright)) + "px",
            "margin-top": "10px",
            "word-wrap": "break-word",
			"display":"none"
        });
    }

    $("#press_rel").addClass("left_wraps");
    $("#graph").addClass("left_wraps");
    $("#contact_info").addClass("right_wraps");
    $("#CorpEvent").addClass("right_wraps");
    $("#prime_rate").addClass("right_wraps");

    /* Title is null then section Hide done */
    var TitleHead = $("#TitleHead h3").text();
    if (TitleHead == "") {
        $("#TitleHead").hide();
    }

    /* Widget */
    $(".press_rel").hide();
    $(".press_rel_widget").show();

    $(".invtool_top_horz").hide();
    $(".invtool_top_horz_widget").hide();

    $(".search_section").hide();
    $(".search_section_widget").hide(); /* End Widget */

    $(".search_section_widget .searchValue").keypress(function (event) {
        var code = (event.keyCode ? event.keyCode : event.which);
        if (code == "9" || code == "13") {
            searchButton();
        }
    });
    $(".search_section_widget .searchValue").keyup(function (event) {
        var code = (event.keyCode ? event.keyCode : event.which);
        if (code != "") {
            searchButton();
        }
    });
    $("#dummy_div").css("height", $("#invtool_top_horz").height() + "px");
}

function wrapdivs() {
    var divs = $("div.left_wraps");
    for (var i = 0; i < divs.length; ) {
        i += divs.eq(i).nextUntil(":not(.left_wraps)").andSelf().wrapAll('<div class="wrapperdiv" />').length;
    }
    var divs = $("div.right_wraps");
    for (var i = 0; i < divs.length; ) {
        i += divs.eq(i).nextUntil(":not(.right_wraps)").andSelf().wrapAll('<div class="wrapperdivright" />').length;
    }
    $(".wrapperdiv").css({
        float: "left"
    });

    if ($("#graph").length > 0) {
        $(".wrapperdivright").css({
            float: "left",
            clear: "right",
            "margin-left": "10px"
        });    
    } else {
        $(".wrapperdivright").css({
            float: "left",
            clear: "both"
        });
    }
    var rssdivs = $(".news");
    for (var i = 0; i < rssdivs.length; ) {
        i += rssdivs.eq(i).nextUntil(":not(.news)").andSelf().wrapAll('<div class="autowrap" />').length;
    }
    $(".autowrap").css({
        float: "left",
        width: "100%"
    });

}

/* lightbox */
function lighbox() {
    //select all the a tag with name equal to modal
    $("a[name=modal]").click(function (e) {
        //Cancel the link behavior
        e.preventDefault();

        //Get the A tag
        var id = $(this).attr("href");
        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set heigth and width to mask to fill up the whole screen
        var bgcolor = $("body").css("background-color");
        if (bgcolor = 'transparent') {
            bgcolor = "#ffffff";
        }
        $("#PRmask").css({
            width: maskWidth,
            height: maskHeight,
            "background-color": bgcolor
        });

        //transition effect
        $("#PRmask").fadeIn(1000);
        $("#PRmask").fadeTo("slow", 0.8);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the popup window to center
        $(id).css("top", (winH / 2 - $(id).height() / 2) + $(document).scrollTop());
        $(id).css("left", winW / 2 - $(id).width() / 2);

        //transition effect
        $(id).fadeIn(2000);

        //Pass iframe URL link
        var rel = $(this).attr("rel");
        document.getElementById("showpr").src = rel;
        //$("#showpr").height(482);
    });

    //if close button is clicked
    $(".window .close").click(function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $("#PRmask").hide();
        $(".window").hide();
    });

    //if mask is clicked
    $("#PRmask").click(function () {
        $(this).hide();
        $(".window").hide();
    });
} /* End lightbox */

/* Press Release Slider */
var PRshow;
var PRformat;

function PRslider() {
    var PRWidth = $("#press_rel").width();
    $(".snl_sliderContent").css("width", "100%");
    var mdWidth = PRWidth - 32;
    $(".snl_slidemain").css("width", mdWidth + "px");
    var PRWedget_li_length = $("#snl_slider ul li").length;    
    var loop = Math.round(PRWedget_li_length / 2);
    if (PRWedget_li_length <= 3) {
        $(".l_arrow").hide();
        $(".r_arrow").hide();
    }
    if (PRWedget_li_length >= 3) {
        loop = 3;
    } else {
        loop = PRWedget_li_length;
    }
    var liWidth = Math.round(mdWidth / loop);
    var snl_slider = liWidth * PRWedget_li_length;
    $("#snl_slider").css("width", snl_slider + "px");
    $("#snl_slider ul li").css("width", liWidth + "px");
    $("#LeftClick").css({
        clear: "right",
        float: "right",
        "margin-right": "8px"
    });
    var count = 0;
    var Licount = 0;
    var MainSliderWidth = $("#snl_slider").width();
    var ContainerWidth = $(".snl_slidemain").width();
    var MoveLeft = MainSliderWidth - ContainerWidth;
    //var MyLiWidth = liWidth * loop;/* move three colun */
    var MyLiWidth = liWidth; /* add margin valu */

    $(".r_arrow").click(function () {
        if (MoveLeft > -count) {
            count = count - MyLiWidth;            
        }        
        $("#snl_slider").animate({
            "margin-left": count
        }, 600);
    });
    $(".l_arrow").click(function () {
        if (count != 0) {
            count = count + MyLiWidth;            
        }        
        $("#snl_slider").animate({
            "margin-left": count
        }, 600);
    });
    if (PRshow == "true") {
        PRDateFormat();
    }
} /* End Press Release Slider */

/* Goole Seach Slider */

function GoogleSearchslider() {
    var butH = $(".search_section_widget .search_button").height();
    $("#gSearchbutton").css({
        height: butH
    });
    $("#gSearchbutton").addClass("gLeft");
    searchButton();
    var search_main = $(".search_slider").width();
    var search_button = $(".search_button").width();
    $("input.Text").css({
        "width": (search_main - (search_button + 25)) + "px"
    });
    var gcount = 0;
    var widthSlide = -($("#search_slider").width());
    $(".gSearchbutton").click(function () {
        gcount++;
        //even odd click detect
        var isEven = function (someNumber) {
            return (someNumber % 2 === 0) ? true : false;
        };
        // on odd clicks do this
        if (isEven(gcount) === true) {
            $("#search_slider").animate({
                "margin-right": widthSlide
            }, 1000, function () {
                $("#gSearchbutton").removeClass("gRight").addClass("gLeft");
            });
            searchButton();
        }
        // on even clicks do this
        else if (isEven(gcount) === false) {
            $("#search_slider").animate({
                "margin-right": 0
            }, 1000, function () {
                $("#gSearchbutton").removeClass("gLeft").addClass("gRight");
            });
            searchButton();
        }
    });
}

function searchButton() {
    var searchValue = $(".search_section_widget .searchValue").val();
    if ((searchValue == "") || (searchValue == undefined)) {
        $(".GoogleSearchBut").attr("disabled", "false");
    } else {
        $(".GoogleSearchBut").removeAttr("disabled");
    }
} /* End Goole Seach Slider */

/* Investor Toolkit Slider */

function Invtoollider() {
    var TbutH = $("#ToolkitSlider").height(); ;
    $("#ToolkitButton").css({
        height: TbutH
    });
    $("#ToolkitButton").addClass("gLeft");
    //var setWidth = $("#ToolkitSlider").css("margin-left");
    var ToolkitSlider_length = $("#ToolkitSlider ul li").length;
    var setWidth = ToolkitSlider_length * 20;
    var Toolkit_length = (ToolkitSlider_length - ShowToolkit) * 20;
    var setToolkit = setWidth + Toolkit_length;
    $("#ToolkitSlider").css({
        "width": setWidth + "px",
        "margin-left": -(Toolkit_length) + "px"
    });
    $("a#ToolkitButton").toggle(function () {
        $("#ToolkitSlider").stop().animate({
            "width": setToolkit + "px"
        }, 500, function () {
            $("#ToolkitButton").removeClass("gLeft").addClass("gRight");
        });
        return false;
    }, function () {
        $("#ToolkitSlider").stop().animate({
            "width": setWidth + "px"
        }, 500, function () {
            $("#ToolkitButton").removeClass("gRight").addClass("gLeft");
        });
        return false;
    });
} /* End Investor Toolkit Slider */


/* Date Format */

function PRDateFormat() {
    var len = $("#snl_slider ul li span").size() - 1;
    $("#snl_slider ul li span").each(function (i) {
        if (i <= len) {
            var dateStamp = $(this).text();
            var dateF = dateFormat(dateStamp, PRformat);
            $(this).html(dateF);
        }
    });
} /* End Date Format */

function BodyCss() {
    //Build your CSS.
    var FontSize = $("body").css("font-size");
    if (parseInt(FontSize) <= 10) {
        FontSize = FontSize = $("#Copyright a").css("font-size");
    }
    var FontFamily = $("body").css("font-family");
    var FontColor = $("body").css("color");
    var body_tag_css = "font-size:" + FontSize + "; font-family:" + FontFamily + "; color:" + FontColor;
    //Apply your CSS to the body tag.  You can enter any tag here, as
    //well as ID's and Classes.
    var body_css = "<style type='text/css'>body{" + body_tag_css + "} </style>"
    $(body_css).appendTo("head");
}

$(document).ready(function () {
    $("#PRlightboxes").appendTo($("body"));
    BodyCss();
    template1();
    lighbox();
    PRslider();
    Invtoollider();
    GoogleSearchslider();
    wrapdivs();
});
$(window).resize(function () {
    //template1(); 
    //lighbox();
    //PRslider();
    //Invtoollider();
    //GoogleSearchslider();
});
