// JavaScript Document

window.name="jopssearch";

function showpop(popID,popURL){
						   		   
	//When you click on a link with class of poplight and the href starts with a # 

				
		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value

		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="img11/close.png" class="btn_close" title="Close Window" alt="Close" /></a>');
		
		//Define margin for center alignment (vertical + horizontal) - we add 80 to the height/width to accomodate for the padding + border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;
		
		//Apply Margin to Popup
		$('#' + popID).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer 
		
}


function closepop(){
$('#fade, a.close').remove();
$('#fade , .popup_block').hide();
}


var lightbox = new function() {
	
	this.lbOpened = $.cookie('stateLBX');
	

	if (this.lbOpened == null) this.lbOpened = false;
	else if (this.lbOpened == 'show') {
		this.lbOpened = true;
	} else {
		this.lbOpened = false;
	}


	// shows lightbox
	this.toggleLBX = function() {
		if (this.lbOpened) {
			this.hideLBX();
		} else {
			this.showLBX();
		}
		
		if(this.moveTitleToolitpAfterResize){
			this.moveLightboxTitleToolitip();
		}
	}
	this.showLBX = function() {
		$.cookie('stateLBX', 'show', {expires: 365, path: '/'});
		$('#lbxContent').show();
		$('#lbMinimize').show();
		$('#lbMaximize').hide();
			
	//	$('#lbMinimize').removeClass('lbShow');
	//	$('#lbMinimize').addClass('lbMinimize');
	//	$('#lbMaximize').removeClass('lbRestore');
	//	$('#lbMaximize').addClass('lbMaximize');
		this.lbOpened = true;
		//this.lbMaximized = false;
	//	this.setMainDivHeight();
	}
	// hides lightbox
	this.hideLBX = function() {
		$.cookie('stateLBX', 'hide', {expires: 365, path: '/'});
		$('#lbxContent').hide();
		$('#lbMinimize').hide();
		$('#lbMaximize').show();
		//$('#lbMinimize').removeClass('lbMinimize');
		//$('#lbMinimize').addClass('lbShow');
		this.lbOpened = false;
	}
	
	
	this.setState = function() {
		if (!this.lbOpened)
			this.hideLBX();
	
	}
	
	this.addtolbx = function(cod,brand,path,tipo,crc32) {
	$('#lbxlog').html("Se agrego el item #"+cod+" a su lightbox");
		this.addtolbxphp(cod,0,0,5,tipo,crc32);
	
	}
	

	
	
	this.addtolbxphp=function(v1,v2,v3,v4,v5,crc32) {
				dataString="v1="+v1+"&v2="+v2+"&v3="+v3+"&v4="+v4+"&v5="+v5+"&crc32="+crc32;
				
				$.ajax({
				  type: "POST",
				  url: "searchLib/lbxfunctions.php",
				  data: dataString,
				  success: function(datos) {
					$('#lbxthumb').html(datos);
					
					//$('#contact_form').html("<div id='message'></div>");
					//$('#sendMsg').html("La solicitud ha sido enviada. En breve nos pondremos en contacto con usted.")
					//.append("<p>We will be in touch soon.</p>")

					}
				 });
	
	} 
	
	
	this.deltolbxphp=function(v1,v2,v3,v4,v5) {
				dataString="v1="+v1+"&v2="+v2+"&v3="+v3+"&v4="+v4+"&v5="+v5;
				
				$('#lbx'+v1).remove();
				$.ajax({
				  type: "POST",
				  url: "searchLib/lbxfunctions.php",
				  data: dataString,
				  success: function(datos) {
					
			
					//$('#contact_form').html("<div id='message'></div>");
					//$('#sendMsg').html("La solicitud ha sido enviada. En breve nos pondremos en contacto con usted.")
					//.append("<p>We will be in touch soon.</p>")

					}
				 });
	
	} 
	
	
		this.rank=function(v1,v2,v3,v4,v5) {
				dataString="v1="+v1+"&v2="+v2+"&v3="+v3+"&v4="+v4+"&v5="+v5;
				
				
				$.ajax({
				  type: "POST",
				  url: "searchLib/jopsFunctions.php",
				  data: dataString,
				  success: function(datos) {
					alert(datos);
			
					//$('#contact_form').html("<div id='message'></div>");
					//$('#sendMsg').html("La solicitud ha sido enviada. En breve nos pondremos en contacto con usted.")
					//.append("<p>We will be in touch soon.</p>")

					}
				 });
	
	} 

	
	
			this.newlbx=function(v1,pop,v2) {
				
				
				
				dataString="v1="+v1+"&v4="+v2;
				
			
				$.ajax({
				  type: "POST",
				  url: "searchLib/lbxfunctions.php",
				  data: dataString,
				  success: function(datos) {
				$('#lbxthumb').html(datos);
				lightbox.setMenu();
				closepop();
			
				
					}
				 });
	
		} 
		
		
		
		this.editlbx=function(v1,v2,v3,v4,v5) {
				
				
				
				dataString="v1="+v1+"&v2="+v2+"&v3="+v3+"&v4="+v4;
				
			
				$.ajax({
				  type: "POST",
				  url: "searchLib/lbxfunctions.php",
				  data: dataString,
				  success: function(datos) {
				
				window.location.replace("lightbox.php?lbxid="+v5)	;	
				closepop();
			
				
					}
				 });
	
		} 
		
		
		
		
		
		this.sendlbx=function(v2,v3,v4,pop,v5){


			dataString="v2="+v2+"&v3="+v3+"&v4="+v4;

				$.ajax({
				  type: "POST",
				  url: "searchLib/lbxfunctions_send.php",
				  data: dataString,
				  success: function(datos) {
				$('#lbxsendalert').html("<h1>El lightbox  se ha enviado correctamente</h1>");
				closepop();
			
				
					}
				 });
	
		
		}


		
		
		
		
		this.change=function(s) {
				var s2= s[s.selectedIndex].value;
				dataString="v1="+s2;
				
				$.ajax({
				  type: "POST",
				  url: "searchLib/lbxmenu.php",
				  data: dataString,
				  success: function(datos) {
				lightbox.addtolbxphp(0,0,0,0,0,0);
				$('#lbxmenu').html(datos);
					}
				 });
	
		} 
		
		this.changenoajax=function(s) {
				var s2= s[s.selectedIndex].value;
			
				window.location.replace("lightbox.php?lbxid="+s2)	;
				
				

	
		} 
	
	
	
	
	
		this.setMenu=function() {
				dataString="";
				$.ajax({
				  type: "POST",
				  url: "searchLib/lbxmenu.php",
				  data: dataString,
				  success: function(datos) {
					$('#lbxmenu').html(datos);

					}
				 });
	
	} 


}


$(document).ready(function () {



//DRAG 

			$('.leche').draggable({
			
		    	appendTo: "body",
				revert: "invalid",
				helper:'clone',
				start:function(event,ui){
				 $('.tipimg').hide();
		
					//$(this).draggable('helper').css('z-index',10);
					
				},
				stop:function(event,ui){
		
				},
				drag:function(event,ui){
		 $('.tipimg').hide();
				}
			});
		
		
					$('#lbxthumb').droppable({
				
				drop:function(event,ui){
		
					 $('.tipimg').hide();
				
					
				lightbox.addtolbx(ui.draggable.attr('atr1'),ui.draggable.attr('atr2'),'',1,ui.draggable.attr('atr3'));
					
				
					//var price = $(source).find('p:eq(1)').html();
					//addProduct(name, parseFloat(price.split('$')[1]));
				}
			});




//

	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
	  	$('#fade , .popup_block').fadeOut(function() {
			$('#fade, a.close').remove();  
	}); //fade them both out
		
		return false;
	});



	var timer; 





 $(".tip_trigger_img").hover(
	  
		 function(e){
		 $('.tipimg').hide();
		 tipI = $(this).find('.tipimg');
		 par=$(this);
		 evento=e;
	//	window.willhide = setTimeout(function() {
    
	if(timer) {                        
	 clearTimeout(timer);                        
	  timer = null                
	   } 
	   
	   
	timer = setTimeout(function() { 
	$('#toltipIMG').remove();
	$('#toltipIMGA').remove();
	
	if(par.attr('MediaType')==3)
	{
		//tipI.flash('wifget.swf');
		
				tipI.flash(
			{
				swf: 'footageplayer.swf',
				width: 320,
				height: 240,
				play: false,
				flashvars: {
					url: par.attr('rel')
				}
			}
		);

		wF = 320;
		hF = 240;
		wO=180;
		hO=135;
		if(wO<hO) {
		wF = (hF / hO) * wO;
		
		} else {
		hF= (wF / wO) * hO;
		
		}
		
		tipI.css({"height": hF, "width": wF});
		tipI.show();
		
		var tipVisX = $(window).width() - 20 - wF;
        var tipVisY = $(window).height() - 20 - hF;
		
		tipI.css({  "margin-left": 30});	
	
		if((tipI.position().left+ wF + 20) > ($(window).width() - 20) ) {
	
			tipI.css({  "margin-left": -(wF + wO + 30)});	
		}
		

		
		
		if((tipI.offset().top+ hF -$(document).scrollTop()) > ($(window).height()) ) {
	
			var ytop=(tipI.offset().top -$(document).scrollTop() + hF ) - ($(window).height()) + 20;
	
			tipI.css({  "margin-top": -(ytop)});	
		}
		
	}
	
	if(par.attr('MediaType')==1 || par.attr('MediaType')==5 || par.attr('MediaType')==2 )
	{
	

	

		tipI.append('<a id="toltipIMGA"><img id="toltipIMG"  /></a>')
       	thumb = par.find('#itemThumb');
		
	      //Absolute position the tooltip according to mouse position
       // tip.css({  top: mousey, left: mousex });
    	
		wF = 550;
		hF = 550;
		var pre = new Image(); 
		
		
		
	if(1==1) {
		

		//$(pre).load(function(){
		//alert($(image1).attr("width"));
		//$(this).css({"height": 'auto', "width": 300});
		
		$(pre).attr('src', thumb.attr('src'));
		
		wO=$(pre).attr("width");
		hO=$(pre).attr("height");
		if(wO<hO) {
		wF = (hF / hO) * wO;
		
		} else {
		hF= (wF / wO) * hO;
		
		}
		//tip.css({  "margin-top": -hO, " margin-left": -(wF-(wO/2))});
		
		//tipI.css({  "margin-top": -(hO+10), "margin-left": -(wF-(wO/2))});
	
	
			
		$('#toltipIMG').css({"height": hF, "width": wF});
        $('#toltipIMG').attr('src',  thumb.attr('src'));
		//alert($("#toltipIMG").parent().attr('id'));
		$("#toltipIMG").parent().attr('href', thumb.parent().attr('href'));
		
		tipI.show();
		
			var tipVisX = $(window).width() - 20 - wF;
        var tipVisY = $(window).height() - 20 - hF;
		
		tipI.css({  "margin-left": 30});	
	
		if((tipI.position().left+ wF + 20) > ($(window).width() - 20) ) {
	
			tipI.css({  "margin-left": -(wF + wO + 30)});	
		}
		

		
		
		if((tipI.offset().top+ hF -$(document).scrollTop()) > ($(window).height()) ) {
	
			var ytop=(tipI.offset().top -$(document).scrollTop() + hF ) - ($(window).height()) + 20;
	
			tipI.css({  "margin-top": -(ytop)});	
		}
   
  	//}).attr('src', par.attr('rel'))
		
		 // }).attr('src',  thumb.attr('src'))
	
		}
	
	
	if(par.attr('rel')) {
		
			var zoom = new Image(); 
			
			$(zoom).load(function(){
			
			$('#toltipIMG').attr('src',  par.attr('rel'));
			}).attr('src',  par.attr('rel') )
	
		}
		
		
		}
		
		
		
		 //Show tooltipthi
},500);
   
   
    }, function(e) {
		clearTimeout(timer);
	$('#toltipIMG').remove();
		$('#toltipIMGA').remove();
     tipI.hide(); //Hide tooltip
		
	
	}
	);





});


function imagedetail(url,name)
{
var nameop=name;
nameop = nameop.replace("-","");
nameop = nameop.replace("-","");
nameop = nameop.replace("-","");
nameop = nameop.replace(".",""); 
window.open("detailphoto.php?"+url,nameop,"width=950,height=600, top=0,left=0, location=no,scrollbars=1,fullscreen=0,directories=no,toolbar=no,menubar=no,status=no,titlebar=no,channelmode=0,resizable=1");


}
function cddetail(url,name)
{
var nameop=name;
nameop = nameop.replace("-","");
nameop = nameop.replace("-","");
nameop = nameop.replace("-","");
nameop = nameop.replace(".",""); 
window.open("detailcd.php?"+url,nameop,"width=950,height=600, top=0,left=0, location=no,scrollbars=1,fullscreen=0,directories=no,toolbar=no,menubar=no,status=no,titlebar=no,channelmode=0,resizable=1");


}
function toogle(id) { 


if(document.getElementById(id).style.display=="block") {
document.getElementById(id).style.display = 'none';
} else {
document.getElementById(id).style.display = 'block';  
}

}



function changeOrden(s,searchVariables) {
				var s2= s[s.selectedIndex].value;
			
				window.location.replace("search.php?"+searchVariables+"&pagina=1&orden="+s2)	;
	
		} 


