var heightArray;

function jsOverlayVideoPlayer(path){
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
    document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"');
    document.write(' id="overlayVideoPlayer" width="643" height="385">');
    document.write(' <param name="movie" value="'+ path +'" />');
    document.write(' <param name="quality" value="high" />');
    document.write(' <param name="allowFullScreen" value="true" /> ');
    document.write(' <param name="menu" value="false" />');
    document.write(' <param name="bgcolor" value="#ffffff" />');
    document.write(' <param name="wmode" value="transparent" />');
    document.write(' <param name="allowScriptAccess" value="always" />');
    document.write(' <embed width="643" height="385" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" bgcolor="#ffffff" allowfullscreen="true" menu="false" quality="high" swLiveConnect="true" wmode="transparent" name="overlayVideoPlayer" allowscriptaccess="always" src="'+ path +'" />');
    document.write('</object>');
}

function getFlashMovie(movieName){
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  return (isIE) ? window[movieName] : document[movieName];
}

function flashClose(){
  $("#dialogVideoPlayer").jqmHide();
}

$().ready(function() {
  //videoOverlay
  var closeOverlayVideoPlayer=function(hash){
    getFlashMovie("overlayVideoPlayer").stopFlash();
    hash.w.css("z-index",-100);
    hash.o.remove();
  };
  var openOverlayVideoPlayer=function(hash){
  	hash.w.css("z-index",1000000);
    hash.w.show();
  };
  $("#dialogVideoPlayer").jqm({overlay:80,overlayClass:'jqmOverlayVideoPlayer',onShow:openOverlayVideoPlayer,onHide:closeOverlayVideoPlayer});
  $("a.playOverlayVideoPlayer").bind("click", function(e){
  	var path = $(this).attr("rel");
  	$("#dialogVideoPlayer").jqmShow();
 		getFlashMovie("overlayVideoPlayer").startFlash(path);
  });
  
  
  	
	// switchBox
	$(".switchBoxItem .headline").bind("click", function(){
		$(".switchBox .switchBoxItem .headline").removeClass("colorRed");
	  $("#" + this.id).addClass("colorRed");
		$(".switchBox .switchBoxItem .headline").css("cursor","pointer");
		$("#" + this.id).css("cursor","auto");
		$(".switchIcon").empty();
	  $(".switchIcon").append("<img src='http://www.bosch-stiftung.de/content/language1/shared/iconPlus.gif' width='10' height='10' border='0' alt=''/>");
	  $("#" + this.id + " .switchIcon").empty();
	  $("#" + this.id + " .switchIcon").append("<img src='http://www.bosch-stiftung.de/content/language1/shared/iconRed.gif' width='10' height='10' border='0' alt=''/>");
	  $(this).next("div.text").css({height: heightArray[$(".switchBoxItem .headline").index(this)]});
		$(".switchBoxItem .text:not(#" + this.id + " + .text)").slideUp("slow");
		$("#" + this.id + " + .text").slideDown("slow");
	});
});


/* #### boxHeadlineToLink #### */
function boxHeadlineToLink(inId){
	if ($("#" + inId + " .link:fist a").attr("href")!=undefined){
		if ($("#" + inId + " .link:fist a").attr("rel")!=""){
  		$("#" + inId + " .headline h2").wrapInner("<a  class='playOverlayVideoPlayer' href='"+$("#" + inId + " .link:fist a").attr("href")+"' rel='"+$("#" + inId + " .link:fist a").attr("rel")+"'></a>");
  	}else{
  		$("#" + inId + " .headline h2").wrapInner("<a href='"+$("#" + inId + " .link:fist a").attr("href")+"'></a>");
  	}
  }
}


/* #### switchBox #### */
function switchBox(inId,firstShow){
	heightArray = new Array();
	$(".switchBoxItem .text").each(function(i) { 
	theHeight = $(this).height();
		heightArray[i] = theHeight;
	});
	$("#switchBox" + inId +  " .text").hide();
	$("#switchBox" + inId +  " .headline").css("cursor","pointer");
	$("#switchBox" + inId +  " .switchIcon").empty();
  $("#switchBox" + inId +  " .switchIcon").append("<img src='http://www.bosch-stiftung.de/content/language1/shared/iconPlus.gif' width='10' height='10' border='0' alt=''/>");
if (firstShow){
	$("#switchBox" + inId +  " .text:first").show();
	$("#switchBox" + inId +  " .headline:first").addClass("colorRed");
	$("#switchBox" + inId +  " .headline:first").css("cursor","auto");
  $("#switchBox" + inId +  " .switchIcon:first").empty();
  $("#switchBox" + inId +  " .switchIcon:first").append("<img src='http://www.bosch-stiftung.de/content/language1/shared/iconRed.gif' width='10' height='10' border='0' alt=''/>");
}
}


/* #### slideBox #### */
function slideBoxHideContent(inId){
  $("#slideBoxHide" + inId).addClass("displayNone");
  $("#slideIconPlus" + inId).append("... <a href='#' onclick='slideBoxShowContent(\""+inId+"\");return false'><img src='http://www.bosch-stiftung.de/content/language1/shared/iconPlus.gif' width='10' height='10' border='0' alt=''/></a>");
}
function slideBoxShowContent(inId){
	$("#slideBoxHide" + inId).toggleClass("displayNone");
  if($("#slideBoxHide" + inId).is(":visible")){
		$("#slideIconPlus" + inId).empty();
	  $("#slideIconMinus" + inId).append("<a href='#' onclick='slideBoxShowContent(\""+inId+"\");return false'><img src='http://www.bosch-stiftung.de/content/language1/shared/iconMinus.gif' width='10' height='10' border='0' alt=''/></a>");
  }
  else{
		$("#slideIconMinus" + inId).empty();
	  $("#slideIconPlus" + inId).append("... <a href='#' onclick='slideBoxShowContent(\""+inId+"\");return false'><img src='http://www.bosch-stiftung.de/content/language1/shared/iconPlus.gif' width='10' height='10' border='0' alt=''/></a>");
  }
}

function slide(id){
	$(id).slideBox();
}

$.fn.slideBox = function(option){
	var settings = jQuery.extend({
		boxItem: ".slideBoxItem",
		boxMenu: ".slideBoxMenu",
		defautBox: 1
	}, option);
	$(this).each(function() {
		var itemId = "#" + this.id;
		var itemLength = $(itemId + " > .slideBoxWrap > " + settings.boxItem).length;
		if (itemLength > 1){
			hideAll();
			menu();
			showBox(settings.defautBox);
		} else {
			$(itemId + " " + settings.boxMenu).hide();
			$(".slideBoxWrap").css("border","1px solid #E1DCD2");
		}
		function hideAll(){
			$(itemId + " " + settings.boxItem).hide();
	    for(i = 1; i <= itemLength; i++){
	      $(".slideBoxMenu > ul > li#slideBoxMenuItemId" + i).removeClass("colorRed");
	    }
		}
		function menu(){
			var menuStr = '';
			for(i = 1; i <= itemLength; i++){
				menuStr = menuStr + '<li id="slideBoxMenuItemId' + i + '">' + i + '</li>';
			}
			$(itemId + " " + settings.boxMenu).append('<ul>' + menuStr + '</ul>');
			$(itemId + " " + settings.boxMenu).show();
		}
		function showBox(nr){
			hideAll();
			if(itemLength == 3){
				$(itemId + " " + settings.boxMenu).removeClass("slideBoxMenuSildes3Active1");
				$(itemId + " " + settings.boxMenu).removeClass("slideBoxMenuSildes3Active2");
				$(itemId + " " + settings.boxMenu).removeClass("slideBoxMenuSildes3Active3");
				$(itemId + " " + settings.boxMenu).addClass("slideBoxMenuSildes3Active" + nr);
	      $("li#slideBoxMenuItemId" + nr).addClass("colorRed");
			}
			if(itemLength == 2){
				$(itemId + " " + settings.boxMenu).removeClass("slideBoxMenuSildes2Active1");
				$(itemId + " " + settings.boxMenu).removeClass("slideBoxMenuSildes2Active2");
				$(itemId + " " + settings.boxMenu).addClass("slideBoxMenuSildes2Active" + nr);
	      $("li#slideBoxMenuItemId" + nr).addClass("colorRed");
			}
			nrIndex = nr - 1
			$(itemId + " .slideBoxItem:eq(" + nrIndex + ")").show();
		}

		$(itemId + " " + settings.boxMenu + " li").click(function(){
			var numContent = this.id.substr(this.id.length-1, this.id.length);
			showBox(numContent);
		});
		
		
	});
}

