﻿var ancho,alto,altoPantalla,anchoPantalla,ruta,img_x,img_y;
var num_img = 8;

function ini(){
	effects();
	 
	 ini_img();
	 $('#img').innerfade({
		speed: 1000,
		timeout: 5000,
		type: 'sequence'
	 });
	  $(window).bind("resize", function(){//Adjusts image when browser resized
		imageresize();
	 });
}

function effects(){
	$('#content').fadeTo('slow',0.5).fadeTo('slow',1);
}


function ini_img(){

	ancho = $(window).width();
	alto = $(window).height();
	altoPantalla 	= 	screen.height;
	anchoPantalla 	= 	screen.width;

	ruta = url(anchoPantalla,altoPantalla);
	var pic = "";

	for(var i=1;i<=num_img;i++){
		image = "fotos/"+ruta+"/dioxide-"+i+".jpg";
		document.images['dioxide_'+i].src = image;
	}
}

function url(anchoPantalla,altoPantalla){
	url_aux = anchoPantalla+"x"+altoPantalla;
	if(url_aux!="1024x768"  && url_aux!="1280x800"  && url_aux!="1280x1024"  && url_aux!="1440x900" && url_aux!="1680x1050" && url_aux!="1950x1200" && url_aux!="2048x1536"){
		if(anchoPantalla>2048) url_aux = "2048x1536";
		if(anchoPantalla<1024) url_aux = "1024x768";
		if(anchoPantalla>1024 && anchoPantalla<1280)
			url_aux = "1024x768";
		else if(anchoPantalla>1280 && anchoPantalla<1024)
				if(altoPantalla>800 && altoPantalla<1024)
					url_aux = "1280x800";
				else
					url_aux ="1280x1024";
		else if(anchoPantalla>1440 && anchoPantalla<1680)
			url_aux ="1680x1050";
		else if(anchoPantalla>1680 && anchoPantalla<1950)
			url_aux ="1950x1200";
	}
	return url_aux;
}


function imageresize(){
	var pic = "";
	ancho_tmp = $(window).width();
	for(var i=1;i<=num_img;i++){
		pic = $('#dioxide_'+i); 
		pic.removeAttr("width");  
		pic.removeAttr("height"); 
		img_x = pic.width();
		img_y =  pic.height();
		arr_tam = tam_img(img_x,img_y);
		document.getElementById("dioxide_"+i).width  = arr_tam[0];
		document.getElementById("dioxide_"+i).height = arr_tam[1];
		document.getElementById("dioxide_"+i).style.marginLeft = Math.ceil((ancho_tmp - arr_tam[0])/2)+"px";
	} 
}

function tam_img(ancho_x,alto_y){
	var dim_img = new Array();
	var alto_img =  alto;
	var ancho_img = (ancho_x * alto_img)/alto_y;
	dim_img[0] = Math.ceil(ancho_img);
	dim_img[1] = Math.ceil(alto_img);
	
	return dim_img;
}

function dioxide(){

	// Analytics
	var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-20572143-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();

	//

	//banner & content
	alto = alto - 80;
	document.getElementById("banner").style.height = parseInt(alto)+"px";
	alto = alto - 60;
	document.getElementById("content").style.height = parseInt(alto)+"px";

	document.cookie="div_alto = "+alto+"";
	//
	/*
	var image,pic;


	for(var i=1;i<=num_img;i++){
		
		
		pic = $('#dioxide_'+i); 
		image = "fotos/"+ruta+"/dioxide-"+i+".jpg";
		pic.src = image;
		pic.removeAttr("width");  
		pic.removeAttr("height"); 
		
		img_x = pic.width();
		img_y =  pic.height();
		
		arr_tam = tam_img(img_x,img_y);
		
		document.getElementById("dioxide_"+i).width  = arr_tam[0];
		document.getElementById("dioxide_"+i).height = arr_tam[1];
		document.getElementById("dioxide_"+i).style.marginLeft = Math.ceil((ancho - arr_tam[0])/2)+"px";
	}
	*/
	imageresize();
	document.getElementById("banner").style.overflow = "visible";

	document.getElementsByTagName("html")[0].style.overflow = "hidden";


}



function dfocus(obj){
	var obj2 = document.getElementById(obj);
	obj2.style.backgroundColor = '#4c006c';
	var ar = new Array()
	ar[0] = "home";
	ar[1] = "mark";
	ar[2] = "colecction";
	ar[3] = "contact";
	ar[4] = "clients";
	for(i=0;i<ar.length;i++) {
		
		if(ar[i] != obj)
			document.getElementById(ar[i]).style.backgroundColor = 'black';
	}
}	


function focusForm(text,num){

	var obj;
	obj = document.getElementById("obj-"+num);
	if(obj.value==text){
		obj.value = '';
		obj.style.backgroundColor = '#f9f2db';
		obj.style.fontWeight = 'bold';
	}
}
function changeForm(text1,text2,text3,text4,num){

	var obj;
	obj = document.getElementById("obj-"+num);
	
	if((obj.value!=text1 || obj.value!=text2 || obj.value!=text3  || obj.value!=text4) && obj.value){
		obj.style.backgroundColor = '#b6b6b6';
		obj.style.color = 'white';
		obj.style.fontWeight = 'bold';
	}
}


