$.fn._blank = function() {

	function clickHandler(e) {

		if (e.ctrlKey || e.shiftKey || e.metaKey)
			return;

		var w = window.open(this.href, '_blank', 'top=0,left=0,width=230,height=350');
		if (w && !w.closed) {
			w.focus();
			e.preventDefault();
		}
	}

	this
		.filter('a[@href]')
		.bind('click', clickHandler);

	return this;

}





$(document).ready( function(){ 
		
		$('.atras').click(function(){
		    history.back();
		    return false;
		})
		
    $("a[rel*='external']").click(function(){
         this.target = "_blank";
     });
     
     
     // $("a[rel*='nota']")._blank();
     
     $('#servicios_tabs').tabs();
     
     	
			
     
     
     /*
      
     */
     
    $('.focusb').addClass("idleField");
    
   	$('.focusb').focus(function() {
   		$(this).removeClass("idleField").addClass("focusField");
           if (this.value == this.defaultValue){
           	this.value = '';
       	}
        if(this.value != this.defaultValue){
   	    	this.select();
        }
    });
    
     $('.focusb').blur(function() {
     	$(this).removeClass("focusField").addClass("idleField");
      // if ($.trim(this.value == '')){
        if (this.value == ''){
         	this.value = (this.defaultValue ? this.defaultValue : '');
     	}
     });
     


     
     /*
      
     */
     

     $(".center").center();
     
      $(".centerH").center({
        vertical: false
      });
    
     
     $('.paging a, .nav a').each(function() {
         var href = $(this).attr('href');
         $(this).attr('href', href+'#lista');
     });
     
            
     $('#menu_especie').jScrollPane({scrollbarWidth:20, scrollbarMargin:10});
     $('#menu_criadero').jScrollPane({scrollbarWidth:20, scrollbarMargin:10});
     
     function detectar_ie6win() {
       var userAgent = navigator.userAgent.toLowerCase();
       if (userAgent.indexOf('windows') != -1 && userAgent.indexOf('msie 6')!=-1 ) {
         return true;
       }
     }
     
     if(!detectar_ie6win()){
       $('.concursos .bases div').jScrollPane({scrollbarWidth:20, scrollbarMargin:10});
       $('.concursos .ficha div').jScrollPane({scrollbarWidth:20, scrollbarMargin:10});
     }
     
     
     var userAgent = navigator.userAgent.toLowerCase();
     
     if (userAgent.indexOf('msie') != -1) {
       $('div.interesCont').corner('50px');
       $('div.iecor').corner('10px');
       
     }
     
     


     //      
      
      $('.nota').click(function(){	    
        $("#nota").modal(
        {    containerCss:{
          		backgroundColor:"#077647",
          		borderColor:"#077647",
          		height:500,
          		padding:0,
          		width:415
        	    },
        	     overlayClose:true,
        	     closeHTML: "<a href='#'>(x)</a>"
             
            
        	}
      	);
      	return false;
      });
      
      
      
      
      
      // $('#magazine .imagen').click(function(){
      //   $("body").append('<div class="overlay"></div>');
      //  $('.overlay').css('height', $(document).height()+100);
      //      
      //     $("#magazine div.imgBig").modal(
      //     {    containerCss:{
      //          backgroundColor:"#47AA42",
      //          borderColor:"#47AA42",
      //          width: 505,
      //          padding:20,
      //          height: $('#magazine div.imgBig img').attr('height')
      //          },
      //           closeHTML: "<a href='#'>(x)</a>",
      //           onClose:function() {
      //               $.modal.close();
      //               $('.overlay').remove();
      //             }
      //      
      //     
      //      }
      //    );
      //        return false;
      // });
      
      $('#promociones .imagen').click(function(){	 
        $("body").append('<div class="overlay"></div>');
      	$('.overlay').css('height', $(document).height()+100);
         
          $("#promociones div.imgBig").modal(
          {    containerCss:{
            		backgroundColor:"#47AA42",
            		borderColor:"#47AA42",
            		width: 505,
            		padding:25,
            		height: $('#promociones div.imgBig img').attr('height')
          	    },
          	     closeHTML: "<a href='#'>(x)</a>",
          	        onClose:function() {
              	       $.modal.close();
              	       $('.overlay').remove();
              	     }
           
          
          	}
        	);
    		return false;
      });  
      
      // catalogo
      $('#catalogoAmpliada').hide();
      
      $('.imgCatalogo').click(function(){	 
          $("#catalogoAmpliada").modal(
            {
              overlayClose:true,
          	overlay:80,
          	overlayCss: {backgroundColor:"#fff"},
          	 containerCss:{
              		backgroundColor:"#47AA42",
              		borderColor:"#47AA42",
              		padding:25
            	    },
            closeHTML: "<a href='#'>(x)</a>",
          	onClose:function() {
      	       $.modal.close();
      	     }
          }
          );
      	return false;
      });
      
      
      
      // 
      // 
      //
       $(".audio").click(function(){
    		player();
    	});

    	
      

});

/*
  
*/

// window.onload = function() {
//    player();
// }

function player() {
		var newwindow = window.open("",'ply','width=160,height=50,left=0,top='+(screen.height+10)+',scrollbars=no');
		newwindow.resizeTo(160,50);
		newwindow.moveTo(0,screen.height);
		if (window.focus) {newwindow.focus()}


    var playerpath = 'files/player/'; 
		var filename = "files/player/audio.mp3";

		var options = {
			"filepath": "files/player/",										
			"backcolor": "C5E29F",									
			"forecolor": "075530",								
			"width": "150",										
			"repeat": "true",										
			"volume": "100",										
			"autoplay": "true",								
			"showdownload": "false",								
			"showfilename": "false"								
		};

		var mp3html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
		mp3html += '<html xmlns="http://www.w3.org/1999/xhtml">';
		mp3html += '<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Guacamole mascotas</title>';
		mp3html += '<style>body {margin: 0 0 0 0;padding: 0;background: #C5E29F;color: #fff;font-size:90%}\n #player {width: 110px;height: 40px;display: block;padding: 0px 0 0 5px;}</style>';
		mp3html += '</head><body><div id="player">';

		mp3html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
		mp3html += 'width="' + options.width + '" height="40" ';
		mp3html += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">';
		mp3html += '<param name="movie" value="' + playerpath + 'singlemp3player.swf?';
		mp3html += 'showDownload=' + options.showdownload + '&file=' + filename + '&autoStart=' + options.autoplay;
		mp3html += '&backColor=' + options.backcolor + '&frontColor=' + options.forecolor;
		mp3html += '&repeatPlay=' + options.repeat + '&songVolume=' + options.volume + '" />';
		mp3html += '<param name="wmode" value="transparent" />';
		mp3html += '<embed wmode="transparent" width="' + options.width + '" height="40" ';
		mp3html += 'src="' + playerpath + 'singlemp3player.swf?'
		mp3html += 'showDownload=' + options.showdownload + '&file=' + filename + '&autoStart=' + options.autoplay;
		mp3html += '&backColor=' + options.backcolor + '&frontColor=' + options.forecolor;
		mp3html += '&repeatPlay=' + options.repeat + '&songVolume=' + options.volume + '" ';
		mp3html += 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		mp3html += '</object>';

		mp3html += '</div>';
		mp3html += '</body></html>';

		newwindow.document.write(mp3html);
    newwindow.document.close();

		return false;
	}


/*
  
*/
// $('.iecorner').corner();



/*
  iframe height
*/

function doIframe(){
	o = document.getElementsByTagName('iframe');
	for(i=0;i<o.length;i++){
		if (/\bautoHeight\b/.test(o[i].className)){
			setHeight(o[i]);
			addEvent(o[i],'load', doIframe);
		}
	}
}

function setHeight(e){
	if(e.contentDocument){
		e.height = e.contentDocument.body.offsetHeight + 35;
	} else {
		e.height = e.contentWindow.document.body.scrollHeight;
	}
}

function addEvent(obj, evType, fn){
	if(obj.addEventListener)
	{
	obj.addEventListener(evType, fn,false);
	return true;
	} else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
	return r;
	} else {
	return false;
	}
}

if (document.getElementById && document.createTextNode){
 addEvent(window,'load', doIframe);	
}



