//Author:PR
//Added On: 06/04/2011
//Purpose: Footer Brands
//Setting the width of footer brands
function SetWidthFooterBrands(width) {

    //Set the Maximum width found to each column
    $('.footer .footer_extra  .footerBrands ul li').each(function () {
        var pos = $(this).index();
        $(this).width(width[pos]);
    });
}


//Author:PR
//Added On: 06/04/2011
//Purpose: Character Count
// Script Used to show character count 
//Author:PR
//Modified On: 08/17/2011
//Purpose: Character Update character count after text box value gets change

function CheckCount(elementVariable, words, classSelector)
//Detect keypress in the textarea
{
    var text_area_box = $(elementVariable).val(); //Get the values in the textarea
    var max_numb_of_words = words; //Set the Maximum Number of characters
    var main = text_area_box.length * 100; //Multiply the lenght on words x 100
    var value = (main / max_numb_of_words); //Divide it by the Max numb of words previously declared
    var count = max_numb_of_words - text_area_box.length; //Get Count of remaining characters
    //To make sure count is always positive
    if (count < 0) {
        count = 0;
    }
    if (text_area_box.length > max_numb_of_words) {
        //Remove the excess words using substring
        var remove_excess_characters = text_area_box.substr(0, max_numb_of_words);
        $(elementVariable).val(remove_excess_characters);
    }
    //Update the charecter count value
    var elem = $(elementVariable).parent().parent().parent().parent().find(classSelector);
    if (typeof (lblCharacterCount) != "undefined") {
        $(elem).html("<table style='float:right;'><tr><td>" + lblCharacterCount + " </td><td style='width:21px; text-align:right;'>" + count + '</td><td>/</td><td>' + max_numb_of_words + '</td></tr></table>'); //Output the count variable previously calculated into the div with id= count
    }
    else {
        $(elem).html("<table style='float:right;'><tr><td>" + "Character Remaining : " + " </td><td style='width:21px; text-align:right;'>" + count + '</td><td>/</td><td>' + max_numb_of_words + '</td></tr></table>'); //Output the count variable previously calculated into the div with id= count
    }

    return false;

}

//Modified On: 08/17/2011
//Purpose: Added the Paste event
function SetCountRemainingOnEdit() {

    $('.count').each(function () {
        var limit = $(this).attr('limit');
        var divParent = $(this).parent();
        var divInput = $(divParent).find('div div span input');
        var divTextarea = $(divParent).find('div div span textarea');
        var classSelector = '.count';

        if (divInput.length != 0) {
            CheckCount(divInput, limit, classSelector);
            $(divInput).keypress(function () {
                CheckCount(this, limit, classSelector);
            });
            $(divInput).keyup(function () {
                CheckCount(this, limit, classSelector);
            });
            $(divInput).change(function () {
                CheckCount(this, limit, classSelector);
            });
            $(divInput).bind('paste', function (e) {
                //Wait till the text gets pasted into the box
                setTimeout("ActionComplete('" + this.id + "')", 250);
            });
            $(divInput).bind('cut', function (e) {
                //Wait till the text gets cut from the box
                setTimeout("ActionComplete('" + this.id + "')", 250);
            });
        }
        if (divTextarea.length != 0) {
            CheckCount(divTextarea, limit, classSelector);
            $(divTextarea).keypress(function () {
                CheckCount(this, limit, classSelector);
            });
            $(divTextarea).keyup(function () {
                CheckCount(this, limit, classSelector);
            });
            $(divTextarea).change(function () {
                CheckCount(this, limit, classSelector);
            });
            $(divTextarea).bind('paste', function (e) {
                //Wait till the text gets pasted into the box
                setTimeout("ActionComplete('" + this.id + "')", 250);
            });
            $(divTextarea).bind('cut', function (e) {
                //Wait till the text gets cut from the box
                setTimeout("ActionComplete('" + this.id + "')", 250);
            });
        }
    });

    //Modified On: 08/17/2011
    //Purpose: Added the Paste event With URL Description field
    $('.countUrl').each(function () {
        var limit = $(this).attr('limit');
        var divParent = $(this).parent();
        var divInput = $(divParent).find('div div span input').get(1);
        var classSelector = '.countUrl';

        if (divInput.length != 0) {
            CheckCount(divInput, limit, classSelector);
            $(divInput).keypress(function () {
                CheckCount(this, limit, classSelector);
            });
            $(divInput).keyup(function () {
                CheckCount(this, limit, classSelector);
            });
            $(divInput).change(function () {
                CheckCount(this, limit, classSelector);
            });
            $(divInput).bind('paste', function (e) {
                //Wait till the text gets pasted into the box
                setTimeout("ActionComplete('" + this.id + "')", 250);
            });
            $(divInput).bind('cut', function (e) {
                //Wait till the text gets cut from the box
                setTimeout("ActionComplete('" + this.id + "')", 250);
            });
        }
    });
}

$(document).ready(function ()//When the dom is ready  
{
    SetBrandsOnMaster();
    SetCountRemainingOnEdit();
});


//Author:ND
//Added On: 04/15/2011
//Purpose:Left Navigation Topics Syncup 
//Left Nav Sync up start

//sychronizes the index
function SetIndex(index, returnable, callClick) {
    try {
        if (window["isSocietyPage"] != undefined && isSocietyPage == true) {
            var indexedObject = ".tab_nav > ul > li:nth-child(" + parseInt(index + 1) + ")";

            //remove the class from L2 navigation
            $(".content_menu.nav > ul > li > h3 > a.selected:first-child").removeClass("selected");

            //
            $(".content_menu.nav > ul > li > ul > li > a.selected:first-child").removeClass("selected");

            //add the selected style to left navigation topic
            $(".content_menu.nav > ul > li > ul > li:nth-child(" + parseInt(index + 1) + ")").find("a").addClass("selected");

            //if clicked through left navigation then call the click event of tabs
            if (callClick) {
                $(indexedObject).click();
            }
        }
    }
    catch (e) { }

    //check if it is called through left navigation then only return false else don't return
    if (returnable) {
        return false;
    }
}

//appends the topics in appropriate HTML
function AppendNavigation() {
    var submenu = '';
    //for each element set click event
    $(".tab_nav >ul>li").each(
                            function (index) {
                                submenu += "<li><a href='#' onclick='javascript:return SetIndex(" + index + ", true, true);'>" + $(this).find("a").html().replace(/<br>/ig, " ") + "</a></li>";
                            });

    $(".nav > ul >li > h3 > a.selected:first-child").each(
            function (index) {
                //if current page already contains children then append before other children
                if ($(this).parent().parent().find("ul").html() != null && submenu != '') {
                    $(this).parent().parent().find("ul>li").before(submenu);
                }
                //else create ul tag and append the children
                else if (submenu != '') {
                    submenu = "<ul>" + submenu + "</ul>";
                    $(this).parent().parent().append(submenu);
                }
                //initialize to first tab
                SetIndex(0, false, false);
            }
        );
}
//Left Nav Sync up end

//Author:ND
//Added On: 04/18/2011
//Purpose: Download Icon events sync up
//Download Icon events sync up start

$(document).ready(function () {
    $(".estee-Download-Image").hover(function (event) {
        $(this).css({
            'background-image': 'url("/Style Library/EsteeLauder/images/icon_download_hover.png")',
            'background-position': 'top left',
            'background-repeat': 'no-repeat',
            'width': '20px',
            'height': '16px',
            'cursor': 'pointer'
        });

        var downloadAnchor = $(this).parent().find(".estee-Download-Text:first a");
        downloadAnchor.css({ 'color': '#f8ec92' });
    }, function (event) {
        $(this).css({
            'background-image': 'url("/Style Library/EsteeLauder/images/icon_download.png")',
            'background-position': 'top left',
            'background-repeat': 'no-repeat',
            'width': '20px',
            'height': '16px',
            'cursor': 'pointer'
        });
        var downloadAnchor = $(this).parent().find(".estee-Download-Text:first a");
        downloadAnchor.css({ 'color': '#f8efca' });
    });

    $(".estee-Download-Image").click(function (event) {
        var downloadAnchor = $(this).parent().find(".estee-Download-Text:first a");
        window.open(downloadAnchor.attr("href"));
    });

    $(".estee-Download-Text:first a").hover(function (event) {
        var downloadImage = $(this).parent().parent().find(".estee-Download-Image:first");
        downloadImage.mouseover();
    }, function (event) {
        var downloadImage = $(this).parent().parent().find(".estee-Download-Image:first");
        downloadImage.mouseout();
    });
    $(".estee-Download-Text:first a").attr("target", "_blank");
});

//Download Icon events sync up end


//Author:AT
//Added On: 04/26/2011
//Purpose: To open LightBox in Story Pages
//To open LightBox in Story Pages
function OpenLightboxold(dataString) {
    var data = new Array();
    var temp = new Array();
    temp = dataString.split('#$&*');
    var count = Math.floor(temp.length / 4);
    for (var i = 0, j = 0; j < count; j++, i = i + 4) {
        data.push({
            'url': temp[i],
            'title': temp[i + 1],
            'caption': temp[i + 2],
            'date': temp[i + 3]
        });
    }
    var slideshow = new FD.SlideShow(data);
    var lightbox = new FD.Lightbox(slideshow);
    lightbox.pop();
    $('.fd_lightbox').height($(document).height());
    $('.fd_lightbox').width($(document).width());
}

//Author:ND
//Added On: 04/26/2011
//Purpose: Asterix sign
//Add Asterix sign start
(function ($) {
    $.inArrayInsensitive = function (val, array) {
        var returnIndex = -1;
        $.each(array, function (index, indexValue) {
            if (indexValue != undefined && val.toLowerCase().trim() == indexValue.toLowerCase().trim()) {
                returnIndex = index;
                return true;
            };
        });
        return returnIndex;
    };
})(jQuery);

function AddAsterixToFields() {
    $(".ms-formfieldcontainer").each(function () {
        var fieldLabel = $(this).find(".ms-formfieldlabelcontainer > .ms-formfieldlabel:first");
        var fieldLabelText = "";

        if (fieldLabel.html() != null) {
            fieldLabelText = fieldLabel.html();
            if ($.inArrayInsensitive(fieldLabelText, requiredFields) >= 0) {
                var fieldValueControlContainer = $(this).find(".ms-formfieldlabelcontainer:first");
                $('<SPAN class="estee-Required">*</SPAN>').appendTo(fieldValueControlContainer);
            }
        }
    });
}
//Add Asterix sign end


//Author:AT
//Added On: 05/30/2011
//Purpose: Converts UTC time to Client Time Zone
//Converts UTC time start
function ConvertUTCToLocalTime(displayFormat, year, month, date, hours, minutes, seconds, ms) {
    var d = Date.UTC(year, month, date, hours, minutes, seconds, ms); //returns the milliseconds elapsed
    var localDateTime = (new Date(d)).toLocaleDateString();
    var dd = new Date(localDateTime);
    dd.setMonth(dd.getMonth() - 1);
    document.write(dd.format(displayFormat));
} //Converts UTC time end


//Author:ND
//Added On: 06/14/2011
//Purpose: attaches download class start
function SetDownloadLinkProperties() {
    var downloadAnchor = $("#downloadContainer a");

    if (downloadAnchor.html() != null) {
        downloadAnchor.addClass("download");
        if (downloadAnchor.attr("target") != null) {
            downloadAnchor.attr("target", "_blank");
        }
    }
}

function AdjustClickHereToTest() {

    if ($("#estee-download-container .ms-formfieldcontainer:first >  .ms-formfieldvaluecontainer:first > span > .ms-formdescription > a") != null) {
        $("#estee-download-container .ms-formfieldcontainer:first >  .ms-formfieldvaluecontainer:first > span > .ms-formdescription > a").attr("target", "_blank");
        $("#estee-download-container .ms-formfieldcontainer:first >  .ms-formfieldvaluecontainer:first > span > .ms-formdescription > a").attr("href", "#");

        $("#estee-download-container .ms-formfieldcontainer:first > .ms-formfieldvaluecontainer:first > span > .ms-formdescription > a").click(function (e) {
            $("#estee-download-container .ms-formfieldcontainer:first >  .ms-formfieldvaluecontainer:first > span > .ms-formdescription > a").attr("target", "_blank");
            $("#estee-download-container .ms-formfieldcontainer:first >  .ms-formfieldvaluecontainer:first > span > .ms-formdescription > a").attr("href", "#");

            var inputUrl = $("#estee-download-container .ms-formfieldcontainer:first >  .ms-formfieldvaluecontainer:first > span > input:first");

            if (inputUrl != null) {
                inputUrl = inputUrl.val().trim().toLowerCase();
            }
            //var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/

            //validated the url format
            var regexp = /^(http|https|ftp):\/[\/]+\w[:]{0,1}[0-9]*[\/]*\w*?/
            if (inputUrl != null && inputUrl != "" && regexp.test(inputUrl)) {
                window.open(inputUrl);
            }

            e.preventDefault();
        });
    }
}

//download link End

//Author:PR
//Added On: 05/07/2011
//Purpose: Header Brands
//Setting the width of Header brands
function SetWidthHeaderBrands(width) {
    var totalColumn = 4;

    //Calculate total width of brand section
    var totalWidth = 0;
    for (i = 0; i < totalColumn; i++) {
        //10 % additional width than footer brands since font is in upper case
        width[i] += parseInt(width[i] * 0.10);
        totalWidth += width[i];
    }

    //Set the Maximum width found to each column
    $('.headerBrands ul li').each(function () {
        var pos = $(this).index();
        $(this).width(width[pos]);
    });

    //Additional width for container include (padding for container and margins 20*4 + 10 + 10)
    totalWidth += 100;
    $('.brandNavWidth').width(totalWidth);
    $('.headerBrands').width(totalWidth);
}

//Author:PR
//Added On: 06/07/2011
//Purpose: Brands On Master Page in Header/Footer
//Setting the width of Header/Footer brands

function SetBrandsOnMaster() {
    var width = new Array();
    var totalColumn = 4;

    //Initialize Array with width 0
    for (i = 0; i < totalColumn; i++) {
        width[i] = 0;
    }

    //Find the Maximum width of each brand column
    $('.footer .footer_extra  .footerBrands ul li').each(function () {
        var pos = $(this).index();
        if (width[pos] < $(this).width()) {
            width[pos] = $(this).width() + 4; //add additional 4 pixel for font rendering in MAC
        }
    });

    SetWidthFooterBrands(width);
    SetWidthHeaderBrands(width);
}

//Author:MA
//Added On: 07/14/2011
//Purpose: Handles Buzz section Date and Time display
function ConvertUTCToLocalBuzzTime(year, month, date, hours, minutes, seconds, ms, format, feedName) {
    var d = Date.UTC(year, month, date, hours, minutes, seconds, ms); //returns the milliseconds elapsed
    var localDateTime = (new Date(d)).toLocaleDateString();
    var dd = new Date(localDateTime);
    if (feedName.toString() == "PressRelease") {
        dd.setMonth(dd.getMonth() - 1);
    }

    var localTime = (new Date(d)).toLocaleTimeString();

    var Time = localTime.split(':');
    var hours = Time[0];
    var minutes = Time[1];
    var clockNotation = Time[2].split(" ")[1];
    if (format.toString() == "Date") {

        document.write(dd.format("MM/dd"));
    }
    else {
        if (format.toString() == "Time") {
            //Working for IE-7/8, FF and MAC 
            if (clockNotation != undefined) {
                if ((hours == 12) && (clockNotation == "AM"))
                    hours = hours - 12;

                document.write(hours + ":" + minutes + " " + clockNotation);

            }
            //In case of 24 hour format
            else {
                //Working for Safari and Chrome
                if (hours > 11) {
                    if (hours != 12)
                    { hours = hours - 12; }

                    document.write(hours + ":" + minutes + " ")
                    document.write("PM")
                }
                else {
                    //To display hours less than 10 as single digit and not as double as per VD
                    if (hours < 10) {
                        hours = hours.toString().charAt(1);
                    }
                    document.write(hours + ":" + minutes + " ")
                    document.write("AM")
                }
            }

        }
    }
}

function DisplayDate(dateTime) {
    document.write(dateTime.format("MM/dd"));
}

function DisplayTime(minutes, hours) {
    if (minutes < 10) {
        minutes = "0" + minutes
    }
    //document.write(hours + ":" + minutes + " ")
    if (hours > 11) {
        if (hours != 12)
        { hours = hours - 12; }
        document.write(hours + ":" + minutes + " ")
        document.write("PM")
    }
    else {
        document.write(hours + ":" + minutes + " ")
        document.write("AM")
    }
}

function TwitterWrapper(created_at, format) {
    var dateTime = new Date(getDateFromFormat(created_at.substring(4).replace("+0000 ", ""), "MMM dd HH:mm:ss yyyy"));
    ConvertUTCToLocalBuzzTime(dateTime.getYear(), dateTime.getMonth(), dateTime.getDate(), dateTime.getHours(), dateTime.getMinutes(), dateTime.getSeconds(), dateTime.getMilliseconds(), format, "Twitter");

}

function FacebookWrapper(created_time, format) {
    /*JS the date constructor is like this:
    new Date(milliseconds)  (milliseconds since 1970/01/01)
    and createdTime is a unix-style seconds-since-1970.
    So multiply by 1000.*/
    var fbMilliSeconds = parseInt(created_time);
    var dateTime = new Date(fbMilliSeconds * 1000);


    var hours = dateTime.getHours();
    var minutes = dateTime.getMinutes();
    if (format.toString() == "Date") {
        DisplayDate(dateTime);
    }
    else {
        if (format.toString() == "Time") {
            DisplayTime(minutes, hours);
        }
    }

}

//Author: PR
//Added On: 07/22/2011
//Purpose: Typekit call to each master page
function LoadTypekit() {
    try {
        Typekit.load({
            active: function () {
                SetContentHeight();
                // As soon as the fonts are active, set height for related link for CR Landing Page
                SetCRRelatedLinkHeight();
            }
        });

    } catch (e) {
    }
}

//Author: MA
//Added On: 07/27/2011
//Purpose: Set Related link padding top which is equal to height difference between Associated Information Header height 
//and related height
function SetCRRelatedLinkHeight() {

    if ($("div.content:first").hasClass('CR-content')) {

        var padding = $('#buzzDisplay .header h1').height() - $(".related_links h3").height();
        if (padding != null) {
            $(".related_links h3").css("padding-top", 0);
            $(".related_links h3").css("padding-top", padding);
        }

    }

}

//Author: DB
//Added On: 08/31/2011
//Purpose: Used on set minimum height according to left nav
function SetContentHeight() {
    var height = $('.content_menu').height();
    //For Non Brand Pages
    if (height != null) {
        $(".content").css("min-height", height);
    }
    else      //Brand Pages  
    {
        var brandmenu_height = ($('.brand_menu').height());
        if (brandmenu_height != null) {
            $(".content").css("min-height", brandmenu_height);
        }
    }

}
//Author: AT
//Added On: 08/03/2011
//Modified On: 08/09/2011 --> Added bindHoverImage() function
//Purpose: Used on ShareThis control to provide the functionality of mousein and mouseout

function showLoadPopup(id1) {
    document.getElementById(id1).style.display = 'block';
    var more = document.getElementById('more');
    if (more != null) {
        more.className = 'more_Icon more_IconSel';
    }
}
function hideLoadPopup(id2) {
    document.getElementById(id2).style.display = 'none';
    var more = document.getElementById('more');
    if (more != null) {
        more.className = 'more_Icon';
    }
}
function iconChange(item, normalImage, hoverImage) {
    $(item).hover(function () {
        $(item).css('background-image', "url('" + hoverImage + "')");
    }, function () {
        $(item).css('background-image', "url('" + normalImage + "')");
    });
}
function bindHoverImage() {
    $('.shareItem a').each(function () {
        var hoverImage = $(this).attr('hoverimg');
        var normImage = $(this).attr('normimg');
        iconChange(this, normImage, hoverImage);
    });
}

//Author: MA
//Added On: 08/09/2011
//Purpose: Sets associated header UI when there is no at a glance section
function AssociatedHeaderSectionUI() {
    if (($.browser.msie) && ($.browser.version == 7.0)) {
        $('.separator').css('margin-top', '20px');
    }

    $('.features').addClass('ataglance-removed');

}

//Author: PR
//Added On: 08/17/2011
//Purpose: Trigger the change event when Paste/Cut event occure
function ActionComplete(Id) {
    //Trigger the change event assosiated
    $('#' + Id).trigger('change');
}

//Author:PR
//Added On: 08/17/2011
//Purpose: Sitemap page
//Setting the height of Sitemap columns
function SetSitemapColumnsHeight() {
    var totalColumn = 5;
    var pos = 0;
    var height = new Array();
    var currentHeight;

    //Find the Maximum height of each Sitemap column
    $('.sitemap_col1').each(function () {
        currentHeight = $(this).height();
        //Increase the position for each new row (Each row has fixed number of columns[totalColumn] )
        if (($(this).index() % totalColumn) == 0) {
            pos = pos + 1;
            height[pos] = 0;
        }
        if (height[pos] <= currentHeight) {
            height[pos] = currentHeight + 4; //add additional 4 pixel for font rendering in MAC
        }
    });

    //Set the Maximum height found to each column
    pos = 0;
    $('.sitemap_col1').each(function () {
        if (($(this).index() % totalColumn) == 0) {
            pos = pos + 1;
        }
        $(this).height(height[pos]);
    });
}


//Author:AT
//Added On: 08/19/2011
//Used On: Press Release Story Page
//Increasing the width of Story content and Headline when there are no Related Links present
function IncreaseWidth() {
    if ($('.aside').is(':hidden')) {
        $('.article2').width('720px');
        $('.article2 .header h1').width('658px');
    }
}

//Author:AT
//Added On: 08/23/2011
//Used On: SpotlightWithRTE pages
//Increasing the height of Content section title, in case, if Spotlight Items are present
function AddHeightToContentSection() {
    if ($('.main_content .features ul').children().size() > 0) {
        $('.main_content .sectionTitle').css('padding-top', '20px');
    }
}

//Author:PR
//Added On: 08/31/2011
//Used On: HomePage Carousal
var donePrev = true;
var doneNext = true;
var autoScroll = true;
var doneCreating = true;

function PrepareCarousal() {

    //Make the button div inside carousal
    $('.list_carousel').append($('.pagenp'));
    $('.pagenp').css('top', '350px');
    $('.pagenp').css('left', '50px');

    //Calculate total width and set width accordingly
    var items = $("#carousalList").find('li');
    var itemsWidth = 0;
    var itemNumber = 0;
    $(items).each(function () {
        //Calculate the items in visible width section
        itemsWidth += $(this).outerWidth(true);
        itemNumber++;
    });
    $("#carousalList").width(itemsWidth);


    //Find if the Items Width is less than carousal width 
    var carousalWidth = itemsWidth;
    //If there are items to scroll
    if (carousalWidth > 660) {

        //Make the carousal scroll
        CreateCarousal();

        //Custom Working of Carousal 

        //On Hover
        $('.list_carousel').hover(function () {
            donePrev = true;
            doneNext = true;
            autoScroll = false;
            doneCreating = true;
            $("#carousalList").stop();
        }, function () {
            doneCreating = true;
            autoScroll = true;

            if (donePrev && doneNext) {
                doneCreating = false;
                autoScroll = false;
                var item = $("#carousalList").find('li:first-child');
                var itemWidth = $(item).outerWidth(true);
                var l = $("#carousalList").css("left").replace("px", "");
                if (isNaN(l)) {
                    l = 0;
                }
                var remainingWidth = itemWidth - Math.abs(parseInt(l));
                var remainingDuration = Math.round(remainingWidth * 10);

                //Make the carousla slide till the last item gone completely
                $('#carousalList').animate({
                    left: (0 - itemWidth)
                }, remainingDuration, 'linear', function () {
                    //CallBack function to restart the carousal
                    $('#carousalList').append(item);
                    $('#carousalList').css('left', '0px');
                    autoScroll = true;
                    doneCreating = true;
                    CreateCarousal();
                });
            }
            return false;
        });

        //Previous Button Click
        $('#prev2').click(function () {
            if (donePrev) {
                donePrev = false;
                var items = $("#carousalList").find('li');
                var itemsWidth = $(items[0]).outerWidth(true); ;
                var itemNumber = 0;
                for (itemNumber = items.length - 1; itemNumber > 0; itemNumber--) {
                    //Calculate the items in visible width section
                    itemsWidth += $(items[itemNumber]).outerWidth(true);
                    if (itemsWidth > 660) {
                        itemsWidth -= $(items[0]).outerWidth(true);
                        while (itemNumber < items.length) {
                            $('#carousalList').prepend($('#carousalList li:last-child'));
                            itemNumber++;
                        }
                        $('#carousalList').css('left', -itemsWidth + 'px');
                        $('#carousalList').stop();
                        $('#carousalList').animate({
                            left: 0
                        }, 2000, 'linear', function () {
                            //CallBack function to restart the carousal
                            CreateCarousal();
                        });
                        break;
                    }
                }
            }
        });

        //Next Button Click 
        $('#next2').click(function () {
            if (doneNext) {
                doneNext = false;
                var items = $("#carousalList").find('li');
                var itemsWidth = 0;
                var itemNumber = 0;
                $(items).each(function () {
                    //Calculate the items in visible width section
                    itemsWidth += $(this).outerWidth(true);
                    if (itemsWidth > 700) {
                        itemsWidth -= $(this).outerWidth(true);
                        $('#carousalList').stop();
                        $('#carousalList').animate({ left: (0 - itemsWidth) }, 2000, 'linear', function () {
                            //CallBack function to restart the carousal
                            while (itemNumber > 0) {
                                $('#carousalList').append($('#carousalList li:first-child'));
                                itemNumber--;
                            }
                            $('#carousalList').css('left', '0px');
                            CreateCarousal();
                        });
                        return false;
                    }
                    itemNumber++;
                });
            }
        });
    }
}

function CreateCarousal() {

    donePrev = true;
    doneNext = true;

    //Make the first visible item from left to scroll
    var item = $("#carousalList").find('li:first-child');
    var itemWidth = 0;
    var itemDuration = 0;

    //Calculate width of the first items in visible width section
    itemWidth = $(item).outerWidth(true);
    itemDuration = itemWidth * 10;

    if (doneNext && donePrev && autoScroll && doneCreating) {
        doneCreating = false;
        $('#carousalList').animate({ left: (0 - itemWidth) }, itemDuration, 'linear', function () {
            //CallBack function to restart the carousal
            $('#carousalList').append(item);
            $('#carousalList').css('left', '0px');
            doneCreating = true;
            if (doneNext && donePrev && autoScroll) {
                CreateCarousal();
            }
        });
    }
    return false;
}

function RemoveDuplicate() {
    var seen = {};
    $('#carousalList li').each(function () {
        var txt = $(this).html();
        if (seen[txt])
            $(this).remove();
        else
            seen[txt] = true;
    });
}

function SetHomePageViewMode() {
    try {
        $('.news div > a').addClass('see_all');
        $('.news span > a').addClass('see_all');
        $('.insight div > a').addClass('see_all_content');
        $('.insight span > a').addClass('see_all_content');

        var minHeightNews = 0;
        var minHeightNewsHeader = 0;

        //Find the maximum News Header Height
        $('.template_0 .news > ul li').each(
                function () {
                    var currentHeaderHeight = $(this).find('.article .header h1').height();
                    if (currentHeaderHeight > minHeightNewsHeader) {
                        minHeightNewsHeader = currentHeaderHeight;
                    }
                }
            );
        //Set the maximum News Header Height
        $('.template_0 .news > ul li .article .header h1').css('height', minHeightNewsHeader + 'px');

        //Find the maximum News Section Height
        $('.template_0 .news > ul li').each(
                function () {
                    var currentHeight = $(this).height();
                    if (currentHeight > minHeightNews) {
                        minHeightNews = currentHeight;
                    }
                }
            );
        //Set the maximum News Section Height
        $('.template_0 .news > ul li').css('height', minHeightNews + 'px');

    } catch (e) {
    }
}

//Author:PR
//Added On: 09/01/2011
//Used On: HomePage Fix click here to test on home page
function FixClickHereToTest() {
    if ($(".downloadContainer .ms-formfieldcontainer:first >  .ms-formfieldvaluecontainer:first > span > .ms-formdescription > a") != null) {
        $(".downloadContainer .ms-formfieldcontainer:first >  .ms-formfieldvaluecontainer:first > span > .ms-formdescription > a").attr("target", "_blank");
        $(".downloadContainer .ms-formfieldcontainer:first >  .ms-formfieldvaluecontainer:first > span > .ms-formdescription > a").attr("href", "#");

        $(".downloadContainer .ms-formfieldcontainer:first > .ms-formfieldvaluecontainer:first > span > .ms-formdescription > a").click(function (e) {
            $(".downloadContainer .ms-formfieldcontainer:first >  .ms-formfieldvaluecontainer:first > span > .ms-formdescription > a").attr("target", "_blank");
            $(".downloadContainer .ms-formfieldcontainer:first >  .ms-formfieldvaluecontainer:first > span > .ms-formdescription > a").attr("href", "#");

            var inputUrl = $(".downloadContainer .ms-formfieldcontainer:first >  .ms-formfieldvaluecontainer:first > span > input:first");

            if (inputUrl != null) {
                inputUrl = inputUrl.val().trim().toLowerCase();
            }
            //var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/

            //validated the url format
            var regexp = /^(http|https|ftp):\/[\/]+\w[:]{0,1}[0-9]*[\/]*\w*?/
            if (inputUrl != null && inputUrl != "" && regexp.test(inputUrl)) {
                window.open(inputUrl);
            }

            e.preventDefault();
        });
    }
}

