$(document).ready(function() {

    //PNG FIX
    if ($.browser != null && $.browser.msie != null) {
        if ($.browser.msie && $.browser.version <= 6) {
            $('#directoryEntries').pngFix();
        }
    }

    if ($("#mainMenu li.activePage") != null) {
        $("#mainMenu li.activePage").addClass("CurrentPage");
        $("#mainMenu > li").hover(
                function() {
                    if ($(this).children().is("ul")) {
                        $("#mainMenu li.activePage").removeClass("activePage").addClass("hideSubmenu");
                        $(this).addClass("activePage");
                    }
                }, function() {
                    if ($(this).children().is("ul")) {
                        $(this).removeClass("activePage");
                        $("#mainMenu li.hideSubmenu").addClass("activePage").removeClass("hideSubmenu");
                        $("#mainMenu li.CurrentPage").addClass("activePage");
                    }
                })
    }

    if ($('.newsletterSubscription input.newsletterSubscriptionEmail, #ankiro_input_right') != null) {
        $('.newsletterSubscription input.newsletterSubscriptionEmail, #ankiro_input_right').focus(function () {
            $(this).animate({  width: "185px"}, 500);
        });
    }

    if ($('.newsletterSubscription input.newsletterSubscriptionEmail, #ankiro_input_right') != null) {
        $('.newsletterSubscription input.newsletterSubscriptionEmail, #ankiro_input_right').blur(function () {
            $(this).animate({  width: "105px"}, 500);
        });
    }

    if ($('tr th') != null) {
        $('tr th').parent().addClass("headerRow");
    }

    if ($("table:not(.mediaTable) tr:odd") != null) {
        $("table:not(.mediaTable) tr:odd").addClass("lightRow");
    }

    if ($("#priorityNav") != null) {
        $("#priorityNav > li").hover(
                function() {
                    $(this).addClass("hover");
                }, function() {
                    $(this).removeClass("hover");
                })
    }

    if ($(".prioritySlide:gt(0)") != null) {
        var priorityNr = 0;
        $(".prioritySlide:gt(0)").hide();
    }

    if ($("ul#priorityNav li") != null) {
        $("ul#priorityNav li").click(function() {
            priorityNr = $("ul#priorityNav li").index(this);
            $("#priorityNav li").removeClass("currentItem").eq(priorityNr).addClass("currentItem");
            $("#prioritySlides .prioritySlide").fadeOut("slow").eq(priorityNr).fadeIn("slow");
        })
    }
    //090512 mrr
    //var txtSearchValue = $("#searchTxt").attr("value");

    //$("#searchTxt").focus(function () {
    //  alert(txtSearchValue);
    //$(this).attr("value","")

    //});


    //$("#searchTxt").blur(function () { 
    // txtSearchNewValue = $(this).attr("value");
    //if ((txtSearchNewValue != txtSearchValue) &&(txtSearchNewValue !="")){
    //}else{
    //      $(this).attr("value",txtSearchValue)
    //}
    // });


    /* BRANCH - EQUAL HIGHT */
    if ($(".branches") != null) {
        var branchesHeight = 50;
        var branchesNr = $(".branches").length;
        if (branchesHeight < $(this).height()) {
            $(".branches").each(function (i) {
                if (branchesHeight < $(this).height()) {
                    branchesHeight = $(this).height()
                }
            });

            $(".branches").each(function (i) {
                $(this).children(".branchesBody").css({height: branchesHeight + "px"})

            });
        }
        /* THEME EQUAL HEIGHT */
        var themeHeight = 50;
        var themeNr = $(".branches").length;
        if (branchesHeight < $(this).height()) {
            $("#themePage .brancheOverview").each(function (i) {
                if (branchesHeight < $(this).height()) {
                    branchesHeight = $(this).height()
                }
            });
            $("#themePage .brancheOverview").each(function (i) {
                $(this).children(".brancheOverviewContent").css({height: branchesHeight - 70 + "px"})

            });
        }
    }


    /* STYLE SWITCHER */
    if ($('.styleswitch') != null) {
        $('.styleswitch').click(function() {
            switchStylestyle(this.getAttribute("rel"));
            return false;
        });

        var c = readCookie('style');
        if (c) {
            switchStylestyle(c);
        }
    }


    /*

     $("#mainMenu li ul").css({height: "0px"});

     $("#mainMenu > li, #serviceMenu > li").hover(function(){
     $(this).addClass("hover");
     },function(){
     $(this).removeClass("hover");
     })

     $(".frontPageShortLinksSelectList ul").hide();
     $(".frontPageShortLinksSelectList").hover(function(){
     $(".frontPageShortLinksSelectList ul").show();
     $(".frontPageShortLinksSelectList").addClass("hover");
     $(".frontPageShortLinksBanners a").css({zIndex: "-2"});

     },function(){
     $(".frontPageShortLinksSelectList ul").hide();
     $(".frontPageShortLinksSelectList").removeClass("hover");
     $(".frontPageShortLinksBanners a").css({zIndex: "2"});
     })









     $("#mainMenu").hover(function(){
     $("#mainMenu li ul").stop().animate({
     height: "150px"
     }, 500 );

     },function(){
     $("#mainMenu li ul").stop().animate({
     height: "0px"
     }, 500 );

     })





     /*



     $("#mainMenu").hover(function(){
     $("#frontPage #content").animate({
     marginTop: "160px",
     }, 500 );

     },function(){
     $("#frontPage #content").animate({
     marginTop: "0px",
     }, 500 );



     })




     $("#mainMenu").hover(function(){
     $("#mainMenu li ul").slideDown(500);
     },function(){
     $("#mainMenu li ul").slideUp(500);
     })







     $("#mainMenu li ul").hide();



     $("#mainMenu.hover li ul").show().slideDown(500).stop().slideDown(500);



     $("#mainMenu.hover li").stop().animate({
     height: "200px",
     }, 500 );
     $("#mainMenu li ul").slideDown(500);

     },function(){
     $("#mainMenu li").stop().animate({
     height: "50px",
     }, 500 );
     $("#mainMenu li ul").slideUp(500);





     $("#mainMenu").slideToggle(500);




     $("#mainMenu").hover(function(){
     $("#mainMenu li ul").stop().slideDown(500);

     },function(){
     $("#mainMenu li ul").stop().slideUp(500);

     })
     */


    function switchStylestyle(styleName) {
        $('link[@rel*=style][@title]').each(function(i) {
            this.disabled = this.getAttribute('title') != styleName;
        });
        createCookie('style', styleName, 365);
    }

// cookie functions http://www.quirksmode.org/js/cookies.html
    function createCookie(name, value, days) {
        var expires;
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            expires = "; expires=" + date.toGMTString();
        } else {
            expires = "";
        }
        document.cookie = name + "=" + value + expires + "; path=/";
    }

    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1, c.length);
            }
            if (c.indexOf(nameEQ) == 0) {
                return c.substring(nameEQ.length, c.length);
            }
        }
        return null;
    }

    function eraseCookie(name) {
        createCookie(name, "", -1);
    }

    var showMoreText = jQuery('#jsReadMoreLable').val();
    var showLessText = jQuery('#jsReadLessLable').val();
	var numberCharactersForText = 600;
	
	var textCharactersForText = jQuery('#numberCharactersForText').val();
	try{
		numberCharactersForText = parseInt(textCharactersForText);
	}catch (err) {}
	
    jQuery('.expanding_text').expander({
        slicePoint: numberCharactersForText,  // default is 100 . first time was 250
        expandPrefix: '',
        expandSpeed: 100,
        expandText: showMoreText, // default is 'read more...'
        userCollapseText: showLessText  // default is '[collapse expanded text]'
    });

    jQuery.fn.showHideItems = function () {
        if (jQuery('#numberOfPagesToShow').val() < this.find('li').length) {
            this.after('<a class="show_more_items">' + showMoreText + '</a>');
            var that = this,
                show_more_items = jQuery('.show_more_items'),
                hide_this_item = that.find('.hide_this_item');
            jQuery('.show_more_items').click(function() {
                var elementDisplay = that.find('.hide_this_item').css('display');
                if (elementDisplay == 'none') {
                    hide_this_item.show();
                    show_more_items.html(showLessText);
                } else {
                    hide_this_item.hide();
                    show_more_items.html(showMoreText);
                }
            });
        }
    };
    
    jQuery('.showHideItems').each(function() {
        jQuery(this).showHideItems();
    });
});




