$(document).ready(function(){
	$('.fsecs').lightBox();
	$('.fsecs').click(function(){
		$('#lightbox-image-details-currentNumber').remove();
	});
	$('#bg-error').animate({opacity:0.7});
	$('.fsecs[title=CuyArts]').mouseover(function(){
		var img = $(this).attr('name');
		$('#fpri').attr('src','images/productos/' + img);
	}).mouseout(function(){
		var img = $('#hfpri').val();
		$('#fpri').attr('src',img);
	});
	$('#addbag').click(function(){
		var objbtn = this; 
		$(objbtn).css('disabled','disabled');
		var id = $('#idpro').val();
		var val_attr='';
		var atributo_opc=document.getElementById('sle_atributo');
		if(atributo_opc!=null)val_attr=atributo_opc.value;
		$.ajax({
			type:"POST",
			url:"request/addBag.php",
			data:{id:id,id_atributo:val_attr},
			success:function(resp){
				var jobj = eval(resp);
				$(objbtn).css('disabled','');
				if(jobj.error == 1){
					showError({
						msg:jobj.mensaje,
						title:'Error',
						cancel:false
					});
				}else{
					showError({
						msg:jobj.mensaje,
						title:'Mensaje',
						cancel:false
					});
				}
			}
		});
		return false;
	});
	$('#envFriend').click(function(){
		$('#ibox_content').css('background','none');
	});
	/* METODOS ERROR*/
	$('#btnacept,#btncancel').click(function(){
		var nom = $(this).attr('id');
		$('#box-error').fadeOut('fast');
		$('#bg-error').fadeOut('fast',function(){
			error = new btnError();
			if(nom=='btnacept'){
				error.accept();
			}else{
				error.cancel();
			}
		});
	});
	$('#btncancel').hide();
	var e = btnError.prototype;
	e.cancel = function(){}
});
function showError(obj){
	var pageSize = ___getPageSize();
	var error = eval(obj);
	var positionObj = __getPositionCenter(pageSize);
	var e = btnError.prototype;
	$('#bg-error').css({width:pageSize[0],height:pageSize[1]});
	$('#box-error').css({top:positionObj[0],left:positionObj[1]});
	$('#msg-error').text(error.msg);
	$('#title-error').text(error.title);
	if(error.btnAceptar !== undefined){
		e.accept = error.btnAceptar;
	}else{
		e.accept = function(){}
	}
	if(error.btnCancel !== undefined){
		e.cancel = error.btnCancel;
	}else{
		e.cancel = function(){}
	}
	if(error.cancel){
		$('#btncancel').show();
	}
	$('#box-error,#bg-error').fadeIn('slow');
}
function btnError(){
	$('#btncancel').hide();
}
function printProducto(){
	print( );
}
function __getPositionCenter(pageSize){
	var widthObj = $('#box-error table').css('width').replace('px','');
	var heightObj = $('#box-error table').css('height').replace('px','');
	var leftContent = (pageSize[0]/2) - (widthObj/2);
	var topContent = (pageSize[1]/2) - (heightObj/2);
	return new Array(topContent,leftContent);
}
function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
};
