/* INITIALIZATION ACTIONS */
jQuery(function () {

	jQuery('a').each(function (i) {
		var anchorHref = $(this).attr('href');
		if(anchorHref != ''){
			try{
			var newAnchorHref = anchorHref.replace("http://auth.dpp.local/","/");
			var newAnchorHref = newAnchorHref.replace("http://AUTH.DPP.LOCAL/","/");
			$(this).attr('href', newAnchorHref);
			}catch(e){}
		}
	});
	
    /*remove last node from breadcrumb and change the previous to last node*/
    jQuery('.breadcrumbitemlast').hide();
    lastBreadCrumb = jQuery('.breadcrumbitem').last();
    lastBreadCrumb.removeClass('breadcrumbitem');
    lastBreadCrumb.addClass('breadcrumbitemlast');
    /*remove last node from breadcrumb and change the previous to last node */

    /*hide image div if there is no image*/
    if (jQuery('.bigImage').find('img').length == 0)
        jQuery('.bigImage').hide();
    /*hide image div if there is no image*/

	/* opens declared items as such */
	jQuery('.menuClickerOpen').css({
		'color': '#81775D',
		'background-position': 'right -14px'
	});
	jQuery.each(jQuery('.subMenuWrapperOpen'), function() {
		jQuery(this).css({
			'height': jQuery(this).find('.subMenuContainer').height(),
			'padding-top': 10,
			'padding-bottom': 10
		});
	});

	/* menu mouseover (only not opened items) */
	jQuery('.menuClickerClose').hover(
		function() {
			menuClickerMouseEnter(jQuery(this));
		},
		function() {
			menuClickerMouseLeave(jQuery(this));
		}
	); //end menu mouseover
	
	/* submenu mouseover (only not opened items) */
	jQuery('.subMenuWrapperClose').hover(
		function() {
			menuClickerMouseEnter(jQuery(this).siblings('.menuClickerClose'));
		},
		function() {
			menuClickerMouseLeave(jQuery(this).siblings('.menuClickerClose'));
		}
	); //end submenu mouseover
	
	/* submenu mouseover */
	jQuery('.subMenuItem a').hover(
		function() {
			jQuery(this).parent('.subMenuItem').addClass('subMenuItemSelected');
		},
		function() {
			jQuery(this).parent('.subMenuItem').removeClass('subMenuItemSelected');
		}
	); //end submenu mouseover
	
	/* subscribe newsletter button mouseover */
	jQuery('.newsletterButton').hover(
		function() {
			jQuery(this).css('background-position', '0 -64px');
			jQuery(this).find('.newsletterButtonTextWrapper').css('color', '#3C3729');
		},
		function() {
			jQuery(this).css('background-position', '0 0');
			jQuery(this).find('.newsletterButtonTextWrapper').css('color', '#80775D');
		}
	); //end subscribe newsletter button mouseover
	
	/* quickaccess mouseover*/
	jQuery('.qsWrapper').hover(
		function() {
			jQuery(this).find('.qsLinksWrapper').css({
				'border': '2px solid #c9c9c9',
				'border-top': 'none'
			}).stop().animate({
				height: jQuery(this).find('.qsLinks').outerHeight(true)
			}, 0, 'swing');
		},
		function() {
			jQuery(this).find('.qsLinksWrapper').css({
				'border': 'none'
			}).stop().animate({
				height: 0
			}, 0, 'swing');
		}
	); //end quickaccess mouseover
	
	/* quickaccess links mousehover*/
	jQuery('.qsLinks a').hover(
		function() {
			jQuery(this).css('color', '#7F775D').parent('li').css('background-image', 'url("/style%20library/DPP.Images//system/backgrounds/qslinks.png")');
		},
		function() {
			jQuery(this).css('color', '#666666').parent('li').css('background-image', 'none');
		}
	); //end quickaccess links mouseover
	
	/* seach focus */
	jQuery('.searchInput').focus(function() {
		if(jQuery(this).val().toLowerCase() == 'pesquisa') {
			jQuery(this).val('');
		}
	}).blur(function() {
		if(jQuery(this).val().toLowerCase() == '') {
			jQuery(this).val('Pesquisa');
		}
	}).blur();
	
	SetupAccordion();
});


/* UTILITY FUNCTIONS */
function menuClickerMouseEnter(item) {
	var submenuWrapper = item.siblings('.subMenuWrapperClose'),
		submenu = jQuery(submenuWrapper).find('.subMenuContainer');
	item.css({
		'color': '#81775D',
		'background-position': 'right -14px'
	});
	submenuWrapper.stop().animate({
		'height': submenu.outerHeight(true),
		'padding-top': 10,
		'padding-bottom': 10
	}, 350);
}

function menuClickerMouseLeave(item) {
	var submenuWrapper = item.siblings('.subMenuWrapperClose'),
		submenu = jQuery(submenuWrapper).find('.subMenuContainer');
	item.css({
		'color': '#488E36',
		'background-position': 'right 0'
	});
	submenuWrapper.stop().animate({
		'height': 0,
		'padding-top': 0,
		'padding-bottom': 0
	}, 350);
}

function SetupAccordion() {
	var accordionItems = jQuery('.accordionItemWrapper');
	
	jQuery.each(accordionItems, function() {
		var	clicker = jQuery(this).find('.accorionClicker'),
			icon = clicker.find('.icon'),
			title = clicker.find('h2'),
			toggler = jQuery(this).find('.accordionToggler'),
			content = toggler.find('.accordionContent');
			
		clicker.hover(
			function() {
				clicker.css('background-image', 'url("/style%20library/DPP.Images//system/backgrounds/accordion.png")');
				title.css('font-weight', 'bold');
			},
			function() {
				clicker.css('background-image', 'none');
				title.css('font-weight', 'normal');
			}
		).data('status', 'close').click(function() {
			if(clicker.data('status') == 'close') {
				clicker.data('status', 'open');
				icon.css('background-position', '0 -15px');
				title.css('color', '#999999');
				toggler.stop().animate({
					height: content.outerHeight()
				}, 750, 'swing');
			} else {
				clicker.data('status', 'close');
				icon.css('background-position', '0 0');
				title.css('color', '#195E8D');
				toggler.stop().animate({
					height: 0
				}, 750, 'swing');
			}
		});
	});
}

function UpdateInnerWrapper() {
	try{
    jQuery(function () {
        jQuery.each(jQuery('.innerWrapper ul li').not(jQuery('.innerWrapper .accordionContent ul li, .mapcolumnborder ul li, .mapcolumn ul li')), function () {
            var html = jQuery(this).html();
            jQuery(this).css('font-weight', 'bold').html('<span style="font-weight: normal;">' + html + '</span>');
        });
    });
	}catch(e){}
}

