//jQuery.noConflict();

/*
 * General DOM ready statemenets
 */
jQuery(function ($) {

    if (($.browser.msie) && ($.browser.version <= 6)) {
        $('#nav li:first-child, .tab ul li:first-child, .tabs-list li:first-child, #useful-links li:first-child, .network .tab li:first-child, #homepage.network .tab li:first-child').addClass('first-child')
    }

    //is is the subhomepage, add the class 'network'
    if ($('#isSubHome').length) {
        $('#homepage').addClass('network');
    }

    $('#search, #subscribe').emptyOnFocus();

    $('.tabs-list').click(function (event) {
        $a = $(event.target);
        if ($a.is('a')) {
            $li = $a.parent();
            $li.siblings('li').removeClass('active').end().addClass('active');
            index = $li.index(); //Active index
            $(this).siblings('#latest-news').find('.tab').hide() //All tabs
				.eq(index).show(); //Showing active tab
        }
    }).each(function () {
        $(this)
			.find('>li:first').addClass('active').end() //Activating the first tab on dom ready
			.siblings('#latest-news').find('.tab').not(':first').hide();
    });

    if ($('#slider-inner').length) {
        var rotTime = parseInt($("#rotatorTime").val());
        $('#slider-inner').after('<div id="pager">').cycle({
            fx: 'fade',
            pager: '#pager',
            speed: 1000,
            timeout: rotTime
        });
    }
    //ribbons
    /*
    #header-icons li {
    color:#666666;
    float:left;
    font-weight:bold;
    padding:0 0 0 20px;
    width:170px;
    }
    */


    for (i = 1; i <= 5; i++) {
        if ($('#rightNavSubMenu' + i).length == 0) {
            $('#leftNavSubMenu' + i).css({ 'width': '200px' })
        }
    }
    if ($('#header-icons').children().length == 5) { $('#header-icons').children().css({ 'width': '180px', 'padding': '0 0 0 10px' }) };

    //boxes
    //adjust wideBoxes width
    $('div.widebox > div.box-bg > div.box-inner').each(function () { if ($(this).siblings().length != 0) { } else { $(this).css({ 'width': '365px' }); } })
    //adjust shortBoxes height
    $('div.shortbox> div.box-bg > div.box-inner').each(function () { if ($(this).siblings().length != 0) { } else { $(this).css({ 'height': '200px' }); } })

    if ($('#column').length) {
        //este column
        $('#main-wrap, #content-wrap > #box-wrap').css({ 'width': '780px' });

        if ($('#inner-column').length) {
            //este inner-column
        } else {
            //nu este inner-column
            $('#inner-wrap > #inner-content').css({ 'width': '578px' });
        }

        if ($('#main-wrap > #side').length) {
            //este side
            //$('#main-wrap > #main').css({'width': '570px'})
            $('#main-wrap > #main').css({ 'width': '549px' })
        } else {
            //nu este side
            $('#main-wrap > #main').css({ 'width': '780px' })

        }

    } else {
        //nu este column
        if ($('#inner-column').length) {
            //este inner-column
        } else {
            //nu este inner-column
            $('#inner-wrap > #inner-content').css({ 'width': '780px' });
        }

        $('#main-wrap, #content-wrap > #box-wrap').css({ 'width': '980px' });


        if ($('#main-wrap > #side').length) {
            //este side
            $('#main-wrap > #main').css({ 'width': '780px' })

        } else {
            //nu este side
            $('#main-wrap > #main').css({ 'width': '980px' })
        }
    }

    //Set Branding top Image
    var brandBakImageUrl = "'" + $('#brandBakImageUrl').val() + "'";    
    if (brandBakImageUrl != "'undefined'")
        $('#content').css('background', '#fff url(' + brandBakImageUrl + ') no-repeat 0 0');
    

    //top nav bar
    for (var i = 1; i <= 5; i++) {
        $('#menuItem' + i).bind('mouseover', { 'id': i }, function (params) {
            var id = params['data']['id'];
            $('#navSubMenu' + id).css({ 'display': 'block' });
            $('#navSubMenu' + id).children().css({ 'display': 'inline' });
            $('#menuItem' + id + '> a').addClass("hovered");

            if (id != 1) {
                $('#navSubMenu' + id).css({ 'margin-left': '1px' });
            }
            /*
            var auxPaddingLeft = $('#menuItem'+id +'> a').css('padding-left');
            var auxPaddingRight = $('#menuItem'+id +'> a').css('padding-right');
            newWidth = parseInt(newWidth) + parseInt(auxPaddingLeft) + parseInt(auxPaddingRight) + 2;
            $(this).css({'width':newWidth+'px'});
            */
        });

        $('#menuItem' + i).bind('mouseout', { 'id': i }, function (params) {
            var id = params['data']['id'];
            $('#navSubMenu' + id).css({ 'display': 'none' });
            $('#navSubMenu' + id).children().css({ 'display': 'none' });
            $('#menuItem' + id + '> a').removeClass("hovered");
        });
    }

});

/*START function used for char limitation on text area control on MailBox*/
jQuery.fn.maxLength = function(max) {
    this.each(function() {
        //Get the type of the matched element
        var type = this.tagName.toLowerCase();
        //If the type property exists, save it in lower case
        var inputType = this.type ? this.type.toLowerCase() : null;
        //Check if is a input type=text OR type=password
        if (type == "input" && inputType == "text" || inputType == "password") {
            //Apply the standard maxLength
            this.maxLength = max;
        }
        //Check if the element is a textarea
        else if (type == "textarea") {
            //Add the key press event
            this.onkeypress = function(e) {
                //Get the event object (for IE)
                var ob = e || event;
                //Get the code of key pressed
                var keyCode = ob.keyCode;
                //Check if it has a selected text
                var hasSelection = document.selection ? document.selection.createRange().text.length > 0 : this.selectionStart != this.selectionEnd;
                //return false if can't write more
                return !(this.value.length >= max && (keyCode > 50 || keyCode == 32 || keyCode == 0 || keyCode == 13) && !ob.ctrlKey && !ob.altKey && !hasSelection);
            };
            //Add the key up event
            this.onkeyup = function() {
                //If the keypress fail and allow write more text that required, this event will remove it
                if (this.value.length > max) {
                    this.value = this.value.substring(0, max);
                }
            };
        }
    });
};

$().ready(function() {
$(".GuestbookFormStyletextarial").maxLength(2000);
});
/*END function used for char limitation on text area control on MailBox*/

  function redesign(){
    //boxes
    //adjust wideBoxes width
    $('div.widebox > div.box-bg > div.box-inner').each(function(){if($(this).siblings().length != 0){}else{ $(this).css({'width': '365px'});} })
    //adjust shortBoxes height
    $('div.shortbox> div.box-bg > div.box-inner').each(function(){if($(this).siblings().length != 0){}else{$(this).css({'height': '200px'});}})
    
     if ($('#inner-column').length) 
        {
        //este inner-column
        }else
        {
        //nu este inner-column
          $('#inner-wrap > #inner-content').css({'width': '578px'});
        }
    
    if ($('#column').length) {
        //este column
        $('#main-wrap, #content-wrap > #box-wrap').css({'width': '780px'});
		
        
        
        if ($('#main-wrap > #side').length){
          //este side
          $('#main-wrap > #main').css({'width': '570px'})
        }else{
          //nu este side
          $('#main-wrap > #main').css({'width': '780px'})
		  
        }
        
      }else{
        //nu este column
        $('#main-wrap, #content-wrap > #box-wrap').css({'width': '980px'});
        
        
        if ($('#main-wrap > #side').length){
          //este side
          $('#main-wrap > #main').css({'width': '780px'})
		  
        }else{
          //nu este side
          $('#main-wrap > #main').css({'width': '955px'})
        }
        
        
      }
    
    
  }

