$(document).ready(function() {
	$('#flash_header').flash( {
		src : 'templates/default/swf/header.swf',
		width : 480,
		height : 200,
		wmode : 'transparent',
		id : 'headerflash',		
		flashvars : {
			topic : $('#topic').attr("value")
		}
	},{version: '9'});
	$('#flash_header_video').flash( {
		src : 'templates/default/swf/player.swf',
		width : 480,
		height : 200,
		wmode : 'transparent'
	});
	$('#navi a').click(function(event) {
		event.preventDefault();
		//unFocus.History.addHistory($(this).attr("id")+".html");
		ajax_main($(this));
	});	
	$('#home').click(function(event) {
		event.preventDefault();
		//unFocus.History.addHistory($(this).attr("id")+".html");
		$.ajax( {
			url: "index"+(LANGUAGE=='english'?'_en':'')+".html?ajax=1",
			success: function(data) {
				$('#content').html(data);
				$('#subnavi_holder').empty();
				refresh_content();
				$('#navi a').unbind();
				$('#navi a').click(function(event) {
					event.preventDefault();
					ajax_main($(this));
				});	
				$('#navi').children().removeClass('active');
				
				document.getElementById('headerflash').setTopic($('#topic').attr("value"));
			}
		});
	});
	$('#subnavi .ajax').click(function(event) {
		event.preventDefault();
		//unFocus.History.addHistory($(this).attr("id")+".html");
		click_sub($(this).attr("id"));
		$.ajax( {
			url : $(this).attr("href") + "?ajax=1",
			context : document.body,
			success : function(data) {
				$('#content').html(data);
				refresh_content();
				document.getElementById('headerflash').setTopic($('#topic').attr("value"));
			}
		});
	});	
	refresh_content();
});

function gotoImageVideo() {
	click_main("unternehmensgruppe");
	$.ajax( {
		url : BASEURL + "image_video.html?ajax=1",
		success : function(data) {
			$('#content').html(data);
			refresh_content();
			document.getElementById('headerflash').setTopic($('#topic').attr("value"));
		}
	});
	$.ajax( {
		url : BASEURL + "unternehmensgruppe.html?ajax=2",
		context : document.body,
		success : function(data) {
			$('#subnavi_holder').html(data);
			$('#subnavi_holder .ajax').first().addClass('active');
			$('#subnavi .ajax').click(function(event) {
				event.preventDefault();
				//unFocus.History.addHistory($(this).attr("id")+".html");
				click_sub($(this).attr("id"));
				$.ajax( {
					url : $(this).attr("href") + "?ajax=1",
					context : document.body,
					success : function(data) {
						$('#content').html(data);
						refresh_content();
						document.getElementById('headerflash').setTopic($('#topic').attr("value"));
					}
				});
			});
			click_sub("image_video");
		}
	});
}

function refresh_content() {
	if(typeof admin_refresh == 'function') {
		$('#editor').hide(500);
		admin_refresh();
	}
	$('#imagevideo').flash( {
		src : 'templates/default/swf/player_600x338.swf',
		width : 600,
		height : 338,
		wmode : 'transparent',		
		allowfullscreen: true
	});
	$('#videobox').flash( {
		src : 'templates/default/swf/player_280x160.swf',
		width : 280,
		height : 160,
		wmode : 'transparent'
	});
	$('#tagcloud').flash( {
		src : 'templates/default/swf/tagcloud.swf',
		wmode : 'transparent',
		width : 280
	});
	$('.news_archive_item_link').unbind();
	$('.news_archive_item_link').click(function(event) {
		event.preventDefault();
		//$('#single_news').hide("slow");
		$.ajax( {
			url : $(this).attr("href") + "&ajax=2",
			context : document.body,
			success : function(data) {
			$('#single_news').html(data);
			
			var reiter;
			if(LANGUAGE=='english') {
				if($('input[name="is_news"]').val()==1) {
					reiter= '<img src="'+BASEURL+'templates/default/img/reiter_presse_aktiv_en.png" alt="Press releases " /><a class="reiter" id="reporting" href="reporting.html"><img src="'+BASEURL+'templates/default/img/reiter_bericht_passiv.png" alt="reporting" /></a>';	
				} else {
					reiter= '<a class="reiter" id="press_releases" href="press_releases.html"><img src="'+BASEURL+'templates/default/img/reiter_presse_passiv_en.png" alt="Press releases " /></a><img src="'+BASEURL+'templates/default/img/reiter_bericht_aktiv_en.png" alt="reporting" />';
				}
			} else {
				if($('input[name="is_news"]').val()==1) {
					reiter= '<img src="'+BASEURL+'templates/default/img/reiter_presse_aktiv.png" alt="Pressemitteilungen " /><a class="reiter" id="berichterstattung" href="berichterstattung.html"><img src="'+BASEURL+'templates/default/img/reiter_bericht_passiv.png" alt="Berichterstattung" /></a>';	
				} else {
					reiter= '<a class="reiter" id="pressemitteilungen" href="pressemitteilungen.html"><img src="'+BASEURL+'templates/default/img/reiter_presse_passiv.png" alt="Pressemitteilungen " /></a><img src="'+BASEURL+'templates/default/img/reiter_bericht_aktiv.png" alt="Berichterstattung" />';
				}
			}
			$('#reiter').html(reiter);
		//	click_sub($('input[name="is_news"]').val()==1?'pressemitteilung':'berichterstattung'));
//			$('.zoom').click(function(event) {
//				zoom($(this));
//			});
			//	$('#single_news').show("slow");
		}
		});
	});
	$('.standort_href').unbind();
	$('.standort_href').click(function(event) {
		event.preventDefault();
		$.ajax( {
			url : $(this).attr("href") + "&ajax=2",
			context : document.body,
			success : function(data) {
			$('#kuhlhaus_details').html(data);
			//	$('#single_news').show("slow");
		}
		});
	});
//	$('.w600').click(function(event) {
//	event.preventDefault();
//		zoom($(this).children("a"));
//	});
	$('#standorte').css("display","none");
	$('#flash_karte').flash( {
		src : 'templates/default/swf/standorte.swf',
		width : 910,
		height : 1000,
		wmode : 'transparent',
		id : 'standortflash',
		flashvars : {
			url : BASEURL,
			lang : LANGUAGE
		}
	});
	$('#showmap').click(function(event) {
		event.preventDefault();
		showFlashMap();
	});
	$('#kuehllink').click(function(event) {
		event.preventDefault();
		//unFocus.History.addHistory($(this).attr("id")+".html");
		click_sub("kuehlhausstandorte");
		$.ajax( {
			url : $(this).attr("href") + "?ajax=1",
			context : document.body,
			success : function(data) {
				$('#content').html(data);
				refresh_content();
				document.getElementById('headerflash').setTopic($('#topic').attr("value"));
			}
		});
	});
	$('.reiter').click(function(event) {
		event.preventDefault();
		//unFocus.History.addHistory($(this).attr("id")+".html");
		click_sub($(this).attr("id"));
		$.ajax( {
			url : $(this).attr("href") + "?ajax=1",
			context : document.body,
			success : function(data) {
				$('#content').html(data);
				refresh_content();
			}
		});
	});
	$('.page').click(function(event) {
		event.preventDefault();
		//unFocus.History.addHistory($(this).attr("id")+".html");
		$.ajax( {
			url : $(this).attr("href") + "&ajax=1",
			context : document.body,
			success : function(data) {
				$('#content').html(data);
				refresh_content();
			}
		});
	});
}

function zoom(elem) {
	//alert(elem.attr("id"));
	$('#content_padding').fadeOut(300);
	//$('#content_padding').hide("fast");
	$('#content').append('<div id="zoomed" style="display:none"><a href="#"><img src="templates/default/img/close.png" alt"Bild schlie&szlig;en" /></a><br /><img src="uploads/img/zoom_'+elem.attr("id")+'" /></div><div class="clear" id="zoomed_clear">&nbsp;</div>');
	$('#zoomed').click(function(event) {
		event.preventDefault();
		unzoom();
	});
	setTimeout("$('#zoomed').fadeIn(300)",300);
}

function unzoom() {
	$('#zoomed').fadeOut(300);
	$('#zoomed').remove();
	$('#zoomed_clear').remove();
	$('#content_padding').fadeIn(300);
}

function tag(tag) {
	alert(tag);
}

function ajax_main(link) {
	click_main(link.attr("id"));
	$.ajax( {
		url : link.attr("href") + "?ajax=1",
		success : function(data) {
			$('#content').html(data);
			refresh_content();
			document.getElementById('headerflash').setTopic($('#topic').attr("value"));
		}
	});
	$.ajax( {
		url : link.attr("href") +(link.attr("id")=='home'?'index.html':'')+ "?ajax=2",
		context : document.body,
		success : function(data) {
			$('#subnavi_holder').html(data);
			$('#subnavi_holder .ajax').first().addClass('active');
			$('#subnavi .ajax').click(function(event) {
				event.preventDefault();
				//unFocus.History.addHistory($(this).attr("id")+".html");
				click_sub($(this).attr("id"));
				$.ajax( {
					url : $(this).attr("href") + "?ajax=1",
					context : document.body,
					success : function(data) {
						$('#content').html(data);
						refresh_content();
						document.getElementById('headerflash').setTopic($('#topic').attr("value"));
					}
				});
			});
		}
	});
}
function click_sub(filename) {
	$('#subnavi').children().removeClass('active');
	$('#' + filename).addClass('active');
}

function click_main(filename) {
	$('#navi').children().removeClass('active');
	$('#' + filename).addClass('active');
}

function showList() {
	$('#flash_karte').css("display","none");
	$('#standorte').fadeIn(500);
}

function showFlashMap() {
	$('#standorte').fadeOut(500);
	//setTimeout("$('#flash_karte').css('display','block')",500);
	setTimeout("$('#flash_karte').fadeIn(1000)",500);
	//$('#standorte').css("display","none");
	//document.getElementById("standortflash").showMap();	
}
