var root = "/unimogjeans.com.ar/";

$(function() {
$('.tooltips-h a,.tooltips-m a,.tooltips-j a, .tooltips-j-dos a').tooltip({ 
    track: true, 
    delay: 0, 
		showURL: false, 
    showBody: " - ", 
    fade: 100 ,
    bodyHandler: function() { 
      return $($(this)).html(); 
    }
});
$('.tooltips-h a,.tooltips-m a, .tooltips-j, .tooltips-j-dos').click(function(e){
	e.preventDefault();
});
/*$('#prod-hombres a').lightBox({
fixedNavigation:'true',
overlayBgColor: '#000000',
overlayOpacity: 0.5,
containerResizeSpeed: 450,
txtImage: 'Imagen',
txtOf: 'de'
});


$('#prod-mujer a').lightBox({
fixedNavigation:'true',
overlayBgColor: '#000000',
overlayOpacity: 0.5,
containerResizeSpeed: 450,
txtImage: 'Imagen',
txtOf: 'de'
});*/

$('#slide-home').cycle({
fx:     'fade',
speed:    800, 
timeout:  4000
});

$('#slide-look').cycle({
fx:     'fade',
speed:    900, 
timeout:  5000
});

$('.prod-mujer').cycle({
fx:     'fade',
speed:   800, 
prev:   '#prev-m',
next:   '#next-m',
timeout: 4000 ,
after: function(){
	var actual = $(this).attr('class');
	actual = actual.substr(2);
	$('.tooltips-m a:visible').hide();
	$('.tooltips-m a.t-'+actual).show();
}
});
$('.prod-mujer').cycle('pause');

$('.prod-hombres').cycle({
fx:     'fade',
speed:   800, 
prev:   '#prev-h',
next:   '#next-h',

timeout: 4000 ,
after: function(){
	var actual = $(this).attr('class');
	actual = actual.substr(2);
	$('.tooltips-h a:visible').hide();
	$('.tooltips-h a.t-'+actual).show();
}
});
$('.prod-hombres').cycle('pause');

$('.prod-hombres-dos').cycle({
fx:     'fade',
speed:   800, 
prev:   '#prev-j',
next:   '#next-j',

timeout: 4000 ,
after: function(){
	var actual = $(this).attr('class');
	actual = actual.substr(2);
	$('.tooltips-j a:visible').hide();
	$('.tooltips-j a.t-'+actual).show();
}
});
$('.prod-hombres-dos').cycle('pause');

$('.prod-hombres-dos').cycle({
fx:     'fade',
speed:   800, 
prev:   '#prev-j',
next:   '#next-j',

timeout: 4000 ,
after: function(){
	var actual = $(this).attr('class');
	actual = actual.substr(2);
	$('.tooltips-j-dos a:visible').hide();
	$('.tooltips-j-dos a.t-'+actual).show();
}
});
$('.prod-hombres-dos').cycle('pause');

$('#slide-stores').cycle({
fx:     'fade',
speed:    800, 
timeout:  4000
});

$('.slide-coleccion').cycle({
fx:     'fade',
speed:   800, 
prev:   '#prev',
next:   '#next',
after:   onAfter,
timeout: 4000
});

$('.slide-coleccion').cycle('pause');
$('#pause').click(function() { 
$('.slide-coleccion').cycle('pause');
$('#pause img').attr("src","img/bt_pause_active.png");
$('#resume img').attr("src","img/bt_play.png");
//$('#actual').html("reanudar");
});

$('#resume').click(function() { 
$('.slide-coleccion').cycle('resume',true);
$('#resume img').attr("src","img/bt_play_active.png");
$('#pause img').attr("src","img/bt_pause.png");
});

//lazyload
/*$(".prod-hombres img").lazyload({
placeholder : root + "img/loading.gif",
effect      : "fadeIn"
});

$(".prod-mujer img").lazyload({
placeholder : root + "img/loading.gif",
effect      : "fadeIn"
});
*/
$('#banners img').hover(function(){
$(this).animate({
opacity:0.8
},200);
},
function(){
$(this).animate({
opacity:1
},200,'linear',function(){
//alert('alertinga');
});
});
	
});

function onAfter(curr, next, opts) {
    var current = opts.currSlide+1;
	var count = opts.slideCount;
    //$('#prev')[index == 0 ? 'hide' : 'show']();
    //$('#next')[index == opts.slideCount - 1 ? 'hide' : 'show']();
	//$('#actual').append((index+1) + " / " + (opts.slideCount - 1));
	$('#actual').html(current+" / "+count);
	//alert(index);
}

var xmlHttp;
function GetXmlHttpObject(){var xmlHttp=null;try{xmlHttp=new XMLHttpRequest();}catch(e){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}}return xmlHttp;}

function popup(msg,fade,color){
Mcolor = color || "#FFF";
$.blockUI({ css: { 
border: 'none', 
padding: '20px', 
backgroundColor: '#000', 
fontSize: '16px', 
'-webkit-border-radius': '10px', 
'-moz-border-radius': '10px', 
opacity: '.9', 
color: Mcolor
},message: msg });
if(fade==true) fade = 1500;
if(fade>0) setTimeout($.unblockUI, fade); 
}

function validate(status,id){
if(status == 0){
document.getElementById(id).style.borderColor = '#f00';
document.getElementById(id).style.color= '#f00';
}else{
document.getElementById(id).style.borderColor = '#666';
document.getElementById(id).style.color= '#333';
}
}

// Parser
function parseParams(params){
	var contenedor = '';
		
		for(var contar in params){
		
		var type = gettype(params[contar]);
			
			if(type == 'checkbox' || type == 'radio'){
				contenedor += params[contar]+'='+getcheck(params[contar])+'&';
			}else if(type == 'select-multiple'){
				contenedor += params[contar]+'='+getMultiple(params[contar])+'&';
			}else{
				contenedor += params[contar]+'='+escape(getval(params[contar]))+'&';
			}
		
		}
		
	return contenedor.substr(0,contenedor.length-1);
}

// Get And Sets
function setval(id,val){
document.getElementById(id).value = val;
}
function getval(id){
return document.getElementById(id).value;
}
function getcheck(id){
return document.getElementById(id).checked;
}
function gettype(id){
return document.getElementById(id).type;
}
function getMultiple(ob){
ob = document.getElementById(ob);
selected = new Array();
for(var i = 0; i < ob.options.length; i++) if(ob.options[i].selected) selected.push(ob.options[i].value);
return selected;
}

/////////////////////
// ajax links hombres
/////////////////////

function getCatHom(cat){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX.');
		return;
	}

	xmlHttp.onreadystatechange = doGetCatHom;
	xmlHttp.open("POST","ajax/getCat.php?cat="+cat,true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader("Content-length", cat.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(cat);
}

function doGetCatHom(){ 

var lightbox = "<script>$(function() {$('#prod-hombres a').lightBox({fixedNavigation:'true',overlayBgColor: '#000000',overlayOpacity: 0.5,containerResizeSpeed: 450,txtImage: 'Imagen',txtOf: 'de'});});</script>";

	if (xmlHttp.readyState==4){
	var r = xmlHttp.responseText;
	var partido = r.split(",");
	var pedazo1 = partido[0];
	var pedazo2 = partido[1];
	$('#prod-hombres').fadeOut('slow', function() {
	$(this).html(pedazo2).fadeIn('slow');
	$('#lightbox').append(lightbox);
	});
	}
	$('#sub-nav-hom a').removeClass('on');
	$('#sub-nav-hom .'+pedazo1+' a').addClass('on');
}

/////////////////////
// ajax links hombres
/////////////////////

function getCatMujer(cat){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ('Tu explorador no soporta AJAX.');
		return;
	}

	xmlHttp.onreadystatechange = doGetCatMujer;
	xmlHttp.open("POST","ajax/getCatMujer.php?cat="+cat+"&sexo=mujer",true);
	xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlHttp.setRequestHeader("Content-length", cat.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(cat);
}

function doGetCatMujer(){ 

var lightbox_muj = "<script>$(function() {$('#prod-mujer a').lightBox({fixedNavigation:'true',overlayBgColor: '#000000',overlayOpacity: 0.5,containerResizeSpeed: 450,txtImage: 'Imagen',txtOf: 'de'});});</script>";

	if (xmlHttp.readyState==4){
	var r = xmlHttp.responseText;
	var partido = r.split(",");
	var pedazo1 = partido[0];
	var pedazo2 = partido[1];
	$('#prod-mujer').fadeOut('slow', function() {
	$(this).html(pedazo2).fadeIn('slow');
	$('#lightbox-muj').append(lightbox_muj);
	});
	}
	$('#sub-nav-muj a').removeClass('on');
	$('#sub-nav-muj .'+pedazo1+' a').addClass('on');
}

