// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function go()
{
	box = document.getElementById("brandselect");
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}

function goExhibition()
{
	box = document.getElementById("exhibitionselect");
	destination = box.options[box.selectedIndex].value;
	if (destination) location.href = destination;
}

function rate(rating,url) {

	document.getElementById("rating").innerHTML = '<div id="rating_loading">&nbsp;</div><div class="rating_messages"><h1>sending...</h1></div>';

	var args = [rating]; 
	var responseSuccess = function(o) {
		document.getElementById("rating").innerHTML = o.responseText;
		new Effect.Fade("thanksfade",{delay: 1.5, duration: 3.0});
	};

	var responseFailure = function(o){
		document.getElementById("rating").innerHTML = '<div id="rating_loading">&nbsp;</div><div class="rating_messages"><h1>error!</h1></div>';
	}

	var callback =
	{
	  success:responseSuccess,
	  failure:responseFailure,
	  argument:args
	};

	var showStatus = undefined;
	var sUrl = url + rating;
	YAHOO.util.Connect.initHeader('Accept-Charset','UTF-8');
	var transaction = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, null); 
	
}

function showcaseswitch(container,url,trigger) {
	for (i=1;i<20;i++) {
		if (document.getElementById('showcase' + i)) {
			//document.getElementById('showcase' + i).style.backgroundColor = '#8269DB'; 
			document.getElementById('showcase' + i).className = 'picture_buttons'; 
		}
	}
	//document.getElementById('showcase' + trigger).style.backgroundColor = '#666';
	document.getElementById('showcase' + trigger).className = 'picture_buttons_selected'; 
	document.getElementById(container).style.backgroundImage = "url(" + url + ")";
	startIn = trigger - 1;
}

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; 
 } 
}


function alterInput(oI,oT,vT,nF) {
  if(!oI || !oI.parentNode || (oT.length<4) || 
    !document.getElementById || !document.createElement) return;
  var nE = document.createElement('input');
  nE.className = 'tinytext';
  nE.type = oT;
  if(oI.name) nE.name = oI.name;
  if(oI.id) nE.id = oI.id;
  nE.onfocus = function() {
    if(this.hasFocus) return;
    var nE = alterInput(this,'password',
      (this.value.toLowerCase()=='password')?'':this.value);
    if(nE) nE.hasFocus=true;
  }
  nE.onblur = function() {
    if(this.hasFocus)
    if(this.value=='' || this.value.toLowerCase()=='password') {
      alterInput(this,'text','password',true);
    }
  }
  nE.hasFocus=false;
  oI.parentNode.replaceChild(nE,oI);
  if(vT) nE.value = vT;
  if(!nF || typeof(nF)=='undefined') {
    window.tE = nE;
    setTimeout("tE.hasFocus=true;tE.focus();",1);
  }
  return nE;
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

function mapita() {

	if (vallerylanguage == "en") {
  	var WINDOW_HTML = '<div style="font-size: 11px; font-family: Helvetica, Arial; color:#666; width: 210px; padding-right: 10px"><strong>Vallery:</strong><br /><br />We are open tuesdays thru saturdays from 11 to 14 and 17 to 20<br /><br />Calabria, 85<br />08015 Barcelona<br />Spain</div>';
	} else {
  	var WINDOW_HTML = '<div style="font-size: 11px; font-family: Helvetica, Arial; color:#666; width: 210px; padding-right: 10px"><strong>Vallery:</strong><br /><br />Abrimos de martes a sábado de 11 a 14 y de 17 a 20<br /><br />Calabria, 85<br />08015 Barcelona<br />España</div>';
	}
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.setCenter(new GLatLng(41.378813, 2.156153), 16);


	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());


	var marker = new GMarker(new GLatLng(41.378813, 2.156153));
	map.addOverlay(marker);
	GEvent.addListener(marker, "click", function() {
	  marker.openInfoWindowHtml(WINDOW_HTML);
	});
	marker.openInfoWindowHtml(WINDOW_HTML);

  }
}