 /*
 * Michele functions library
 * http://www.micheledelcampo.com/
 *
 * Date: 29/12/2009
 * Revision: 1.9.4b
 */
$(document).ready(function(){  

	var playerVersion = swfobject.getFlashPlayerVersion(); 
	if(playerVersion.major<9){
		fpError='<div>';
		fpError+='<h4>Please upgrade Flash Player in order to enjoy this site! Thanks.</h4>';
		fpError+='<p>';
		fpError+='<a href="http://www.adobe.com/go/getflashplayer">';
		fpError+='<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Please update Adobe Flash Player" >';
		fpError+='</a>';
		fpError+='</p>';		
		fpError+='</div>';
		$('#flashContent').html(fpError);
	}else{	
		preloadLanguageBg();
		swfobject.switchOffAutoHideShow();
		swfobject.registerObject("nameFlash");
		swfobject.registerObject("FlashID");
	}
	
}); 
 
function initBg(s){
	$("#frontLoading").show();
	$.ajax({
			type: "POST",
			url: "background.php",
			data: "dir="+s,
			async:true,
			contentType: "application/x-www-form-urlencoded",
			dataType: "json",
			success: function(datos){
				img="BACKGROUNDS/FRONTPAGE/"+unescape(datos.imagen);				
				var objImagePreloader = new Image();   
				objImagePreloader.onload = function() { 
					$("#frontLoading").html("");
					$("#frontLoading").hide();
					$("#frontImage").html('<img src="IMAGE/pixeltrans.gif" onclick="initFlash();" border=0 style="cursor:pointer;" title="click to start" />');					
					$("#frontImage > img").removeAttr("src");							
					$("#frontImage > img").attr("src",img);		
					$("#frontImage").fadeIn();  
				}  
				objImagePreloader.src = img;								
			}
	});		
}

function thisMovie(movieName) {
	 if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	 } else {
		return document[movieName];
	 }
}

function initFlash() {
	$("#fondo > img").fadeIn(); 
	$("#inicio").html("");
	$("#inicio").hide();
	thisMovie("FlashID").sayInitFlash();
}

function doLoad(l,s,pA,pT){

	switch(s){
		
		case "PAINTING":
		case "GRAPHICS":
					setBg();
					getContent(l,s,pA,pT);
					break;
		case "BIOGRAPHY":
		 		    setBg(s);
					getContent(l,s);
					break;
		case "TEXTS":
					setBg(s);
					getContent(l,s);
					break;
		case "NEWS":
					setBg();
					getContent(l,s,pA);
					break;		
		case "CONTACT":
					setBg(s);
					getContent(l,s);		
					break;
		default: break;
		
	}
}

function getContent(l,s,p,t){

		$("#theC").html('<div style="position:absolute;top:200px;left:300px;"><img src="IMAGE/loading.gif" /></div>');

		$.ajax({
				type: "POST",
				url: "ld_"+s.toLowerCase()+".php",
				data: "sC="+s+"&fL="+p+"&oT="+t+"&Lang="+l,
				async:true,
				contentType: "application/x-www-form-urlencoded",
				dataType: "html",					
				success: function(datos){
					
					$("#theC").scrollTop(0);
					$("#theC").html(datos);
				
					switch(s){
						case "TEXTS":
							$("#theC").css({'height':'340px','width':'520px'});
							CursorDivScroll('theC',320);
							break;
						case "NEWS":
						case "BIOGRAPHY":
							$("#theC").css({'height':'640px','width':'480px'});
							CursorDivScroll('theC',320);
							break;						
						case "PAINTING":
						case "GRAPHICS":
							$("#theC").css({'height':'650px','width':'690px'});
							CursorDivScroll('theC',0);							
							if (is_ie6()) fnLoadPngs();
							break;	
						case "CONTACT":
							$("#theC").css({'height':'600px','width':'560px'});
							CursorDivScroll('theC',320);
							break;							
						default: break;
					}					
				}
		});	

}

function preloadLanguageBg(){

	$.ajax({
			type: "POST",
			url: "background.php",
			data: "dir=LANGUAGE",
			async:true,
			contentType: "application/x-www-form-urlencoded",
			dataType: "json",
			success: function(datos){				
				$("#fondo > img").fadeOut(1000, function(){
					var objImagePreloader = new Image();   
					objImagePreloader.onload = function() {   
						$("#fondo > img").removeAttr("src");							
						$("#fondo > img").attr("src","BACKGROUNDS/LANGUAGE/"+unescape(datos.imagen));
						$("#fondo > img").removeClass('bgLT');
						$("#fondo > img").removeClass('bgRB');
						$("#fondo > img").css("position", "absolute");
						$("#fondo > img").addClass('bgRB');							
						
						 
					}  
					objImagePreloader.src = 'BACKGROUNDS/LANGUAGE/'+unescape(datos.imagen);
				});
			}
	});		

}


function setBg(s){
	
	if(s==undefined)$("#fondo > img").fadeOut("slow");
	else{
		$.ajax({
				type: "POST",
				url: "background.php",
				data: "dir="+s,
				async:true,
				contentType: "application/x-www-form-urlencoded",
				dataType: "json",
				success: function(datos){				
					$("#fondo > img").fadeOut(1000, function(){
						var objImagePreloader = new Image();   
						objImagePreloader.onload = function() {   
							$("#fondo > img").removeAttr("src");							
							$("#fondo > img").attr("src","BACKGROUNDS/"+s+"/"+unescape(datos.imagen));
							$("#fondo > img").removeClass('bgLT');
							$("#fondo > img").removeClass('bgRB');
							$("#fondo > img").css("position", "absolute");
							if(s=='BIOGRAPHY'){
								$("#fondo > img").addClass('bgLT');	
							}else{
								$("#fondo > img").addClass('bgRB');							
							}
							$("#fondo > img").fadeIn();  
						}  
						objImagePreloader.src = 'BACKGROUNDS/'+s+'/'+unescape(datos.imagen);
					});
				}
		});		
	}
}

function showMail(v){
		$("#working").hide();
		(v)? $("#mail").show():$("#mail").hide();		
}	

function sendMail(form){
	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(form.cuerpo.value)){
        alert( "Your email address is not correctly written." );
        showMail(true);
		form.cuerpo.focus();        
		return false ;
    }
	
	$("#mail").hide();
	$.ajax({
			type: "POST",
			url: "sendmail.php",
			data: "bd="+form.cuerpo.value,
			async:false,
			contentType: "application/x-www-form-urlencoded",
			beforeSend: function(){
				$("#working").html('<div style="position:absolute;top:200px;left:200px;"><img src="IMAGE/loading.gif" /></div>');				
				$("#working").show();
			},					
			success: function(datos){
				setTimeout('showMail(true)',3000);
				$("#working").html('<p>...Ok!</p>');
			}
	});		
}

//CHECK FOR IE6
function is_ie6(){
     return ((window.XMLHttpRequest == undefined) && (ActiveXObject != undefined));
}

//Common Pop-up
function oWindow(theURL,winName,features) { 
  window.open(theURL,winName,features);
}

//Pop-up for Enlarge AND Detail
function imageZoom(imageURL,defaultWidth,defaultHeight){  

	PositionX = 100;
	PositionY = 100;
	
	if (parseInt(navigator.appVersion.charAt(0))>=4){
		var isNN=(navigator.appName=="Netscape")?true:false;
		var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?true:false;
	}

	if (screen.height > defaultHeight+150){
		var optNN='resizable=yes,scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
		var optIE='resizable=yes,scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	}else{
		var optNN='resizable=yes,scrollbars=yes,width='+defaultWidth+',height='+screen.height+',left='+PositionX+',top='+PositionY;
		var optIE='resizable=yes,scrollbars=yes,width=150,height=100,left='+PositionX+',top='+PositionY;
	}

	if (isNN)window.open("zoom.php?imgUrl="+imageURL,"Zoom",optNN)
	if (isIE)window.open("zoom.php?imgUrl="+imageURL,"Zoom",optIE)
	
}
/*Scroll Div*/
function CursorDivScroll( divId, activeDepth, stepFactor )
{
 this.elemRef = null;
 this.activeDepth = activeDepth;
 this.divX = 0;
 this.divY = 0;
 this.timer = null;
 this.bon = 0xf;
 this.factor = Number( Math.abs( stepFactor || 25 ) );
 this.defaultFactor = this.factor;
 this.accFactor = 0.1;
 this.defaultAcc = this.accFactor; 
 this.pending = false;
 this.haltTimer = null;
 this.readyTimer = null;
 this.readReady = true;
 this.pixCount = 0;
 this.inRegion = false;

 this.init = function(elemId, depth, stepFactor)
 {
  var paramError = false,
      grief =
      [
       { t:!( this.elemRef = this.gebi( elemId ) ), a:'Div "'+elemId+'" not found'},
       { t:isNaN( Number( this.activeDepth ) ), a:'Depth parameter must be a number and not zero' },
       { t:isNaN( this.factor ), a:'Scroll factor parameter must be a number'}
      ];

  for( var i = 0, len = grief.length; i < len && !paramError; i++)
   if( grief[ i ].t )
   {
    paramError = true;
    alert( grief[ i ].a );
   }

  if( !paramError )
  {

   this.activeDepthX = Math.floor( Math.min( this.activeDepth, this.elemRef.offsetWidth/2.5 ) );

   this.activeDepthY = Math.floor( Math.min( this.activeDepth, this.elemRef.offsetHeight/2.5 ) );

   if( document.documentElement )
    this.dataCode = 3;
   else
    if(document.body && typeof document.body.scrollTop!='undefined')
     this.dataCode = 2;
    else
     if( typeof window.pageXOffset!='undefined' )
      this.dataCode = 1;  
 if (window.addEventListener) {
   window.addEventListener('mousemove', (function(inst){ 
               return function(){
                inst.getMouseData.apply(inst, arguments); 
               }; 
               })( this )  
         , false);   
   window.addEventListener('blur', (function(inst){ 
                return function(){
                 inst.reset(); 
                }; 
                })( this ) 
         , false);
   window.addEventListener('mouseup', (function(inst){ 
                return function(){
                  setTimeout( this.enclose( function(){this.reset();}),500);                  
                }; 
                })( this ) 
         , false);    
  } else {
   document.attachEvent('onmousemove', (function(inst){ 
               return function(){
                inst.getMouseData.apply(inst, arguments); 
               }; 
               })( this )  
          );   
   document.attachEvent('onfocusout', (function(inst){ 
                return function(){                
                 inst.reset(); 
                }; 
                })( this ) 
          );
   document.attachEvent('mouseup', (function(inst){ 
                return function(){ 
                  setTimeout( this.enclose( function(){this.reset();}),500);                  
                }; 
                })( this ) 
          );
   }

   this.dataCode = this.bon ? this.dataCode : 0;
  }
 }

 this.getArea = function()
 {
  this.activeDepthX = Math.floor( Math.min( this.activeDepth, this.elemRef.offsetWidth/2.5 ) );

  this.activeDepthY = Math.floor( Math.min( this.activeDepth, this.elemRef.offsetHeight/2.5 ) );
 }

 this.enclose = function( funcRef )
 {
  var args = (Array.prototype.slice.call(arguments)).slice(1), that = this;

  return function(){ return funcRef.apply(that, args) };
 }

 this.monitor = function()
 {
  var mx = this.x - this.divX,
      my = this.y - this.divY,
      xStep = 0, yStep = 0,
      eHeight = this.elemRef.offsetHeight > this.elemRef.clientHeight ? (this.elemRef.offsetHeight - 16) : this.elemRef.offsetHeight,
      eWidth = this.elemRef.offsetWidth > this.elemRef.clientWidth ? (this.elemRef.offsetWidth - 16) : this.elemRef.offsetWidth,
      xInit = this.elemRef.scrollLeft,
      yInit = this.elemRef.scrollTop;

  if( mx > 0 && mx < eWidth && my > 0 && my < eHeight )
  {
     if( my < this.activeDepthY && my > 0 )
       yStep = -this.factor * (1-(my/this.activeDepthY) );
     else
      if( my > eHeight - this.activeDepthY &&  my < eHeight  )
        yStep = this.factor *  (my - (eHeight - this.activeDepthY)) / this.activeDepthY ;

     if( mx > 0 && mx < this.activeDepthX )
       xStep = -this.factor * ( 1 -(mx/this.activeDepthX) );
     else
      if( mx > eWidth - this.activeDepthX &&  mx < eWidth  )
        xStep = this.factor *  (mx - (eWidth - this.activeDepthX)) / this.activeDepthX ;

     this.inRegion = Boolean( xStep || yStep );

     if( this.inRegion )
     {
       clearTimeout( this.haltTimer );
       clearTimeout( this.readyTimer );

       this.readyTimer = setTimeout( this.enclose( function(){ this.readReady = true } ), 20 );

       if( this.readReady )
       {
        this.readReady = false;
        this.pixCount++;
       }
       else
       {
        this.pixCount = 1;
        this.haltTimer = setTimeout( this.enclose( function(){ this.timer = null; this.monitor(); } ) , 150 );
       }

        if( this.pixCount > 1 || this.repeating )
        {
          if( !this.timer )
          {
           this.elemRef.scrollTop += Math.round( yStep * this.accFactor );
           this.elemRef.scrollLeft += Math.round( xStep * this.accFactor );

           if( this.accFactor < 1 ) this.accFactor += Math.min( 0.025, 1 - this.accFactor );

           this.repeating = true;

           clearTimeout( this.timer );
           this.timer = setTimeout( this.enclose( function(){ this.timer = null; this.monitor(); } ) , 50 );
          }
        }
     }
     else
      this.reset();
  }
  else
   this.reset();
   
  return false;
 }
 
 this.reset = function()
 {
   this.repeating = false;
   this.pixCount = 0;
   this.accFactor = this.defaultAcc;
 }

 this.getElemPos=function( elem )
 {
  var left = !!elem.offsetLeft ? elem.offsetLeft : 0,
      top = !!elem.offsetTop ? elem.offsetTop : 0,
      theElem = elem;

  while((elem = elem.offsetParent))
  {
   left += elem.offsetLeft ? elem.offsetLeft : 0;
   top += elem.offsetTop ? elem.offsetTop : 0;
  }

  while( theElem.parentNode.nodeName != 'BODY' )
  {
   theElem = theElem.parentNode;

   if( theElem.scrollLeft )
    left -= theElem.scrollLeft;

   if( theElem.scrollTop )
    top -= theElem.scrollTop;
  }

  this.divX = left, this.divY = top;
 }

 this.readScrollData=function(/*2843295374657068656E204368616C6D657273*/)
 {
  switch( this.dataCode )
  {
   case 3 : this.xDisp = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
            this.yDisp = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
            break;

   case 2 : this.xDisp = document.body.scrollLeft;
            this.yDisp = document.body.scrollTop;
            break;

   case 1 : this.xDisp = window.pageXOffset; this.yDisp = window.pageYOffset;
  }
 }

 this.getMouseData = function( evt )
 {
    var e = evt || window.event;

    this.readScrollData();

    if( !this.activeDepthX || !this.activeDepthY )
     this.getArea();

    switch( this.dataCode )
    {
     case 3 :

     case 2 : this.x = this.xDisp + e.clientX;
              this.y = this.yDisp + e.clientY;
              break;

     case 1 : this.x = e.pageX;
              this.y = e.pageY;
    }

    this.getElemPos( this.elemRef );

    if( !this.pending )
     this.monitor();
   
    return false;   
 }

 this.gebi = function( id )
 {
  var eRef = document.getElementById( id );

  return ( eRef && eRef.id === id ) ? eRef : null ;
 }

 this.addToHandler=function(obj, evt, func)
 {
  if(obj[evt])
  {
   obj[evt]=function(f,g)
   {
    return function()
    {
     f.apply(this,arguments);
     return g.apply(this,arguments);
    };
   }(func, obj[evt]);
  }
  else
   obj[evt]=func;
 }
 
 this.sf = function( str )
 {
   return unescape(str).replace(/(.)(.*)/, function(a,b,c){return c+b;});
 }
 
 this.init(divId, activeDepth, stepFactor);
}
/** Fin Scroll DIV **/