/*// Script para generar los diferentes slider del home //*/

var ul;
var lis = new Array();
var ligas = new Array();
var lisLength;
var bullets;
var size = 614;
var sizeH = 328;
var slider = "slider";
var position = 0;
var flag = 0;
var lis = "";
var liL = "";
var hom =0;
var intVal = "";
	
/*// Script de funciones para mostrar el slide 
correspondiente de la seccion a la se esta 
accesando medinate click //*/

function getSlider(id) 
{ 
	var box = document.getElementById("Box");
	// Reseteamos la salida del html
	box.innerHTML = "";
	
	var img = new Array();
	
	// Jquery para el menu
	$("div.menuH").css("background", "#0093D3");
	document.getElementById(id).style.background = "none";
	
	if(id == "Videos") 
	{
		img[0] = "video01";
		img[1] = "video02";
		img[2] = "video03";
		
		frames[0] = 'http://www.youtube.com/embed/EBVmifVtP_g';
		frames[1] = 'http://www.youtube.com/embed/QAv46hHUHAg';
		frames[2] = 'http://www.youtube.com/embed/yaZaby0KPVw';
	
		box.innerHTML = setImgs(img, ".png", id, true, frames);
	}
	else if(id == "Promos") 
	{
		img[0] = "p";
		img[1] = "p1";
		
		box.innerHTML = setImgs(img, ".jpg", id);
	}
	else
	{
		img[0] = "CRB002003";
		img[1] = "N-186-0250";
		img[2] = "42-25628341";
		img[3] = "42-26619095";
		img[4] = "42-22376372";
		
		box.innerHTML = setImgs(img, ".jpg", id);
	}
	
	if(id == "Productos") { 
		hom = 0;
	} else { 
		hom =1;
	}
	
	clearInterval(intVal);
	position = 0;
	init();
}

function setImgs(array, prefix, id, onclick, arrayInfo, href) 
{
	var arrayLength = array.length;
	var output = "";
	var bullets = "<div id=\"bullets\"></div>";
	
	output = "<div class=\"sec_slide\" id=\"" + id + "\">";
	output+= "<ul id=\"list\">";
	
	for(var i=0; i < arrayLength; i++) 
	{
		if(onclick) 
		{
			output+="<li style=\"cursor:pointer;\" onclick=\"javascript:setInnerHtml('"+arrayInfo[i]+"', 'frame', 614, 328); loadP('pop');\" id=\""+i+"\"><img src=\"http://itt.com.mx/images/"+array[i] +prefix+"\" /></li>";
		}
		else if(href)
		{
			output+="<li id=\""+i+"\"><a href=\""+href[i]+"\"><img src=\"http://itt.com.mx/images/"+array[i] +prefix+"\" /></a></li>";
		}
		else
		{
			output+="<li id=\""+i+"\"><img src=\"http://itt.com.mx/images/"+array[i] +prefix+"\" /></li>";
		}
	}
	
	output+= "</ul>";
	output+= bullets;
	output+= "</div>";
	
	return output;
}

function setInnerHtml(content, type, wdth, hight) 
{
	var closeBtn = "<span id=\"popClose\" onclick=\"javascript:disablePopup();\">cerrar</span>";
	document.getElementById("pop").style.width = wdth;
	document.getElementById("pop").style.height = hight;
	
	if(type == "frame") 
	{ 
		document.getElementById("pop").innerHTML = closeBtn + "<iframe title=\"Video\" width=\"614\" height=\"328\" src=\"" + content + "\" frameborder=\"0\" allowfullscreen></iframe>";	
	}
	else if(type == "img") 
	{ 
		document.getElementById("pop").innerHTML = closeBtn + '<img src="http://itt.com.mx/images/' + content + '" />';
	}
	else if(type == "blank") 
	{ 
		document.getElementById("pop").innerHTML = closeBtn + content;
	}
}

/*// Script de funciones pata generar el slider //*/
function setProp() 
{ 
	lis = $("ul#list").children("li");
	liL = lis.length;
	
	//alert(lis.length);
	
	lis.wrapAll('<div class="'+ slider +'" />"');
	$('.'+slider).css({ width : (size * liL) + "px", height : sizeH + "px" });
}

function Slide(lis) 
{ 
	if(flag == 0) {
		if(position != (liL - 1)) 
		{
			$('.'+slider).animate({'marginLeft' : size*(-position)},'slow');
			$(".bullet").removeClass("act");
			$("#b" + position).addClass("act");
			position++;
		} 
		else 
		{
			flag = 1;
		}
	}
	else if(flag == 1) 
	{
		if(position != 0) 
		{
			$('.'+slider).animate({'marginLeft' : size*(-position)},'slow');
			$(".bullet").removeClass("act");
			$("#b" + position).addClass("act");
			position--;
		}
		else
		{
			flag = 0;
		}
	}
}

function lnks() 
{
	ul = document.getElementById("list");
	lis = ul.getElementsByTagName("li");
	
	bullets = document.getElementById("bullets");
	
	lisLength = lis.length; //4
	
	// loop
	for(var i=0;i < lisLength; i++) 
	{
		ligas[i] = '<a class="bullet" id="b'+i+'" onclick="javascript:simg('+ i +')"></a>';
		
		bullets.innerHTML+=ligas[i];
	}
}


function simg(valor) { 

	$('.'+slider).animate({'marginLeft' : size*(-valor)},'slow');
	$(".bullet").removeClass("act");
	$("#b" + valor).addClass("act");
	position = valor;

}

function init() 
{
	var img = new Array();
	var frames = new Array();
	var href = new Array();
	
	try 
	{
		if(hom == 0) 
		{
			// Al cargar la pagina por primera
			// vez o si se accesa al slider de
			// videos
			//img[0] = "video01";
			img[0] = "1";
			img[1] = "2";
			img[2] = "3";
			img[3] = "4";
			img[4] = "5";
			img[5] = "6";
			img[6] = "7";
			img[7] = "8";
			img[8] = "9";
			img[9] = "10";
			img[10] = "11";
			img[11] = "12";
			//img[1] = "42-26619095";
			
			href[0] = "index.php?cPath=30";
			href[1] = "index.php?cPath=32";
			href[2] = "index.php?cPath=28";
			href[3] = "index.php?cPath=31";
			href[4] = "index.php?cPath=26";
			href[5] = "index.php?cPath=27";
			href[6] = "index.php?cPath=29";
			href[7] = "index.php?cPath=25";
			href[8] = "index.php?cPath=34";
			href[9] = "index.php?cPath=33";
			href[10] = "index.php?cPath=24";
			href[11] = "index.php?cPath=35";
			
			var box = document.getElementById("Box");
			box.innerHTML = setImgs(img, ".jpg", "Productos", false, '', href);
			
			
			document.getElementById("Productos").style.background = "none";
		}
		
		setProp();
		lnks();
		intVal = setInterval( "Slide()", 5000 );
	}
	catch(err) { }
}

	window.onload = init;
