// JavaScript Document
jQuery.fn.extend({
   haccordion: function(params){
      var jQ = jQuery;
      var params = jQ.extend({speed:400,headerclass:"header",contentclass:"content",contentwidth:200,idPanel:""},params);
      return this.each(function(){
         jQ("."+params.headerclass,this).hover(function(){
            var p = jQ(this).parent()[0];
		    params.idPanel = this.id;
            if (p.opened != null && p.opened.id != params.idPanel){ //diferente de undefined
               jQ(p.opened).next("div."+params.contentclass).animate({width: "0px"},300);//alert(p.opened.id);
			   jQ("#divSpaceIni").css("display", "none");
            }
            p.opened = this;//alert(p.opened.id);	    
		    if(params.idPanel == p.opened.id){
			   //setTimeout("jQ(this).next('div.'+params.contentclass).animate({width:params.contentwidth+'px'},params.speed);",2000);
               jQ(this).next('div.'+params.contentclass).animate({width:params.contentwidth+'px'},params.speed);
		    }
         });
      });
	  
   }
});
//$(function(){ $(".haccordion").haccordion(); });
//$(".content").css("display", "block");
//$(".content").css("width", "135px" );
/**********************************************************************************************************************************************/
/*@license 
 * jQuery Tools 1.2.2 Scrollable - New wave UI design
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * http://flowplayer.org/tools/scrollable.html
 * Since: March 2008
 * Date:  Wed May 19 06:53:17 2010 +0000 
 */
(function($){ 
	// static constructs
	$.tools = $.tools || {version: '1.2.2'};
	$.tools.scrollable = {	
		conf: {	
			activeClass: 'active',
			circular: false,
			clonedClass: 'cloned',
			disabledClass: 'disabled',
			easing: 'swing',
			initialIndex: 0,
			item: null,
			items: '.items',
			keyboard: true,
			mousewheel: false,
			next: '.next',   
			prev: '.prev', 
			speed: 2000,
			vertical: false,
			wheelSpeed: 0
		} 
	};
	// get hidden element's width or height even though it's hidden
	function dim(el, key) {
		var v = parseInt(el.css(key), 10);
		if (v) { return v; }
		var s = el[0].currentStyle; 
		return s && s.width && parseInt(s.width, 10);	
	}

	function find(root, query) { 
		var el = $(query);
		return el.length < 2 ? el : root.parent().find(query);
	}
	
	var current;		
	
	// constructor
	function Scrollable(root, conf) {   
		// current instance
		var self = this, 
			 fire = root.add(self),
			 itemWrap = root.children(),
			 index = 0,
			 vertical = conf.vertical;
			 
		if (!current) { current = self; } 
		if (itemWrap.length > 1) { itemWrap = $(conf.items, root); }
		
		// methods
		$.extend(self, { getConf:function(){return conf;},			
			getIndex:function(){return index;}, 
            getSize:function(){return self.getItems().size();},
			getNaviButtons:function(){return prev.add(next);},
			getRoot:function(){return root;},	
			getItemWrap:function(){return itemWrap;},			
			getItems:function(){return itemWrap.children(conf.item).not("." + conf.clonedClass);},							
			move:function(offset, time){return self.seekTo(index + offset, time);},			
			next: function(time){return self.move(1, time);	},			
			prev: function(time){return self.move(-1, time);},			
			begin: function(time){return self.seekTo(0, time);},			
			end: function(time){return self.seekTo(self.getSize() -1, time);},				
			focus:function(){current = self; return self;},			
			addItem: function(item){
				item = $(item);
				if (!conf.circular){itemWrap.append(item);} 
				else{
					$(".cloned:last").before(item);
					$(".cloned:first").replaceWith(item.clone().addClass(conf.clonedClass)); 						
				}
				fire.trigger("onAddItem", [item]);
				return self;
			},
			
			/* all seeking functions depend on this */		
			seekTo: function(i, time, fn) {	
				// avoid seeking from end clone to the beginning
				if (conf.circular && i === 0 && index == -1 && time !== 0) { return self; }
				// check that index is sane
				if (!conf.circular && i < 0 || i > self.getSize() || i < -1) { return self; }
				var item = i;
				if(i.jquery) { i=self.getItems().index(i); }else{ item=self.getItems().eq(i); }  
				// onBeforeSeek
				var e = $.Event("onBeforeSeek"); 
				if (!fn){
					fire.trigger(e, [i, time]);				
					if (e.isDefaultPrevented() || !item.length) { return self; }			
				}  
	
				var props = vertical ? {top: -item.position().top} : {left: -item.position().left};  
				index = i;
				current = self;  
				if (time === undefined) { time = conf.speed; }   
				
				itemWrap.animate(props, time, conf.easing, fn || function() { 
					fire.trigger("onSeek", [i]);		
				});	 
				return self; 
			}					
		});
				
		// callbacks	
		$.each(['onBeforeSeek', 'onSeek', 'onAddItem'], function(i, name) {
			// configuration
			if ($.isFunction(conf[name])) { 
				$(self).bind(name, conf[name]); 
			}
			self[name] = function(fn) {
				$(self).bind(name, fn);
				return self;
			};
		});  
		
		// circular loop
		if(conf.circular){
			var cloned1 = self.getItems().slice(-1).clone().prependTo(itemWrap),
				 cloned2 = self.getItems().eq(1).clone().appendTo(itemWrap);
				
			cloned1.add(cloned2).addClass(conf.clonedClass);
			self.onBeforeSeek(function(e, i, time) {
		
				if (e.isDefaultPrevented()) { return; }
				/* 1. animate to the clone without event triggering
				   2. seek to correct position with 0 speed*/
				if (i == -1) {
					self.seekTo(cloned1, time, function(){self.end(0);});          
					return e.preventDefault();
				}else if(i == self.getSize()){
					self.seekTo(cloned2, time, function(){self.begin(0);});	
				}
			});
			// seek over the cloned item
			self.seekTo(0, 0);
		}
		// next/prev buttons
		var prev = find(root, conf.prev).click(function() { self.prev(); }),
			 next = find(root, conf.next).click(function() { self.next(); });	
		
		if (!conf.circular && self.getSize() > 1) {
			self.onBeforeSeek(function(e, i) {
				prev.toggleClass(conf.disabledClass, i <= 0);
				next.toggleClass(conf.disabledClass, i >= self.getSize() -1);
			}); 
		}
		// mousewheel support
		if (conf.mousewheel && $.fn.mousewheel) {
			root.mousewheel(function(e, delta)  {
				if (conf.mousewheel) {
					self.move(delta < 0 ? 1 : -1, conf.wheelSpeed || 50);
					return false;
				}
			});			
		}
		
		if(conf.keyboard){
			$(document).bind("keydown.scrollable", function(evt) {
				// skip certain conditions
				if (!conf.keyboard || evt.altKey || evt.ctrlKey || $(evt.target).is(":input")) { return; }
				// does this instance have focus?
				if (conf.keyboard != 'static' && current != self) { return; }					
				var key = evt.keyCode;			
				if (vertical && (key == 38 || key == 40)) {
					self.move(key == 38 ? -1 : 1);
					return evt.preventDefault();
				}				
				if (!vertical && (key == 37 || key == 39)) {					
					self.move(key == 37 ? -1 : 1);
					return evt.preventDefault();
				}	  			
			});  
		}	
		// initial index
		$(self).trigger("onBeforeSeek", [conf.initialIndex]);
	} 
	// jQuery plugin implementation
	$.fn.scrollable = function(conf) { 		
		// already constructed --> return API
		var el = this.data("scrollable");
		if (el) { return el; }		 
		conf = $.extend({}, $.tools.scrollable.conf, conf); 
		this.each(function() {			
			el = new Scrollable($(this), conf);
			$(this).data("scrollable", el);	
		});	
		return conf.api ? el: this; 		
	};			
})(jQuery);
/*============================================[ INSTANCIANDO ]============================================*/
$( function(){ $(".scrollable").scrollable({ vertical: true, mousewheel: true }); } );

var DIR = "top";
var MOV = true;
var nextTo = function(){
   var api = ( $(".scrollable").data("scrollable")!=null ) ? $(".scrollable").data("scrollable") : false;   // API DE ESTE PLUGIN
   /*--------------------------------------------------------------------------------------------------*/				  
   if(MOV && api){
	  if(api.getIndex()<2 && DIR == "top"){ api.next(3000); } 
	  else{
		 if(api.getIndex()>0){ DIR = "dow"; api.prev(3000); }
		 else{ DIR = "top"; api.next(3000); }
	  }
   }
   //alert(MOV);
   //MOV==1;
}
//$(document).ready( function(){ setInterval("nextTo()",16000); } ); //MOVER ULTIMAS NOTICIAS

$(".prev").click( function(){ MOV = true; DIR = "dow"; } );
$(".next").click( function(){ MOV = true; DIR = "top"; } );

$(".item div").mouseout(  function(){ alert(MOV); } );
$(".item div").mouseover( function(){alert(MOV); } );
/*========================================================================================================*/
/**********************************************************************************************************************************************/
/**
 * @license 
 * jQuery Tools 1.2.2 Tabs- The basics of UI design.
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * http://flowplayer.org/tools/tabs/
 * Since: November 2008
 * Date:    Wed May 19 06:53:17 2010 +0000 
*/  
(function($) {
	// static constructs
	$.tools = $.tools || {version: '1.2.2'};
	$.tools.tabs = {
		conf: {
			tabs: 'a',
			current: 'current',
			onBeforeClick: null,
			onClick: null, 
			effect: 'default',
			initialIndex: 0,			
			event: 'click',
			rotate: false,
			// 1.2
			history: false
		},
		addEffect: function(name, fn){ effects[name] = fn; }	
	};
	
	var effects = {
		// simple "toggle" effect
		'default': function(i, done) { 
			this.getPanes().hide().eq(i).show();
			done.call();
		}, 
		/* configuration:
				- fadeOutSpeed (positive value does "crossfading")
				- fadeInSpeed*/
		fade: function(i, done) {			
			var conf = this.getConf(),            
				speed = conf.fadeOutSpeed,
				panes = this.getPanes();
			if(speed){ panes.fadeOut(speed); }else{ panes.hide(); }
			panes.eq(i).fadeIn(conf.fadeInSpeed, done);	
		},
		// for basic accordions
		slide: function(i, done){
			this.getPanes().slideUp(200);
			this.getPanes().eq(i).slideDown(400, done);			 
		}, 
		/*** AJAX effect */
		ajax: function(i, done)  {			
			this.getPanes().eq(0).load(this.getTabs().eq(i).attr("href"), done);	
		}		
	};   	
	
	var w;
	/** Horizontal accordion
	 * @deprecated will be replaced with a more robust implementation*/
	$.tools.tabs.addEffect("horizontal", function(i, done) {
		// store original width of a pane into memory
		if (!w) { w = this.getPanes().eq(0).width(); }
		// set current pane's width to zero
		this.getCurrentPane().animate({width: 0}, function() { $(this).hide(); });
		// grow opened pane to it's original width
		this.getPanes().eq(i).animate({width: w}, function() { 
			$(this).show();
			done.call();
		});
	});	

	function Tabs(root, paneSelector, conf) {
		var self = this, 
			 trigger = root.add(this),
			 tabs = root.find(conf.tabs),
			 panes = paneSelector.jquery ? paneSelector : root.children(paneSelector),			 
			 current;
		// make sure tabs and panes are found
		if (!tabs.length)  { tabs = root.children(); }
		if (!panes.length) { panes = root.parent().find(paneSelector); }
		if (!panes.length) { panes = $(paneSelector); }
		// public methods
		$.extend(this, {				
			click: function(i, e) {
				var tab = tabs.eq(i);
				
				if (typeof i == 'string' && i.replace("#", "")) {
					tab = tabs.filter("[href*=" + i.replace("#", "") + "]"); i = Math.max(tabs.index(tab), 0);
				}
		
				if (conf.rotate) {
					var last = tabs.length -1; 
					if (i < 0){ return self.click(last, e); }
					if (i > last){ return self.click(0, e); }						
				}
				
				if (!tab.length) {
					if(current >= 0){ return self; }
					i = conf.initialIndex;	tab = tabs.eq(i);
				}				
				// current tab is being clicked
				if (i === current) { return self; }
				// possibility to cancel click action				
				e = e || $.Event();
				e.type = "onBeforeClick";
				trigger.trigger(e, [i]);				
				if (e.isDefaultPrevented()) { return; }
				// call the effect
				effects[conf.effect].call(self, i, function() {
					// onClick callback
					e.type = "onClick";
					trigger.trigger(e, [i]);					
				});			
				// default behaviour
				current = i;
				tabs.removeClass(conf.current);	
				tab.addClass(conf.current);				
				return self;
			},
			getConf: function(){ return conf; },
			getTabs: function(){ return tabs; },
			getPanes: function(){ return panes;	},
			getCurrentPane: function(){ return panes.eq(current); },
			getCurrentTab: function(){ return tabs.eq(current);	},
			getIndex: function(){ return current; }, 
			next: function(){ return self.click(current + 1); },
			prev: function(){ return self.click(current - 1); }		
		});
		// callbacks	
		$.each("onBeforeClick,onClick".split(","), function(i, name){
			// configuration
			if ($.isFunction(conf[name])){ $(self).bind(name, conf[name]); }
			// API
			self[name] = function(fn){ $(self).bind(name, fn); return self;	};
		});

		if (conf.history && $.fn.history){ $.tools.history.init(tabs); conf.event = 'history'; }	
		// setup click actions for each tab
		tabs.each(function(i) { 				
			$(this).bind(conf.event, function(e){ self.click(i, e);	return e.preventDefault(); });			
		});
		// cross tab anchor link
		panes.find("a[href^=#]").click(function(e){ self.click($(this).attr("href"), e); }); 
		// open initial tab
		if (location.hash){ self.click(location.hash); } 
		else{
			if(conf.initialIndex === 0 || conf.initialIndex > 0){ self.click(conf.initialIndex); }
		}				
	}

	// jQuery plugin implementation
	$.fn.tabs = function(paneSelector, conf) {
		// return existing instance
		var el = this.data("tabs");
		if (el) { return el; }
		if ($.isFunction(conf)){ conf = {onBeforeClick: conf}; }
		// setup conf
		conf = $.extend({}, $.tools.tabs.conf, conf);		
		this.each(function(){				
			el = new Tabs($(this), paneSelector, conf);
			$(this).data("tabs", el); 
		});		
		return conf.api ? el: this;		
	};		
}) (jQuery); 
/*============================================[ INSTANCIANDO ]============================================*/
// perform JavaScript after the document is scriptable.
   $(function(){
	   $("ul.tabs").tabs( "div.panes > div", {effect: "fade", fadeOutSpeed: 500} );
   });// setup ul.tabs to work as tabs for each div directly under div.panes
/*========================================================================================================*/
function combDep(comb1,comb2){
   $(document).ready(function(){
      $(comb1).change(function(){
	     $(comb1+" option:selected").each(function(){ 
		    if($("option:selected",comb1).val()==0){
				$(comb2).attr("disabled",true);
				$(comb2).html("<option selected='selected' value='Todo'>Todo</option>"); 
			}else{
				$(comb2).attr("disabled",true); 
				$(comb2).html("<option selected='selected'>Espere...</option>"); 
				$(comb2).attr("disabled",false);                                                                     
			    $.post("editor/combos.php",{value:$(this).val(),
			                         comboDep:$(comb2).attr("name"),
								     comboPrin:$(comb1).attr("name")     /*alert("VER-->"+data);*//*$("#combo3").html("");*/
					 		    }, function(data){ $(comb2).html(data); }
				       );			
            }
		 });
	  })
   });
}

function envio(){
  if(document.buscador.ref.value.length>0){
	 location.href="editor/resultadoporinmueble.php?cod="+document.buscador.ref.value;
  }else{ document.buscador.ref.value="";document.buscador.submit(); }
}

function cambio(vec,vecT){
   $("#precio").html('');
   var sel=document.getElementById("precio");   //var cad="<option value='Todo' selected='selected'>Todo</option>";//for(var c=0;c<8;c++){var opt=sel.options[c];opt.parentNode.removeChild(opt);}
   sel.options[0] = new Option("Todo","Todo");
   for(var i=1;i<vec.length;i++){ sel.options[i] = new Option(vecT[i-1],vec[i-1]); }                                                                                          /*/3)+" US$ / S/."+vec[vec.length-1],"Mas");*/
   if(vec.length>1)
      sel.options[vec.length] = new Option("> mas de "+(vec[vec.length-1]/3)+" US$ \/ S\/."+vec[vec.length-1],"Mas");
}
function explo(){
  var nomNav=navigator.appName;
  if(nomNav.indexOf("Explorer")>-1){ var a = document.getElementById("menu");
     for(var i=0;i<a.length;i++){ a.target="_blank";}
  } 
}
/*===============================================================================================================*/
function setPagDef(pag){  //pagina POR defecto
   //var arrayPag = new Array("NOSOTROS","SERVICIOS","PROYECTOS","NOTICIAS","BLOGS","EVENTOS","CONTACTO","INICIO");
   var ul = document.getElementById("menuBar");
   var li = ul.getElementsByTagName("li");
   var a  = ul.getElementsByTagName("a");
   for(var index in a){
	   if(a[index]!=null && a[index].href!=null && a[index].href!=""){
		   var cadurl = a[index].href.split("/");
		   var thisPag = cadurl[cadurl.length-1];  //alert(thisPag);
		   if(pag==thisPag){
			   //alert();
			   li[index].onmouseover=null;
			   var imagBck = (thisPag=="index.php")?"2btnMenuLlorensF.gif":"2btnMenuLlorens.gif";
			   li[index].style.background="transparent url(imagllorens/"+imagBck+") no-repeat right";
			   //alert(li[index].style.background);
		   }
	   }
   }  
}
/*================================================================================================================*/
function change(id, ev){  //Efecto over y out en pestaņa "por estado"
   img1 = document.getElementById(id+"1");  img2 = document.getElementById(id+"2");
   if(ev=="over"){ 
	   img1.style.display = "none";  img2.style.display = "block";
   }else{ //ev=="out"
	   img1.style.display = "block"; img2.style.display = "none"; 
   } 
}
/*================================================================================================================*/
function popPdf(img,ancho,alto){ //v3.0 MUESTRA LA APLICACION DE REVISTA VIRTUAL
  var winprops="toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no,width=" + 
              ancho + ",height=" + alto + ",left=100,top=100";
  window.open(img,'fotomaq',winprops);
}
/*================================================================================================================*/


function verSioNo(){
	
	var objDivBanners = document.getElementById("divbanners");
	var divsBan = (objDivBanners) ? objDivBanners.getElementsByTagName("div") : [] ;
	var len = divsBan.length;
	
	do{
		num = Math.round(Math.random());
	}while(num>0 && num<=len);
	
	var ver = num*(len-1);
	
	//alert(ver);
				
			for(var i=0; i<len; i++ ){ 
				if(i==ver){	divsBan[i].style.display = "block"; }
				else{ divsBan[i].style.display = "none"; }
		
	}

}

$(document).ready( function(){
	setTimeout("verSioNo()",100);
	setInterval("verSioNo()",50000);
});

