function initSlider(initValue, link0, link1) 
{
	document.onselectstart = new Function('return false');

	var slider = jQuery.fn.jSlider({
	    renderTo: '#navislider',
	    size: { barWidth: 515, sliderWidth: 253 },
	    barCssName: 'adpublica_slider',
	    onChanged:function(percentage,e)
	    {
	    	 if (percentage < 0.5) {
	    	 	//news & stories
				slider.setSliderValue(0, function(percentage) { });
	    	 	xajax_showSubnavi(link0, {obj_id:7, level:0}, link0);
	    	 }
	    	 else {
	    	 	//agentur
	    	 	slider.setSliderValue(1, function(percentage) { });
	    	 	xajax_showSubnavi(link1, {obj_id:9, level:0}, link1);
	    	 }
	    }
	});

	slider.setSliderValue(initValue, function(percentage) { });
}

var casePagerArray = new Array;  //tpl -> casestudy_overlay.tpl

/*function check_newsletter_form () {
	var nl_status=true;

	if ((jQuery('#subscr_mail').val().length<5 || jQuery('#subscr_mail').val().indexOf("@")==-1 || jQuery('#subscr_mail').val().indexOf(".")==-1)) {
		alert("Sie müssen ihre E-Mail-Adresse eingeben!");
		nl_status = false;
	}

	if (nl_status==true) {
		b = 600;
		h = 300;
		x = (screen.width-b)/2;
		y = (screen.height-h)/2;
		var nl_popup = window.open('URL','nl_popup','scrollbars=no, resizeable=yes'+'left='+x+',top='+y+',screenX='+x+',screenY='+y+',width='+b+',height='+h);
		jQuery('#newsletterform').submit();
	}
	else {
		return false;
	}
}*/

function validateCommentForm() {
	if (jQuery('#kommentar_name').val().length < 1) {
		alert('Bitte geben Sie Ihren Namen an!');
		return false;
	}
	
	if ((jQuery('#kommentar_mail').val().length<5 || jQuery('#kommentar_mail').val().indexOf("@")==-1 || jQuery('#kommentar_mail').val().indexOf(".")==-1)) {
		alert('Bitte geben Sie Ihre E-Mail-Adresse an! Diese wird nicht veröffentlicht.');
		return false;
	}
	
	if (jQuery('#kommentar_text').val().length < 1) {
		alert('Bitte geben Sie Ihren Kommentar ein!');
		return false;
	}
	
	return true;
}

var sliderObj;

function activateFlowtabs(index)
{
	$("div#flowtabs").children("div.active").removeClass("active");	


	var  child =$("div#flowtabs").children("div[rel!=temp]");
	child = child[index];


	var leftSlidePos = ( ( ( $(child).width() * (index+1) ) - ($(child).width()/2) ) - (99/2) ) ;
	
	$("div.oMid").animate({'left':leftSlidePos});

	$(child).addClass("active");	
}

function calcPageCounter()
{
	pageAmount = 0;
	curPageCount = (sliderObj.getPageIndex()+1);
	var breakLoop = false; 
						
	for( var k=0; k<casePagerArray.length; k++ ) 
	{
		if(curPageCount <= casePagerArray[k] && breakLoop == false)
		{
			pageAmount 	= (k==0)?casePagerArray[k]:casePagerArray[k] - casePagerArray[k-1];
			curPageCount= (k==0)?curPageCount:curPageCount - casePagerArray[k-1];
			breakLoop 	= true;
			activateFlowtabs(k);
		}
 							
 	}
	
	if (pageAmount < 2) {
		$("#page_bottom_bar").hide();
	}
	else {
		$("#page_bottom_bar").show().html('<span style="color:#F64C18">'+curPageCount+"</span> / "+pageAmount);
	}

}

function initCasePager(noPslider)
{
	
	if(typeof(console) != 'undefined') console.log(typeof(noPslider));
	
	var browserWidth		= $(window).width();
	var browserHeight		= $(window).height();
		
	var left = (browserWidth  - parseInt($(".casestudy_overlay").css("width").replace("px",""))) / 2;
    var top  = (browserHeight - $(".casestudy_overlay").height()) / 2;
	
	if((top-60) < 0) {
		top = 0;
	} else {
		top = top-60;	
	}
	
	if(browserHeight <= 750) {
		top = -27;
	}

	$(".casestudy_overlay").css({"left":left,"top":top});
	casePagerArray = [];
	$("div.tempCounter").each(function(){ casePagerArray.push($(this).html()); });
	
	var tWidth = 100 / casePagerArray.length;
	
	$("div#flowtabs").children("div[rel!=temp]").each(function(){	$(this).css("width",tWidth+"%");	});
	
	
	activateFlowtabs(0);
	
	if(typeof(noPslider)=='undefined')
	{
  		projectSliderObj = $("#flowpanes_navi").scrollable({size: 6 ,next: ".nextImg",prev: ".prevImg"}).navigator(
   		{ 
 			api:true, 
 			idPrefix: 'pImg',
        	activeClass: 'current'

    	}); 
	}
 
    // select #flowplanes and make it scrollable. use circular and navigator plugins 
   sliderObj = $("#flowpanes").scrollable({size: 1,clickable:false}).navigator(
   		{ 
 			api:true,
        	navi: "#flowtabs", 
 			idPrefix: 'tab',
        	activeClass: 'current' 
    	}); 

	sliderObj.onSeek(function() 
					{ 

						if((this.getPageIndex()+1)==this.getPageAmount())
						{
							$("button.next img").attr("src","/ccds_tpl_img/case_study/casestudy_arrow_right_inactive.jpg");
							$("button.next").addClass("inactive");
							$("button.next").removeClass("active");
						}
						else
						{
							$("button.next img").attr("src","/ccds_tpl_img/case_study/casestudy_arrow_right_active.jpg");
							$("button.next").addClass("active");
							$("button.next").removeClass("inactive");
						}	
						
						if(this.getPageIndex()==0)
						{
							$("button.prev img").attr("src","/ccds_tpl_img/case_study/casestudy_arrow_left_inactive.jpg");
							$("button.prev").addClass("inactive");
							$("button.prev").removeClass("active");						
						}
						else
						{
							$("button.prev img").attr("src","/ccds_tpl_img/case_study/casestudy_arrow_left_active.jpg");
							$("button.prev").addClass("active");
							$("button.prev").removeClass("inactive");						
						}
						
						calcPageCounter();
						 
					}); 
	sliderObj.reload();
	calcPageCounter();		
	flowplayer("a.myPlayer", "/flash/flowplayer.commercial-3.1.5.swf",
							{
							wmode: 'transparent', 
							 	clip: 
								{ 	autoPlay: 		false,
									scaling: 		'fit',
       						 		autoBuffering: 	true ,
       						 		onResume: 		function(){openCasepageFlv( $(this.getParent()).attr("id"), this  );	},
       						 		onPause: 		function(){closeCasepageFlv( $(this.getParent()).attr("id"), this );  },
       						 		onFinish: 		function(){closeCasepageFlv( $(this.getParent()).attr("id"), this );  }
    							},
    							plugins: { controls: null},
    							canvas:  {
									backgroundColor: '#ffffff',
									backgroundGradient: 'none',
									display: 'none',
									border: 'none'	
								},
								key: '#@4c48b94923df0ca006e'
							}
				);	
	jQuery('a.myPlayer').unbind('change');
}

flv_status = 'closed';

function openCasepageFlv(movID, flowplayer)
{
	if(movID && flv_status != 'opening' && flv_status != 'closing')
	{
	
		flv_status = 'opening';
		
/*		alert("opening ... "+movID);*/
		//$(".page_content").prepend('<img onclick="closeCasepageFlv(\''+movID+'\');$(this).remove();" src="/ccds_tpl_img/case_study/closeX1.png" alt="X" title="X" style="position:relativ;left:-20;top:-20px;left:-20;height:20px;width:20px;" />');
		
		var leftAmount = (-1* parseInt( $("#flowpanes .items").css("left").replace("px","") ) );
		
		$("a#"+movID).addClass('big');
		
		$("a#"+movID).css("left",leftAmount );
		$("a#"+movID).removeClass('small');		
		//$("a#"+movID).fadeIn();
		/*
		$("a#"+movID).parent().removeAttr("onclick");	
		$("a#"+movID).parent().unbind("click");
		$("a#"+movID).unbind("click");
	
		$("a#"+movID).click(function(){closeCasepageFlv(movID);});
		*/
		
		
		
		setTimeout( function() {flv_status = 'opened'; }, 2500);
//		flv_status = 'opened';
	}
}

function closeCasepageFlv(movID)
{
	if(movID && flv_status != 'opening' && flv_status != 'closing')
	{			
		
		flv_status = 'closing';
		
		//$("a#"+movID).unbind("click");	
		//$("a#"+movID).parent().mousedown(function(){openCasepageFlv(movID);});

		$("a#"+movID).addClass('small');
		$("a#"+movID).removeClass('big');
		
		flv_status = 'closed';

	}
}

function openCasepageImg(imgID)
{
	if(imgID)
	{
		var leftAmount = (-1* parseInt( $("#flowpanes .items").css("left").replace("px","") ) );
		$("#"+imgID).addClass('showBig');
		$("#"+imgID).css("left",leftAmount );
		$("#"+imgID).removeClass('bigImgs');		
		$("#"+imgID).fadeIn();

		$("#"+imgID).parent().removeAttr("onclick");	
		$("#"+imgID).parent().unbind("click");
		$("#"+imgID).unbind("click");
	
		$("#"+imgID).click(function(){closeCasepageImg(imgID);});
	}
}

function closeCasepageImg(imgID)
{
	//console.log('closeCasepageImg'+imgID);
	//console.log($("img#"+imgID));	
	if(imgID)
	{			
		$("#"+imgID).unbind("click");	
		$("#"+imgID).parent().mousedown(function(){openCasepageImg(imgID);});
		//console.log($("img#"+imgID).parent());


		$("#"+imgID).fadeOut();
		$("#"+imgID).addClass('bigImgs');
		$("#"+imgID).removeClass('showBig');
	}
}



