// JavaScript Document
$(document).ready(function(){

$('a','#termin_cbox').click(function(evt){
	evt.preventDefault();
	var workshop_prefix = $(this).attr('lang');
	
	workshop_info(workshop_prefix);
	return false;
	});



function ideal_text(max_height, text_element){	
	var elem = text_element;
	var elem_parent = elem.closest("div");
	var elem_parent_height = elem_parent.height();
	
	$.each(elem, function(){
		
		if($(this).height() > max_height){
			$(this).height(max_height);
			$(this).css({
				overflow: "hidden"
				});
			
			$(elem_parent).height(elem_parent_height);
			
			$(this).bind("mouseover mouseout", function(evt){
				if(evt.type == "mouseover"){
				$(this).find(".text_open").css({display: "block"});
				}
				
				if(evt.type == "mouseout"){
				$(this).find(".text_open").css({display: "none"});
				}
				
			});
			/*
			$(this).toggle(
							function(){$(this).css("height","auto");},
							function(){$(this).height(max_height);}
						);
			*/
			
			$(this).click(function(){
				switch($(this).attr("class")){
					case "open": {
									$(this).removeClass("open");
									$(this).height(max_height);
									break;
								 }
					default: {
								$(this).addClass("open");
								$(this).css("height","auto");
								break;
							 }
					}
				
			});
			
							
		}
		
	});
	
}

	
var max_newstext_height = 118;
var news_text_elements = $("li","#news_cbox");

ideal_text(max_newstext_height, news_text_elements);

function first_entrie(){
	$(news_text_elements).first().css("height","auto").addClass("open");
	}
first_entrie();	
	
//Preview News Images

$("img",".news_images").each(function(){
		
			$(this).bind("mouseover mouseout", function(evt){
				if(evt.type == "mouseover"){
					if($(this).closest("li").attr("class") != "open"){
						$(this).parent("a").unbind("click");
						$(this).parent("a").click(function(event){event.preventDefault();});
						$(this).closest("div").find(".zoom_overlay").hide(); //################
						
					}
					if($(this).closest("li").attr("class") == "open"){
						//$(this).parent("a").trigger("click");
						$(this).closest("li").unbind("click");
						$(this).closest("div").find(".zoom_overlay").show();//#################
						$(this).parent("a").colorbox({transition: "elastic", height: "auto", arrowKey: false});
					}
				}
				if(evt.type == "mouseout"){
					if($(this).closest("li").attr("class") == "open"){
						$(this).closest("div").find(".zoom_overlay").hide();//###############
						
						$(this).closest("li").bind("mouseover mouseout", function(evt){
							if(evt.type == "mouseover"){
							$(this).find(".text_open").css({display: "block"});
							}
							
							if(evt.type == "mouseout"){
							$(this).find(".text_open").css({display: "none"});
							}
							
						});
						
						$(this).closest("li").click(function(){
							switch($(this).attr("class")){
								case "open": {  
												$(this).removeClass("open");
												$(this).height(max_newstext_height);
												break;
											 }
								default: {	
											$(this).addClass("open");
											$(this).height("auto");
											break;
										 }
							}
						});
					}
				}
			});
		
});	
		
	
});
