var flexSliderActive	= false;



jQuery(document).ready(function($) {

	$('.csc-menu.csc-menu-1').each(function(){
	 var childs = $(this).children().length;
	 if(childs == 0) {
	  $(this).remove();
	 } 
	
       })


        var firstHeader = $('#pageBodyColumnMiddle').find(".section-header:first");
         if(firstHeader){
          firstHeader.css("margin-top", 0);
         }
	var rootlineEl	= $("#t3Navigation-Rootline").find('#rootlineItem1');
	if(rootlineEl){
		if(!rootlineEl.length){
			var el	=  $("#t3Navigation-Rootline").find(".t3NavigationBody");
			el.wrap('<span id="rootlineItem1" />');
		}
	}
	$('.modalLink').each(function(){
		//$(this).click(function(){
			var url	= $(this).attr("href");
			$(this).colorbox({width:"80%", height:"80%", iframe:true});

	//	});


	});

	// news hook;
	var newsImageEl	= $('.news-image-selection');
	if(newsImageEl){
		var childEL		= newsImageEl.length;
		var imageWrapperEl		= newsImageEl.find('.news-single-img').length;
		if(childEL == 1 && !imageWrapperEl) {
			newsImageEl.find(".section-header").hide();
		}
	}
	
	var newsFileEl	= $('.news-single-files');
	if(newsFileEl) {
		newsFileEl.find('dt').wrap('<div class="section-header"><h3></h3></div>');
		var header	= newsFileEl.find('.section-header h3');
		var headerOrg	= newsFileEl.find('.section-header h3 dt');
		if(header && headerOrg ) {
			header.html(headerOrg.html());
		}
	}


	function pvSlide(parent){

		var headerEl	= parent.find(".t3FlexContent-SliderContent-Header");
		var contentEl	= parent.find(".t3FlexContent-SliderContentWrapper");


		contentEl.animate({
			 height: "toggle"
			 //opacity: "toggle" // this leads to the an error in IE 
			},{ 
			 duration: "slow",
			 specialEasing: {
			  width: 'linear'
			},
			complete: function() {}

		});

		return true;
	}

	$( ".t3FlexContent-SlideWrapper .t3FlexContent-SliderContent-Header").click( function(){
		var el	= $(this);
		var slideStatus	= false;
		var parent	= el.parent().parent();

		var headerEl	= parent.find(".t3FlexContent-SliderContent-Header");
		var contentEl	= parent.find(".t3FlexContent-SliderContentWrapper");
		contentEl.css("width","100%");

		if(contentEl && headerEl){

			pvSlide(parent);

			if(parent.hasClass('state0')){
				$("h3",parent).animate({
				'color' : globalFontColor},
				 500, function(){
					parent.removeClass("state0");
					parent.addClass("state1");
				 });
			} else {
				$("h3",parent).animate({
					'color' : '#6F6E6E'},
					 500, function(){
						parent.removeClass("state1");
						parent.addClass("state0");
				});
			}
		}

		return true;
		}
	);

	// ------------------------------------------
	// FORM: Default input text
	// ------------------------------------------

	$("input.defaultText").focus(function(src) {
		if ($(this).val() == $(this)[0].title) {
			$(this).removeClass("defaultTextActive");
			$(this).val("");
		}
	});

	$("input.defaultText").blur(function() {
		if ($(this).val() == "") {
			$(this).addClass("defaultTextActive");
			$(this).val($(this)[0].title);
		}
	});

	$("input.defaultText").blur();

	pv.init();

/*
	$(".t3ContentElement").each(function(){
		var el		= $(this);
		if(el){
			var elId	= el.children(".csc-default").attr("id");
			if(elId){
				el.find("a").each(function(){

					var linkEl	= $(this);
					if(!linkEl.hasClass("lightbox")){
						linkEl.attr("href", linkEl.attr("href")+'#'+elId);
					}
				});
			}
		}
	});
*/
	function getUrlVars() {
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split('#');
		for(var i = 0; i < hashes.length; i++) {
			// we have to filter the first element out of the array because it is the http:// url
			if(hashes[i].toString().search("http") != 0 ){
				hash = hashes[i].split('=');
				vars.push(hash[0]);
				vars[hash[0]] = hash[1];
			}
		}
		// return only the first element
		return vars[0];
	}

	var parameter	= getUrlVars();
	if(parameter){
		// get all Middle content from the slider Flex and set display:none status with the classes
		var contentEl	= $(".t3FlexContent-MiddleContenWrapper #"+parameter);


		var slideElement	= contentEl.parents('.t3FlexContent-MiddleContenWrapper');


		slideElement.removeClass("state0");
		slideElement.addClass("state1");

		slideElement.css("height","0");
		slideElement.css("height","auto");

	}
});


// function to open a slideelment in the middleConent
function openSlideElement(element){

	var element	= jQuery('.'+element);
	if(element != null){
		var parent	= element.parents('.t3FlexContent-MiddleContenWrapper');
		if(parent != null){
			if(parent.hasClass('state0') ){
				parent.removeClass('state0');
				parent.addClass('state1');
			}
		}

	}
}


function printPage() {
focus();
if (window.print) {
	window.print();
   }
}



pv	= {
	version: 1.0,

	init: function() {
		pv.page.init();
		pv.ajax.init();
		pv.form.init();
	}
}

pv.ajax = {
	init: function(url) {
	},
	post: function(url, params, callback, format) {

	if( !format || format == "" || format == "undefined" ) {
			format = "json";
		}

		jQuery.post(url,
			params,
			callback,
			format );

	}
}


pv.page = {
	init: function() {
	},

	go: function(url, event) {
		window.location = url;
		ibb.stopPropagation(event);
	}
}

pv.form = {
	init: function() {
		pv.form.selectorBox.init();
	}
};

pv.form.selectorBox = {
	timeoutList: {},

	init: function() {
		var timeoutTime		= 2000;
		var inputList		= jQuery("input.selectorBox");
		var selectorList	= jQuery(".selectorBoxSelector");

		if( inputList.length <= 0 ) {
			return;
		}

		inputList.focus(function(src) {
			var elId			= jQuery(this).attr("id");
			var selectorBoxId	= elId+"Selector";
			var elSelectorBox	= jQuery("#"+selectorBoxId);
			elSelectorBox.show();

			try {
				window.clearTimeout( pv.form.selectorBox[selectorBoxId] );
			} catch(e) {}
		});

		inputList.blur(function(src) {
			var elId			= jQuery(this).attr("id");
			var selectorBoxId	= elId+"Selector";
			var elSelectorBox	= jQuery("#"+selectorBoxId);

			var callback = function() {
				elSelectorBox.fadeOut();
			};

			try {
				window.clearTimeout( pv.form.selectorBox[selectorBoxId] );
			} catch(e) {}

			pv.form.selectorBox[selectorBoxId] = window.setTimeout( callback, timeoutTime );
		});

		selectorList.mouseover(function(src) {
			var selectorBoxId = jQuery(this).attr("id");

			try {
				window.clearTimeout( pv.form.selectorBox[selectorBoxId] );
			} catch(e) {}
		});

		selectorList.mouseout(function(src) {
			var selectorBoxId = jQuery(this).attr("id");
			var elSelectorBox	= jQuery(this);

			var callback = function() {
				elSelectorBox.fadeOut();
			};
			try {
				window.clearTimeout( pv.form.selectorBox[selectorBoxId] );
			} catch(e) {}

			pv.form.selectorBox[selectorBoxId] = window.setTimeout( callback, timeoutTime );
		});

	}


}



