var conn=CONNEXION('preview');

function showDetails(pic,divContent,width,height){

	var	param='pic='+pic+'&width='+width;	
	var left = parseInt( (screen.availWidth/2) - (width/2)-50);
	var top = parseInt( (screen.availHeight/2) - (height/2)-30);

	$(divContent).style.display = 	"block";

	conn.openLink('preview.php',param,'post',divContent,'undefined','');
	new Effect.Grow(divContent, { direction: 'top-left', duration: 10.0  })

}


function openMenuItem(divon) {

var toggles = document.getElementsByClassName('sumbeniu_c'); // where I click on
for(i = 0; i < toggles.length; i++) {
	idDivx = toggles[i].parentNode.getAttribute("id");
	idD = idDivx.split("_");
	idC = divon.split("_");
		
	if( String(idD[1]) != String(idC[1]) ) {
		
		if ($(idDivx).style.display!="none"){
			new  Effect.SlideUp($(idDivx), { duration:0.5 });
		}
			
	} else {
	
		if ($(idDivx).style.display=="none"){
			new Effect.SlideDown($(idDivx), { duration:0.5 });
		}
	
	}
}
  	window.setTimeout("resizeLeftSide()", 510);
}

function openMenuItem2(divon) {
	if ($(divon).style.display!="none"){
		new  Effect.SlideUp($(divon), { duration:0.5 });
	} else {
	new Effect.SlideDown($(divon), { duration:0.5 });
	}
}

function openDepartment(divon) {
	if ($(divon).style.display!="none"){
		new  Effect.SlideUp($(divon), { duration:0.5 });
	} else {
		new Effect.SlideDown($(divon), { duration:0.5 });
	}
}

function openMenuItemBlind(divon) {

	var toggles = document.getElementsByClassName('sumbeniu_c'); // where I click on
	for(i = 0; i < toggles.length; i++)
	{
		idDivx = toggles[i].parentNode.getAttribute("id");
		idD = idDivx.split("_");
		idC = divon.split("_");
			
		if( String(idD[1]) != String(idC[1]) ) {
			if ($(idDivx).style.display!="none"){
				new  Effect.BlindUp($(idDivx), { duration:0.5 });
			}
		} else {
			if ($(idDivx).style.display=="none"){
				new Effect.BlindDown($(idDivx), { duration:0.5 });
			}
		}
	}
}

function playEfects() {
   $('meniu').setStyle( { top:'0px',left:'230px' } );
   new Effect.Appear('meniu', { duration: 1 });
   new Effect.Move('meniu',{
   x: -230,
   y: 0,
   afterFinish: function() {
   new Effect.Appear('right_side', { duration: 1 });
   window.setTimeout("resizeRightSide()", 1100);
 	// new Effect.BlindDown('submeniu_1',{duration:0.5});
   remBackground();
   }
   });
 
   
	}

function remBackground() {
$("right_side").style.background="none";
$("meniu").style.background="none";
}

var prevHeight = "0px";

function resizeWindow() {

	var height = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight); 
	var contentHeight = $('continut').offsetHeight;
	if ($('PhotoContainer'))
	{
		heightPoza = $('PhotoContainer').offsetHeight;
	} else {
		heightPoza = 0;
	}
			//alert ($('continut').offsetHeight);

	if (prevHeight != "0px") {
		//alert(prevHeight);
		$('continut').style.height = prevHeight;
	}
	
	if (contentHeight < height && (heightPoza > 400 || heightPoza == 0) )
	{
		if (navigator.userAgent.indexOf("MSIE 6.0")!=-1) {
			
			$('continut').style.height = height+"px";
		
		} else if (navigator.userAgent.indexOf("MSIE 7.0")!=-1) {
			$('continut').style.height = (height-56)+"px";
		} else {
			$('continut').style.height = (height-76)+"px";
		}
		
		if (prevHeight == "0px") prevHeight = $('continut').style.height;
		//alert ("contentHeight < height | height="+height+" | contentHeight="+contentHeight+" | heightPoza="+heightPoza);
	}
	
	if (contentHeight > height && (heightPoza >= 400 || heightPoza == 0) )
	{ 
		$('continut').style.height = $('continut').offsetHeight+"px";
	
		if (prevHeight == "0px") prevHeight = $('continut').style.height;

		//alert ("contentHeight > height | height="+height+" | contentHeight="+contentHeight+" | heightPoza="+heightPoza+" | continut offsetHeight="+$('continut').offsetHeight);
	}

	if (contentHeight <= height && navigator.userAgent.indexOf("MSIE 6.0")!=-1)
	{
		$('continut').style.height = ($('continut').offsetHeight-76)+"px";
		$('fixed1').style.marginLeft = "0px";
		$('shadow').style.marginLeft = "0px";
		$('margin-scroll').style.marginRight = "16px";

		document.body.style.backgroundPosition="50% 100%";
		
		//alert ("contentHeight < height | height="+height+" | contentHeight="+contentHeight+" | heightPoza="+heightPoza);
		//alert ("fixed1 ML: "+$('fixed1').style.marginLeft+" shadow: "+$('shadow').style.marginLeft+" margin-scroll: "+$('margin-scroll').style.marginLeft)
	}
	
	if (contentHeight > height && navigator.userAgent.indexOf("MSIE 6.0")!=-1) { 
		if ( $('fixed1').style.marginLeft = "0px" ) {
			$('fixed1').style.marginLeft = "-16px";
			$('margin-scroll').style.marginLeft = "15px";
			$('margin-scroll').style.marginRight = "0px";
		}
		if ( $('shadow').style.marginLeft = "0px" ) {
			$('shadow').style.marginLeft = "-16px";
		}
		
		document.body.style.backgroundPosition="46% 100%";
		
		//alert ("contentHeight > height | height="+height+" | contentHeight="+contentHeight+" | heightPoza="+heightPoza+" | continut offsetHeight="+$('continut').offsetHeight);
		//alert ("fixed1 ML: "+$('fixed1').style.marginLeft+" shadow: "+$('shadow').style.marginLeft+" margin-scroll: "+$('margin-scroll').style.marginLeft);
	}	
	
}

function resizeRightSide() {

	var height = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight); 
	var contentHeight = $('continut').offsetHeight;
	
	var rightHeight = $('rightcolumn').offsetHeight;

	
	if ((rightHeight > height || contentHeight > height) && navigator.userAgent.indexOf("MSIE 6.0")!=-1) { 
		
		if ( $('fixed1').style.marginLeft = "0px" ) {
			$('fixed1').style.marginLeft = "-16px";
			$('margin-scroll').style.marginLeft = "15px";
		}
		if ( $('shadow').style.marginLeft = "0px" ) {
			$('shadow').style.marginLeft = "-16px";
		}
		
	}

	if ((contentHeight <= height && rightHeight <= height) && navigator.userAgent.indexOf("MSIE 6.0")!=-1)
	{
		$('fixed1').style.marginLeft = "0px";
		$('shadow').style.marginLeft = "0px";
		$('margin-scroll').style.marginLeft = "0px";
	}	
	
	if (rightHeight > contentHeight) $('continut').style.height = (rightHeight+91)+"px";
	
	//alert ("height="+height+" | contentHeight="+contentHeight+" | rightHeight="+rightHeight);
}

function resizeLeftSide() {

	var height = (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight); 
	var contentHeight = $('continut').offsetHeight;
	var leftHeight = $('leftcolumn').offsetHeight;
	
	if (leftHeight > contentHeight) $('continut').style.height = (leftHeight+91)+"px";
	
	if ((leftHeight > height || contentHeight > height) && navigator.userAgent.indexOf("MSIE 6.0")!=-1) { 
		
		if ( $('fixed1').style.marginLeft = "0px" ) {
			$('fixed1').style.marginLeft = "-16px";
			$('margin-scroll').style.marginLeft = "15px";
		}
		if ( $('shadow').style.marginLeft = "0px" ) {
			$('shadow').style.marginLeft = "-16px";
		}
	}

	if ((contentHeight <= height && leftHeight <= height) && navigator.userAgent.indexOf("MSIE 6.0")!=-1)
	{
		$('fixed1').style.marginLeft = "0px";
		$('shadow').style.marginLeft = "0px";
		$('margin-scroll').style.marginLeft = "0px";
	}	
}


function preLoadImages()
{	
	var flag = "no";
    var imageCache = new Array();
    var linkArray = document.getElementsByTagName("a");
    for (var loop=0; loop<linkArray.length; loop++)
    {
        if (linkArray[loop].className.indexOf("preloadThis") != -1)
        {
            imageCache[imageCache.length] = new Image();
            imageCache[imageCache.length-1].src = linkArray[loop].href;
			flag = "ok";
        }
    }
	
	if (flag == "ok"){
		 initImage();
		}
}


function startup() {
	try {
		resizeWindow();
		playEfects();
		preLoadImages();
		initMenu();
		loadAPI();
	} catch(e) {
		//alert (e)	
	}
}


var oldonload = window.onload;

if (typeof window.onload != 'function') {
	window.onload = startup;
} else {
	window.onload = function() {
		oldonload();
		startup();
	}
}

function saveCV(id) {
	var sURL = 'aplica_cv.php?id=' + String(id);
	var imageWin = window.open(sURL, 'saveCV', 'height=250,width=410,scrollbars=1,resizable=1')	
}

window.onresize = resizeWindow;