var addthis_disable_flash = true;


jQuery.adjustcontentcontainer =	function (newcontentcontainerheight) {
	if(newcontentcontainerheight){
		//jQuery("#contentcontainer").height(newcontentcontainerheight);
		return;
	}
	
	windowheight = jQuery(window).height();
	
	headercontainerheight = 0;
	menucontainerheight = 0;
	breadcrumbcontainerheight = 0;
	contentcontainerheight = 0;
	footercontainerheight = 0;
	
	if(jQuery("#headercontainer").length > 0){
		headercontainerheight = jQuery("#headercontainer").height() + parseInt(jQuery("#headercontainer").css("margin-top")) + parseInt(jQuery("#headercontainer").css("margin-bottom")) + parseInt(jQuery("#headercontainer").css("padding-top")) + parseInt(jQuery("#headercontainer").css("padding-bottom"));
	}
	
	if(jQuery("#menucontainer").length > 0){
		menucontainerheight = jQuery("#menucontainer").height() + parseInt(jQuery("#menucontainer").css("margin-top")) + parseInt(jQuery("#menucontainer").css("margin-bottom")) + parseInt(jQuery("#menucontainer").css("padding-top")) + parseInt(jQuery("#menucontainer").css("padding-bottom"));
	}

	if(jQuery("#breadcrumbcontainer").length > 0){
		breadcrumbcontainerheight = jQuery("#breadcrumbcontainer").height() + parseInt(jQuery("#breadcrumbcontainer").css("margin-top")) + parseInt(jQuery("#breadcrumbcontainer").css("margin-bottom")) + parseInt(jQuery("#breadcrumbcontainer").css("padding-top")) + parseInt(jQuery("#breadcrumbcontainer").css("padding-bottom"));
	}

	if(jQuery("#contentcontainer").length > 0){
		contentcontainerheight = jQuery("#contentcontainer").children().height() + parseInt(jQuery("#contentcontainer").css("margin-top")) + parseInt(jQuery("#contentcontainer").css("margin-bottom")) + parseInt(jQuery("#contentcontainer").css("padding-top")) + parseInt(jQuery("#contentcontainer").css("padding-bottom"));
	}

	if(jQuery("#footercontainer").length > 0){
		footercontainerheight = jQuery("#footercontainer").height() + parseInt(jQuery("#footercontainer").css("margin-top")) + parseInt(jQuery("#footercontainer").css("margin-bottom")) + parseInt(jQuery("#footercontainer").css("padding-top")) + parseInt(jQuery("#footercontainer").css("padding-bottom"));
	}
	
	aggregatedheight = parseInt(headercontainerheight) + parseInt(menucontainerheight) + parseInt(breadcrumbcontainerheight) + parseInt(contentcontainerheight) + parseInt(footercontainerheight);
	
	if(aggregatedheight <= windowheight){		
		diff = (windowheight - aggregatedheight) + contentcontainerheight - (parseInt(jQuery("#contentcontainer").css("margin-top")) + parseInt(jQuery("#contentcontainer").css("margin-bottom")) + parseInt(jQuery("#contentcontainer").css("padding-top")) + parseInt(jQuery("#contentcontainer").css("padding-bottom")));
		//jQuery("#contentcontainer").height(diff);
	}
	
	
};

jQuery.callFancybox = function () {	
	jQuery(".geolocation").fancybox({
		'width' : 600,
		'height' : 400,
        'autoScale' : true,
        'scrolling' : 'no',
		'centerOnScroll': true,
		'hideOnOverlayClick' : false,
		'showNavArrows': false,
		'titleShow' : false,
		'type' : 'iframe',
		'onClosed': function(){parent.location.reload(true);}
	});
};


jQuery.topMenuSlideToggle = function () {	
	jQuery("#servicemenu > span > ul > li.topmenuitem-1st-level-ifsub").each(function(i){
		jQuery(this).children("a").click(function(){
			// Close allready opened menues
			jQuery(this).parent().siblings()
				.children("ul").slideUp("slow").end()
				.children("a").removeClass("menuOpen");

			if (jQuery(this).parent().children("ul").is(':hidden')) {
				jQuery(this).addClass("menuOpen");
			}
			else {
				jQuery(this).removeClass("menuOpen");
			}

			offset =  jQuery(this).offset();
			obj = jQuery(this).next("ul");
			obj.slideToggle("slow").css({"left":(offset.left - parseInt(obj.css("padding-left")))+"px", "top": (offset.top + jQuery(this).height())+"px"})
			return false;
		})

		jQuery(this).children("ul").mouseleave(function() {
			jQuery(this).slideUp("slow");
			jQuery(this).parent().children("a").removeClass("menuOpen");
		});
	});
};

jQuery.placeMenuTriangle = function () {
	var offset = 0;
	jQuery("#menucontainer .menu > li").each(function() {
		local_offset = parseInt(jQuery(this).children("a").width());
		position_x = parseInt(local_offset / 2) - 8 + offset;
		
		jQuery(this).find("ul > li:first > table > tbody > tr > td > div > div.dropdownmenu_arrow").css("background-position", position_x + "px 0");
		offset += local_offset;
	});
};

jQuery.splitTopMenuList = function() {
	
	jQuery("#menucontainer .menu li").each(function(i){
		
		attrClass = jQuery(this).find("ul > li > table div.dropdownmenu_bottom > div:first > ul").attr("class");
		var i = 0;
		do {
			var list = jQuery(this).find("ul > li > table div.dropdownmenu_bottom > div:first > ul:eq(" + i + ")");
			var items = list.find('.break ~li');
			list.find('.break').remove(); // remove the marker
			if(items.size()) {
				list.after(jQuery('<ul/>'));
				var newlist = list.nextAll('ul:first');
				newlist.append(items);
			}
			i++;
		} while (items.size() > 0)
		
		if(attrClass){
			jQuery(this).find("ul > li > table div.dropdownmenu_bottom > div:first > ul:last").attr("class", attrClass).addClass("dropdownmenuLastColomn");
		}
	});
};

jQuery.topMenuSlideToggle = function() {
	
	jQuery("#topfunctions > ul > li.topmenuitem-1st-level-ifsub").each(function(i){
		jQuery(this).children("a").click(function(){
			jQuery(this).parent().siblings().children("ul").slideUp("slow").end().children("a").removeClass("menuOpen");

			if (jQuery(this).parent().children("ul").is(':hidden')) {
				jQuery(this).addClass("menuOpen");
			}

			offset =  jQuery(this).offset();
			obj = jQuery(this).next("ul");
			obj.slideDown("slow").css({"left":(offset.left - parseInt(obj.css("padding-left")))+"px", "top": (offset.top + jQuery(this).height())+"px"})
			return false;
		})

		jQuery(this).children("ul").mouseleave(function() {
			jQuery(this).slideUp("slow");
			jQuery(this).parent().children("a").removeClass("menuOpen");
		});
	});
};


jQuery.splitBottomMenuList = function() {
	jQuery("#footercontainer #footer-footermenu ul li").each(function(index) {
		
		if(index % 10 == 0) {
			jQuery("#footercontainer #footer-footermenu > ul:last").after('<ul class="column"></ul>');
		}
		
		if(jQuery(this).parent().parent().is("#footer-footermenu")) {
			jQuery(this).addClass('a1st-level');
		}
		
		if(jQuery(this).find('ul').size() || index == 0){	
			jQuery(this).children('ul').remove();
		}
		
		jQuery('.column:last').append(this);
	});
	
	jQuery("#footercontainer #footer-footermenu > .column:last").css("margin-right","0");
	jQuery("#footercontainer #footer-footermenu > ul:first").remove();
};


jQuery(document).ready(function() {

	jQuery.placeMenuTriangle();
	jQuery.topMenuSlideToggle();
	jQuery.splitTopMenuList();
	jQuery.splitBottomMenuList();
	jQuery.topMenuSlideToggle();
	jQuery.callFancybox();
	
	
	jQuery.adjustcontentcontainer();
	
	jQuery(window).resize(function(){
		jQuery.adjustcontentcontainer();
	});
	
	jQuery(".csc-sitemap > ul > li > ul > li").each(function(){
		if(jQuery(this).children('ul').size()){
			jQuery(this).children('ul').hide();
			jQuery.adjustcontentcontainer();
			jQuery('<span class="sitemapright">&nbsp;&nbsp;&nbsp;</span>').toggle(
				function(){
				jQuery(this).addClass('sitemapdown');
				height = jQuery(this).parent().children('ul').height() + parseInt(jQuery(this).parent().children('ul').css("margin-top")) + parseInt(jQuery(this).parent().children('ul').css("margin-bottom")) + parseInt(jQuery(this).parent().children('ul').css("padding-top")) + parseInt(jQuery(this).parent().children('ul').css("padding-bottom"));
				jQuery(this).parent().children('ul').show();
				jQuery.adjustcontentcontainer(height);
				},
				function() {
				jQuery(this).removeClass('sitemapdown');
				height = jQuery(this).parent().children('ul').height() + parseInt(jQuery(this).parent().children('ul').css("margin-top")) + parseInt(jQuery(this).parent().children('ul').css("margin-bottom")) + parseInt(jQuery(this).parent().children('ul').css("padding-top")) + parseInt(jQuery(this).parent().children('ul').css("padding-bottom"));
				jQuery(this).parent().children('ul').hide();
				jQuery.adjustcontentcontainer();
				jQuery.adjustcontentcontainer(-height);
				}
			).insertAfter(jQuery(this).children('a'));
		}
	});
	
	jQuery("#graphicMenu ul.dropdownMenuContainer li.triggeropacity")
});

//Cufon.replace('#menucontainer .dropdownMenuContainer .dropdownmenu_bottom_left a');
