//----------------------------------------------------------------------------------------------------
//-- site-wide jQuery
//----------------------------------------------------------------------------------------------------

$(document).ready(function(){ 
	//-- begin social media footer links
	$(".twitter-img-link").hover(
  		function () { $(this).css({ "cursor" : "pointer" }); }, 
  		function () { $(this).css({ "cursor" : "default" }); }
	);
	$(".twitter-img-link").click(function(){
        openInNewWindow("http://twitter.com/planview");
	});	
	$(".linkedin-img-link").hover(
  		function () { $(this).css({ "cursor" : "pointer" }); }, 
  		function () { $(this).css({ "cursor" : "default" }); }
	);
	$(".linkedin-img-link").click(function(){
        openInNewWindow("http://www.linkedin.com/companies/7268?trk=anet_cg_grppro");
	});	
	$(".xing-img-link").hover(
  		function () { $(this).css({ "cursor" : "pointer" }); }, 
  		function () { $(this).css({ "cursor" : "default" }); }
	);
	$(".xing-img-link").click(function(){
        openInNewWindow("https://www.xing.com/companies/planviewgmbh-portfoliodrivenperformance");
	});
	//-- end social media footer links
	
	//-- begin show more scripts
    $(".show-more-click-here").hover(function () { 
	  	$(this).css("cursor","pointer");
    });
    $("div.show-more-click-here").click(function () { 
	  	$(this).next().toggleClass("show-more-content");
    });
    $(".show-more-click-item").click(function () { 
	  	$(this).toggleClass("show-more-click-item-clicked");
    });
	//-- end show more scripts

	//-- begin ie6 top-nav drop-down fix
	$('.browserIE6 .what-we-do .menu ul li a#topnav-what-we-do').hover(function(){
		$('ul.what-we-do').addClass('show-me');
	}, function() {
		$('ul.what-we-do').removeClass('show-me');
	});
	$('.browserIE6 .products .menu ul li a#topnav-products').hover(function(){
		$('ul.products').addClass('show-me');
	}, function() {
		$('ul.products').removeClass('show-me');
	});
	$('.browserIE6 .services .menu ul li a#topnav-services').hover(function(){
		$('ul.services').addClass('show-me');
	}, function() {
		$('ul.services').removeClass('show-me');
	});
	$('.browserIE6 .resources-category .menu ul li a#topnav-resources').hover(function(){
		$('ul.resources').addClass('show-me');
	}, function() {
		$('ul.resources').removeClass('show-me');
	});
	$('.browserIE6 .who-we-are .menu ul li a#topnav-who-we-are').hover(function(){
		$('ul.who-we-are').addClass('show-me');
	}, function() {
		$('ul.who-we-are').removeClass('show-me');
	});
	//-- end ie6 top-nav drop-down fix
	
	//-- fancybox image pop-up
	if ( $('a.pop-up').length ) { //if exists
		$("a.pop-up").fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});
	}
	//-- fancybox iframe pop-up (used for youtube videos)
	if ( $('a.pop-up-iframe').length ) { //if exists
		$("a.pop-up-iframe").fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'type'			: 'iframe'
		});
	}		
});//-- end site-wide jQuery

//----------------------------------------------------------------------------------------------------
//-- misc scripts
//----------------------------------------------------------------------------------------------------

	//-- necessary for show more scripts- allows users without javascript enabled to view the additional content
	document.write('<style type="text/css" media="all"> .show-more-content {display:none;} </style>');

	//-- open link in new window
	function openInNewWindow(theLink) {
		window.open(theLink);	
	}

//----------------------------------------------------------------------------------------------------
//-- enlarge image pop-up page code
//-- call this script: <a onclick="javascript:openWin('imageURL','imageWidth','imageHeight');">
//----------------------------------------------------------------------------------------------------

var props;
var leftPosition;
var topPosition;
var pageWidth;
var pageHeight;
var smallWindow = null;

function closeWin(){
	if (smallWindow != null){
		if(!smallWindow.closed)
			smallWindow.close();
	}
}

function openWin(imageURL,imageWidth,imageHeight) {

	closeWin();

	pageWidth = parseInt(imageWidth) + 38; 
	pageHeight = parseInt(imageHeight) + 70;

	leftPosition = (screen.width) ? ((screen.width-pageWidth)/2) : 10;
	topPosition = (screen.height) ? ((screen.height-pageHeight)/2) : 10;
	props = "width=" + pageWidth + ",height=" + pageHeight + ",top=" + topPosition + ",left=" + leftPosition + ",resizable=yes,scrollbars=yes";

	smallWindow = window.open("","Image",props);
	smallWindow.document.writeln('<html>');
	smallWindow.document.writeln('<head>');
	smallWindow.document.writeln('<title>Zum Schliessen auf das Bild klicken</title>');
	smallWindow.document.writeln('</head>');
	smallWindow.document.writeln('<body class="popup">');
	smallWindow.document.writeln('<table cellpadding="0" cellspacing="0"><tr><td><a href="javascript:self.close();"><img src="' + imageURL + '" width="' + imageWidth + '" height="' + imageHeight + '" alt="Zum Schliessen auf das Bild klicken" title="Zum Schliessen auf das Bild klicken" border="0" /></a></td></tr>');
	smallWindow.document.writeln('<tr><td align="center" style="font-family:Verdana,Arial,Helvetica;font-size:.8em;"><br /><a href="javascript:self.close();">Fenster schlie&#223;en</a></td></tr></table>');
	smallWindow.document.writeln('</body>');
	smallWindow.document.writeln('</html>');
	smallWindow.document.close();
	smallWindow.focus();
}

//----------------------------------------------------------------------------------------------------
//-- global left-nav contact form
//----------------------------------------------------------------------------------------------------

function openContactPopup() {
	closeWin();

	pageWidth = 710; 
	pageHeight = 300;

	leftPosition = (screen.width) ? ((screen.width-pageWidth)/2) : 10;
	topPosition = (screen.height) ? ((screen.height-pageHeight)/2) : 10;
	props = "width=" + pageWidth + ",height=" + pageHeight + ",top=" + topPosition + ",left=" + leftPosition + ",resizable=yes,scrollbars=yes";

	smallWindow = window.open("/wer-wir-sind/kontakt-form/","mywindow",props);
}

//----------------------------------------------------------------------------------------------------
//-- left-nav
//----------------------------------------------------------------------------------------------------

function hideShowSection(secId, imgId) {
	var sec = document.getElementById(secId);
	var img = document.getElementById(imgId);
	
	var testString = new String(img.id);

	if (sec.style.display == "block" || (sec.style.display == "" && sec.className.indexOf("nodisplay") < 0)) {
		sec.style.display = "none";
		if (testString.indexOf("contact") > -1) {
			img.style.backgroundImage="url(/img/contact-form-arrow-down.gif)";
		} else {
			img.src = "/img/icons/icon-plus.gif";
		}
	}
	else {
		sec.style.display = "block";
		if (testString.indexOf("contact") > -1) {
			img.style.backgroundImage="url(/img/contact-form-arrow-up.gif)";
		} else {
			img.src = "/img/icons/icon-minus.gif";
		}
		
	}			  
}
  
function showFlyout(anchorElement, popupDiv, flag){
// alert(findPosX( document.getElementById('imgfly2')));
 
	if(document.getElementById(popupDiv).id=='flyout2'){     
		//alert(findPosX( document.getElementById(anchorElement)));
		//alert(findPosY( document.getElementById(anchorElement)));
	}
	
	if(flag) {		
			var yCoord = findPosY(document.getElementById(anchorElement)) - (document.getElementById(popupDiv).offsetHeight);
			var xCoord = findPosX(document.getElementById(anchorElement)) + 8;
			
			document.getElementById(popupDiv).style.display="block";
			document.getElementById(popupDiv).style.left = xCoord + "px";
			document.getElementById(popupDiv).style.top = yCoord + "px";
			
			(document.getElementById(popupDiv).offsetHeight);
		
	  }else{
		 
		   if(onFlyout) {
		      //do nothing
		 }else{	
			//document.getElementById(popupDiv).style.display="none"; 
			//no longer need this but leaving it for debug reasons
		    }//end if onFlyout
		}
	}
	
function showDropdown(anchorElement, popupDiv, flag){ 	
	if(flag) {		
			if((document.getElementById(popupDiv).style.display=="none") || (document.getElementById(popupDiv).style.display=="")) {
			
				var yCoord = findPosY(document.getElementById(anchorElement)) - (document.getElementById(popupDiv).offsetHeight);
				var xCoord = findPosX(document.getElementById(anchorElement)) + 8;
			
				document.getElementById(popupDiv).style.display="block";
				document.getElementById(popupDiv).style.left = (xCoord - 179) + "px";
				document.getElementById(popupDiv).style.top = (yCoord + 18) + "px";
			
				(document.getElementById(popupDiv).offsetHeight);
			}
			else {
				document.getElementById(popupDiv).style.display="none";
			}
	  }else{
		 
		   if(onFlyout) {
		      //do nothing
		 }else{	
			//document.getElementById(popupDiv).style.display="none"; 
			//no longer need this but leaving it for debug reasons
		    }//end if onFlyout
		}
	}	

function findPosX(obj)
{
		var curleft = 0;
		if (obj.offsetParent)
		{
				while (obj.offsetParent)
				{
						curleft += obj.offsetLeft
						obj = obj.offsetParent;
				}
		}
		else if (obj.x)
				curleft += obj.x;
		return curleft;
}

function findPosY(obj)
{
		var curtop = 0;
		if (obj.offsetParent)
		{
				while (obj.offsetParent)
				{
						curtop += obj.offsetTop
						obj = obj.offsetParent;
				}
		}
		else if (obj.y)
				curtop += obj.y;
		return curtop;
}

//----------------------------------------------------------------------------------------------------
//-- 
//----------------------------------------------------------------------------------------------------

