$(document).ready(function () {
	var COOKIE_NAME = 'idsn_cookie';
	$(".div-top-img-large, .div-top-img-small-line1, .div-top-img-small-line2").hover(
		function () {
			var slide = $(this).find("div");
			slide.removeAttr("style");
			if(slide.is(':animated')){
				slide.stop().slideDown("fast");
			}else{
				slide.slideDown("fast");
			}
		}, 
		function () {
			var slide = $(this).find("div");
			if(slide.is(':animated')){
				slide.stop().slideUp("fast");
			}else{
				slide.slideUp("fast");
			}
		}
	);
	
	/* ##### Menu ##### */
	$.each($('#div-menu ul li'), function(i, val){
		var link = $(this).find("a").attr("href");
		var src = $(this).find("img").attr("src").replace("/normal/","/over/").replace("/active/","/over/");
		$(this).append('<div><a href="'+link+'"><img src="'+src+'" alt=""></a></div>');
	})
	
	
	$('#div-menu ul li').hover(
		function(){
			var fade = $(this).find("div");
			fade.removeAttr("style");
			if(fade.is(':animated')){
				fade.stop().fadeTo("fast", 1);
			}else{
				fade.fadeIn("fast");
			}
			
		},function(){
			var fade = $(this).find("div");
			if(fade.is(':animated')){
				fade.stop().fadeTo("fast", 0);
			}else{
				fade.fadeOut("fast");
			}
		}
	);
	/* ##### Take action ##### */
	
	
	/*
	$('.div-take-action-rows a').click(function(){
		if($(this).parent().hasClass("div-take-action-open") || $(this).parent().hasClass("div-take-action-closed")){
			return true;
		}
		var row = $(this).parent().attr("id");
		if($(".div-take-action-open").length > 0){
			if($(".div-take-action-open").is(":animated")){
				$(".div-take-action-open").stop().slideUp("fast",function(){
					$(this).attr("class","div-take-action-closed");
					if($(this).attr("id") != row+"-links"){
						$.cookie(COOKIE_NAME, row, { path: '/', expires: 1 });
						$("#"+row+"-links").attr("style", "display: none;");
						$("#"+row+"-links").attr("class","div-take-action-open");
						$("#"+row+"-links").slideDown("fast");
					}else{
						$.cookie(COOKIE_NAME, null, { path: '/' });
					}
				});
			}else{
				$(".div-take-action-open").slideUp("fast",function(){
					$(this).attr("class","div-take-action-closed");
					if($(this).attr("id") != row+"-links"){
						$.cookie(COOKIE_NAME, row, { path: '/', expires: 1 });
						$("#"+row+"-links").attr("style", "display: none;");
						$("#"+row+"-links").attr("class","div-take-action-open");
						$("#"+row+"-links").slideDown("fast");
					}else{
						$.cookie(COOKIE_NAME, null, { path: '/' });
					}
				});
			}
		}else{
			$.cookie(COOKIE_NAME, row, { path: '/', expires: 1 });
			$("#"+row+"-links").attr("style", "display: none;");
			$("#"+row+"-links").attr("class","div-take-action-open");
			$("#"+row+"-links").slideDown("fast");
		}
		return false;
	});
	if($.cookie(COOKIE_NAME)){
		$("#"+$.cookie(COOKIE_NAME)+"-links").attr("class","div-take-action-open");
	}
	if($.cookie(COOKIE_NAME)){
		$("#"+$.cookie(COOKIE_NAME)+"-links").attr("class","div-take-action-open");
	}
	
	*/
	
	/* ##### Search ##### */
	$('.div-search-field-inner input').focus(function () {	
		if($(this).val() == "Search"){
			$(this).val("");
		}
	});
	$('.div-search-field-inner input').blur(function () {
		if($(this).val() == ""){
			$(this).val("Search");
		}
	});
	/* ##### Galleri ##### */
	$(".tx-chgallery-pi1 .single .img .align img").attr("alt","").attr("title","");
	$(".tx-chgallery-pi1 .single .img .align a").attr("title","");
	$(".tx-chgallery-pi1 div.description, .tx-chgallery-pi1 div.div-top-img-yellow").click(function(){
		$(this).parent().find("a").click();
	});
	var hovertextcontainer = "";
	$(".tx-chgallery-pi1 .single .img").hover(
		function () {
			var slide = $(this).find("div.div-top-img-yellow");
			slide.removeAttr("style");
			if(slide.is(':animated')){
				slide.stop().slideDown("fast");
			}else{
				slide.slideDown("fast");
			}
			var desc = $(this).find("div.description");
			if(desc.find("span").html() != "" && desc.find("span").html() != " " && desc.find("span").html() != "&nbsp;"){
				desc.removeAttr("style");
				if(desc.is(':animated')){
					desc.stop().fadeTo("fast", 0.70);
				}else{
					desc.fadeTo("fast", 0.70);
				}
			}
		}, 
		function () {
			var slide = $(this).find("div.div-top-img-yellow");
			if(slide.is(':animated')){
				slide.stop().slideUp("fast");
			}else{
				slide.slideUp("fast");
			}
			var desc = $(this).find("div.description");
			if(desc.find("span").html() != "" && desc.find("span").html() != " " && desc.find("span").html() != "&nbsp;"){
				if(desc.is(':animated')){
					desc.stop().fadeTo("fast", 0);
				}else{
					desc.fadeOut("fast");
				}
			}
		}
	);
	$(".tx-chgallery-pi1 .single .img a").click(function(){
		//$(this).attr("title", $(this).parent().find("div.discription span").html());
		$(this).attr("title", "dededed");
		return false;
	});
	/*
	$("tr.tx-danewslettersubscription-pi1-listrow-header").hover(
		function(){
			$(this).find("td").css("background-color", "#e7e4de");
		},function(){
			$(this).find("td").css("background-color", "#F0EEE9");
		}
	);
	$("tr.tx-danewslettersubscription-pi1-listrow-header").toggle(
		function(){
			if($(this).find("input:checkbox")){
				if($(this).find("input:checked")){
					$(this).find("input:checkbox").removeAttr("checked");
				}else{
					$(this).find("input:checkbox").attr("checked","checked");
				}
			}
		}
	);
	*/
	/* ##### Hoverboxes ##### */
	$('.news-list-item').hover(
		function(){
			$(this).css("background-color", "#fdfdfd");
		},function(){
			$(this).css("background-color", "transparent");
		}
	);
	$('.news-list-item').click(function(){
		document.location = js_safe_link($(this).find("a").attr("href"));
	});
	$('.div-latestnews-row').hover(
		function(){
			$(this).css("background-color", "#fdfdfd");
		},function(){
			$(this).css("background-color", "transparent");
		}
	);
	$('.div-latestnews-row').click(function(){
		document.location = js_safe_link($(this).find("a").attr("href"));
	});
	$('.div-dalitrow').hover(
		function(){
			$(this).css("background-color", "#f9f9f9");
		},function(){
			$(this).css("background-color", "transparent");
		}
	);
	$('.div-dalitrow').click(function(){
		document.location = js_safe_link($(this).find("a").attr("href"));
	});
	$('.div-teaserbox').hover(
		function(){
			$(this).css("background-color", "#f1f1f1");
		},function(){
			$(this).css("background-color", "transparent");
		}
	);
	$('.div-teaserbox').click(function(){
		document.location = js_safe_link($(this).find("a").attr("href"));
	});
	$('.div-featurebox div').hover(
		function(){
			$(this).parent().find("div[class!='div-featurebox-img'][class!='div-featurebox-img-ro']").stop().fadeTo("fast", 1);
			$(this).parent().find("div.div-featurebox-img-ro").stop().fadeTo("fast",1);
			
		},function(){
			$(this).parent().find("div[class!='div-featurebox-img'][class!='div-featurebox-img-ro']").stop().fadeTo("fast", 0.66);
			$(this).parent().find("div.div-featurebox-img-ro").stop().fadeTo("fast",0);
		}
	);
	$('.div-featurebox div').click(function(){
		document.location = js_safe_link($(this).find("a").attr("href"));
	});
	$('.div-search-row').hover(
		function(){
			$(this).css("background-color", "#fdfdfd");
		},function(){
			$(this).css("background-color", "transparent");
		}
	);
	$('.div-search-row').click(function(){
		document.location = js_safe_link($(this).find("a").attr("href"));
	});
});
function js_safe_link(link){
	if(link.indexOf("http://") == 0){
		return link;
	}else{
		return "/"+link;
	}
}