var ap;					/* alto de pantalla */	
var anp;				/* ancho de pantalla */
var ancho_wrapper;		/* ancho del wrapper */
var ancho_menu = 200;	/* ancho del menu */
var izq_content;		/* ancho content_izq*/

var posicion_wrapper;
var portfolio_visible = false; /* flag portfolio */

var IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;

if(IE6){

	$(function(){
		$("html").css({'overflow': 'hidden' });

		$("<div>")
			.css({
				'position': 'absolute',
				'top': '0px',
				'left': '0px',
				backgroundColor: '#c0ce00',
				'width': '100%',
				'height': $(window).height(),
				zIndex: 5000
			})
			.appendTo("body");
			
		$("<div class='mensaje_ie'><img src='../images/no-ie6.png' alt='' style='float: left;'/><p><br /><br /><b>Lo lamentamos!</b><br />No es posible visualizar este sitio en Internet Explorer 6.<br /><br />Si desea poder ingresar actualice su   <a href='http://windows.microsoft.com/es-ES/internet-explorer/products/ie/home'>navegador</a> o bien cambie a <a href='http://www.mozilla-europe.org/es/'> Mozilla Firefox</a> o <a href='http://www.google.com/chrome?hl=es'> Google Chrome</a>.<br /><br /><br />Z I R I S | Diseño y Desarrollo Web / Multimedia. / E-mail <a href='mailto:info@ziris.com.ar'>info@ziris.com.ar</a> | Rosario - ARGENTINA</p>")
			.css({
				backgroundColor: '#c0ce00',
				'top': '50%',
				'left': '50%',
				marginLeft: -325,
				marginTop: -100,
				width:650,
				paddingRight: 10,
				height: 200,
				'position': 'absolute',
				zIndex: 6000
			})
			.appendTo("body");
	});		
}


function update_screen_size_vars()
{
	ap = $(window).height();
	anp = $(window).width();
	ancho_wrapper = (anp * 2);
	

	if(anp <= 1280 ){
		izq_content = anp-200;
	}
	else{
		izq_content = anp-200;
	}
		
}



function update_sizes()
{
	/* ancho header */
	$(".header").css({ width: anp+'px'}, 0 );		
	
	/* ancho y alto de contenedor izq */
	$(".izq").css({ height: (ap)+'px'}, 0 );
	$(".izq").css({ width: anp+'px'  }, 0 );

	
	$(".izq_content").css({ width:izq_content+'px'  }, 0 );
	
	/* ancho y alto de contenedor der */
	$(".der").css({ height: ap+'px'}, 0 );			
	$(".der").css({ width: anp+'px'  }, 0 );			
	
	$(".seccion_servicios").css({ width: anp+'px'}, 0 );
	$(".seccion_clientes").css({ width: anp+'px'}, 0 );
	$(".seccion_portfolio").css({ width: anp+'px'}, 0 );
	$(".seccion_contacto").css({ width: anp+'px'}, 0 );			
	
	
	if( !portfolio_visible )
	{
		$("#wrapper").css({ width: ancho_wrapper+'px', left: (-anp)+'px' }, 0 );
		$("#overlay").css({ width: ancho_wrapper+'px', left: (-anp)+'px' }, 0 );
		$(".seccion_contacto").css({ paddingBottom:'0px'}, 0 );
			
		//h = getOffsetTop( document.getElementById('contacto' )) + $(".seccion_contacto").height();								
		h = $(".seccion_servicios").height() + $(".seccion_contacto").height() + $(".header").height();					
		padding = ap - $(".seccion_contacto").height();
		
		$(".seccion_contacto").css({ paddingBottom: padding +'px'}, 0 );
		
		$("#wrapper").css({ height: h +'px'}, 0 );
		$("#overlay").css({ height: h +'px'}, 0 );		
		$(".menu").css({ height: (h+padding) +'px'}, 0 );				
		$(".der").css({ height: (h+padding) + 'px', 'overflow': 'hidden'}, 0 );
		
	}
	else
	{
		$("#wrapper").css({ width: ancho_wrapper+'px' }, 0 );
		$("#overlay").css({ width: ancho_wrapper+'px' }, 0 );
		
		$(".izq").css({ height: ap + 'px'}, 0 );
		$(".der").css({ height: ap + 'px', 'overflow': 'hidden'}, 0 );
		$("#wrapper").css({ height: ap + 'px'}, 0 );
		$("#overlay").css({ height: ap + 'px'}, 0 );		
		$(".menu").css({ height: ap + 'px', 'overflow': 'hidden'}, 0 );	
		
	}
}

function general_init()
{
	//$("html:not(:animated),body:not(:animated)").animate({ scrollTop: 16}, 0);
	
	update_screen_size_vars();			
	update_sizes();
	anchor_init();			

	$(".volver").fadeOut(0);			
		
}



function getOffsetTop(obj) {
	var curleft = curtop = 0;
		
	if (obj.offsetParent) 
	{	
		do {
				curtop += obj.offsetTop;	
		} while (obj = obj.offsetParent);
	}
	
	return curtop;
}

function anchor_init()
{
	$("a.anchorLink").click(function()
	{
		
		$("#overlay").css({ zIndex: 2  }, 0);
		$("#overlay").css({ left:0, top:0 },0);
		
		var elementClick = $(this).attr("href");			
		var destination = getOffsetTop(document.getElementById(elementClick.substr(1)));
		var nueva_posicion = -(ancho_wrapper/2);
		
		if(!portfolio_visible)
		{	
			
			
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1000, function(){
				if(elementClick.indexOf("portfolio") != -1){
					$(".izq").css({ height: ap + 'px'}, 0 );
					$(".der").css({ height: ap + 'px', 'overflow': 'hidden'}, 0 );
					$("#wrapper").css({ height: ap + 'px'}, 0 );
					$("#overlay").css({ height: ap + 'px'}, 0 );		
					$(".menu").css({ height: ap + 'px'}, 0 );	
					$("#wrapper").animate({ left: -ancho_menu+'px'  }, 1500 );								
					$("#footer").fadeOut(1500);
					$(".volver").fadeIn(2500, function(){
						portfolio_visible = true;
						$("#overlay").css({ zIndex: 0  }, 0);	
						$("#overlay").css({ left:0, top:0 },0);
					});										
				}
				else
				{
					$("#overlay").css({ zIndex: 0  }, 0);
				}
			});
			
		}
		else
		{
			/*if(elementClick.indexOf("portfolio") == -1)
			{*/
//				h = getOffsetTop( document.getElementById('contacto' )) + $(".seccion_contacto").height();			
				h = $(".seccion_servicios").height() + $(".seccion_contacto").height() + $(".header").height();					
				padding = ap - $(".seccion_contacto").height();
				
				$(".seccion_contacto").css({ paddingBottom: padding +'px'}, 0 );
				
				$("#wrapper").css({ height: h +'px'}, 0 );
				$("#overlay").css({ height: h +'px'}, 0 );		
				$(".menu").css({ height: (h+padding) +'px'}, 0 );	
				$(".der").css({ height: (h+padding) + 'px', 'overflow': 'hidden'}, 0 );			
						
				$("#wrapper").animate({ left: nueva_posicion+'px' },1000, function(){
					$("#overlay").css({ left:0, top:0 },1000);
					//$(".content_menu").animate({ top: destination+'px'  }, 1500 );
					$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1000 );
					$(".volver").fadeOut(1000);							
					$("#footer").fadeIn(1200, function(){
						$("#overlay").css({ zIndex: 0  }, 0);
						$("#overlay").css({ left:0, top:0 },0);

						$(".izq").css({ height: 'auto'}, 0 );
						$(".der").css({ height: 'auto', 'overflow': 'hidden'}, 0 );
					});
					
					portfolio_visible = false;	
				});
			/*}*/
		}
		return false;
	});
}

