// JavaScript Document
var last;
var pSearch = "/Modelo/getBuscador.aspx";
var banner = "xml/"

function getMapa(mapa) {
   document.getElementById("maping").src = "/swf/mapas/client/" + mapa + ".html";

   $(function () {

       $("#pdb").dialog({
           height: 800,
           width: 950,
           modal: true
       });
       $("#pdb").css('z-index', 2000);
       $('#content').hide();
   })

}

$(document).ready(function()
{

    $( "#pdb" ).bind( "dialogclose", function(event, ui) {
        $('#content').show();
});

  $.ajax({
    type: "GET",
    url: pSearch,
    dataType: "xml",
    success: parseXML
  });
  
	$('#configuration').change(function()
	{
		
	 	getDesc($(this).val())

    });	
    	
	imgFx();
	
	$("mapa").hide();
	$("pdb").hide();
	

});

function newMap()
{
$(function() {
	
		$("#mapa").dialog({
			height: 630,
			width: 630,
			modal: true
		});
	})
}

function newPdb()
{
$(function() {
	
		$("#pdb").dialog({
			height: 600,
			width: 780,
			modal: true
		});
	})
}

function imgFx()
{
	imagePreview();
	$('a img').each(function() {
	if(this.id != "p_link")
		{          
			$(this).hover(function() {
			$(this).stop().animate({ opacity: 0.5 }, 300);
			            
		},           
		function() {               
			$(this).stop().animate({ opacity: 1.0 }, 300);          
		});
	}
	});	
	
	
	
$(function() {  

    $('.rollover').hover(function() {  

        var currentImg = $(this).attr('src');  

        $(this).attr('src', $(this).attr('hover'));  

        $(this).attr('hover', currentImg); 
		
		$(this).css('cursor', 'hand');

    }, function() {  

        var currentImg = $(this).attr('src');  

        $(this).attr('src', $(this).attr('hover'));  

        $(this).attr('hover', currentImg);
		
		$(this).css('cursor', 'ponter');

    });  

});
	removeD();
}

function removeD()
	{
//Quitar lineas punteadas
theahrefs = document.getElementsByTagName("a");   
if (!theahrefs){return;}   
for(var x=0;x!=theahrefs.length;x++){   
theahrefs[x].onfocus = function stopLinkFocus(){this.hideFocus=true;}; 
}
//	
}

function showS(id)
{
	//alert(String(id));
	
	
	selected = '#' + id;
	
	if (selected != last )
	{
		$('.menu').hide();
		$(selected).show(600);
		last = selected;
	}
	else
	{
		$('.menu').hide(600);
		last = '';	
	}
}


function getDesc(selected)
{
	
	selected = selected.split(' ').join('');
	
	
	$('#comboCont').hide();
	$('#comboCont option').remove();
	//$('#comboCont').show(300);
	
	$.get(pSearch, function(xml) 
	{
		$(xml).find(selected).each(function()
		{
			$(this).find('type').each(function()
			{
				$('#cType').append('<option value="' + $(this).text() +'">' + $(this).text() + '</option>');
			})
			
		});
	});



}


function parseXML(xml)
{

    var cXML = $(xml);

	//fill market
	$(xml).find('market').each(function()
	{ 
		$(this).find('type').each(function(){
			
			$('#market').append('<option value="' + $(this).text() +'">' + $(this).text() + '</option>');	
		});
	}
	);
	
	//fill configuration
	$(xml).find('configuration').each(function()
	{ 
		$(this).find('type').each(function(){
			
			$('#configuration').append('<option value="' + $(this).text() +'">' + $(this).text() + '</option>');	
		});
	}
	);
	
	//fill model
	$(xml).find('model').each(function()
	{ 
		$(this).find('type').each(function(){
			
			$('#model').append('<option value="' + $(this).text() +'">' + $(this).text() + '</option>');	
		});
	}
	);
}

this.imagePreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 10;
		
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";
		
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ this.ovr +"' alt='Image preview' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});
};

function getMarket(valor, banner) {
    valor = valor.replace("&",".");
    document.location = "/group/"+ escape(valor) + "/%20swf%20Products%20Banner.swf";
}

function getProduct(valor, banner) {
    document.location = "/productos/" + escape(valor);
}
