$(document).ready(function(){

	if($.browser.msie && $.browser.version=="6.0") {
		var blnIE6 = true;
	}

	$('a[rel=lightbox]').lightBox();



//	$("#all_def").hide();
//	$("#showLink").show();

//	$("#toggleDiv").click(function () {
//		$(".showHideLink").toggle();
//		if ($("#all_def").is(":hidden")) {
//			$("#all_def").slideDown("normal");
//		} else {
//			$("#all_def").slideUp("normal");
//		}
//	});


	$("ul.sf-menu").superfish();

	$("#languageSelect").change(function(){
		window.location.href = this.value;
	});

	// fix height for tabs
	$(".tabContent").each(function(){
		$correctHeight = $(this).height();
//		$(this).height($correctHeight);
	});


	if($.browser.msie) {
		$(".tabsBox").tabs({fx: {}, selected: 0 });
	}else{
		$(".tabsBox").tabs({ fx: { opacity: 'toggle', height: 'toggle'}, selected: 0 });
	}


//	var realColumnHeigt = $('.columns').height();
    // only if browser is not IE6
    if(!blnIE6) {
//	    $('.columnize').columnize({
//			columns: 2
//
//			,lastNeverTallest : false
//		})
//
//			//fix columnheigt
//
//		$('.columns').height(realColumnHeigt*1.2);

		$('.newsBody').width(300);
		$('.newsItemBox a').width(300);

    } //end !IE6

	// sets select state on the selected nodes in the menu
	$('ul.MenuLevel0 a').each(function(index, objHref){
		if($(objHref).attr('href') == document.location){
			$(objHref).addClass('selected');
			$(objHref).removeClass('normal');
			objParent = $(objHref).parent();

			while(true){
				tagName = $(objParent).attr('tagName');
				if(tagName == 'LI'){
					$(objParent).addClass('selected');
					$(objParent).addClass('active');
					$(objParent).removeClass('normal');
				}
				objParent = $(objParent).parent();
				if(tagName != 'LI' && tagName != 'UL')
					break;
			}
		}
	});



	/**
	 *  DIALOG
	 */
	$("body").append('<div id="videoDialog" ><div id="custom_dialog_close">&nbsp;</div></div>');

	// dialog config
	$("#videoDialog").dialog({
		autoOpen: false
		,modal: true
		,closeText:''

		,width: 620
		,height: 512
		,title: 'Titel'
	});

	// on click on dialog trigger, open dialog
	$(".videoTrigger").each(function() {
        $(this).click(function() {
			$("#videoDialog").data('videoUrl',  $(this).attr('href'));
			$("#videoDialog").data('videoSplash',  $(this).attr('splash'));
			$("#videoDialog").data('videoTitle',  $(this).attr('title'));
            $("#videoDialog").dialog("open");
			return false;
        })
	});
    //closebutton mouseover class
	$("#custom_dialog_close").mouseover(function(){	$(this).addClass('custom_hover');		});
	$("#custom_dialog_close").mouseout(function(){	$(this).removeClass('custom_hover');	});

	//close dialog on closebutton
	$("#custom_dialog_close").live("click", function() {
		$("#playerContainer" ).remove();
		$("#videoDialog").dialog("close");
    });

	// on click outside dialog, close dialog
	$(".ui-widget-overlay").live("click", function() {
		$("#playerContainer" ).remove();
		$("#videoDialog").dialog("close");
	});

	// BIND FINISH OPEN TO SWF PLACMENT
	$( "#videoDialog" ).bind( "dialogopen", function(event, ui) {
		var strVideoSrc = $("#videoDialog").data('videoUrl');
		var strSplashSrc = $("#videoDialog").data('videoSplash');
		var strVideoTitle = $("#videoDialog").data('videoTitle');
		//replace title
		$( "#ui-dialog-title-videoDialog" ).html(strVideoTitle);

		// APPEND DIV TO CONTAINER
		$( "#videoDialog" ).append('<div id="playerContainer" style="margin-left: 0px;"></div>');
		var flashvars = {};
//		var so = new SWFObject(wwwRoot+"swf/player4.swf", "test", "480", "380", "8", "#FFFFFF");
		var so = new SWFObject(wwwRoot+"swf/player4.swf", "test", "620", "485", "8", "#FFFFFF");
//		so.addParam("wmode", "opaque");
		so.addParam("allowFullScreen", "true");
		so.addVariable("run_mode", "live");
		so.addParam('flashvars','file='+strVideoSrc+'&image='+strSplashSrc+'&autostart=true');
//		so.addVariable('autostart','true');
		so.addVariable("title", strVideoTitle);
		so.write("playerContainer");


	});


	/*
	*	refresh images with class="autoRefresh", for use with webcam generated images
	*/
	var refreshRate = 5000 // refresh rate (ms)
	var imgRefresh = $('img.autoRefresh');
	// do this for every img with class="autoRefresh"
	$.each(imgRefresh, function() {
		// set current img src
		var currentSrc = this.src;
		// put current (random) image in variable
		var thisImg = $(this);
		// do refresh
		var refreshId = setInterval(function() {
			// add random string to img to prevent caching
			var newSrc = currentSrc.replace(/\?.*$/, '') + '?' + Math.random();
			// chenge current image src
	     	$(thisImg).attr('src',newSrc);
		}, refreshRate);

	});


	/**
	* DIALOG
	*/
	// dialog config
	$("#tellAFriendDialog").dialog({
		autoOpen: false
		,modal: true
		,closeText:''

		,width: 400
		,height: 600
	});


	// on click on dialog trigger, open dialog
	$(".triggerTellAFriendDialog").each(function() {
		$(this).click(function() {
			$("#tellAFriendDialog").dialog("open");
			 $currentPage = window.location.pathname;
			return false;
		})
	});

	$(".tellAFriendDialogAutoOpen").each(function() {
		$("#tellAFriendDialog").dialog("open");
	});

	// on click outside dialog, close dialog
	$(".ui-widget-overlay").live("click", function() {
		$("#tellAFriendDialog").dialog("close");
	});

	$("#custom_dialog_close").live("click", function() {
//		$("#tellAFriendDialog" ).remove();
		$("#tellAFriendDialog").dialog("close");
/*
		console.log('to '+ $currentPage);
		window.location.href =  $currentPage;
*/
    });


    /*success*/
    $("#shareSuccessDialog").dialog({
		autoOpen: false
		,modal: true
		,closeText:''

		,width: 400
		,height: 200
	});

    $(".shareSuccessDialogAutoOpen").each(function() {
		$("#shareSuccessDialog").dialog("open");
	});

		// on click outside dialog, close dialog
	$(".ui-widget-overlay").live("click", function() {
		$("#shareSuccessDialog").dialog("close");
	});

	$("#custom_dialog_close").live("click", function() {
//		$("#tellAFriendDialog" ).remove();
		$("#shareSuccessDialog").dialog("close");
/*
		console.log('to '+ $currentPage);
		window.location.href =  $currentPage;
*/
    });





});


