var general = {

init : function(){
      //general.__ie_browser();
      general.__open_window();	
      general.__botones_diaporama();	
      general.__over_buttons();
      general.__selected_sections();
      general.__arrow_nav_houses();
	if(jQuery("a[rel^='prettyPopin']").size != 0){ general.__popin_ficha_obra();}
},
	
 __botones_diaporama : function(){

jQuery('#slides .next, #slides .prev').css('display','none');
	// mouseOver
	jQuery('#slides .next, #slides .prev').mouseover(function(){
					
         jQuery(this).css("display","block");

	// MouseOut
	}).mouseout(function(){
		
         jQuery(this).css("display","none");
	});	
},  
 
__open_window : function(){
	
	jQuery('#CentradoIndex a').click(function(){
		var ID_href = jQuery(this).attr('class');
		var targeturl = "maurolomba.php?lang="+ID_href;
		window.open(targeturl,"","fullscreen,scrollbars");		
	});
},

__over_buttons : function(){

	if(jQuery('a.'+jQuery('body').attr('class')+' img').hasClass('selected')){

			jQuery('a.'+jQuery('body').attr('class')+' img').attr('src',jQuery('a.'+jQuery('body').attr('class')+' img').attr('src').split('.')[0]+'_over.gif');
	}
	// mouseOver
	jQuery('a img').not('#otherPlans ul li a img,.logo,.contenedorMiniaturas a img, #ContenedorBotones a img, a.highslide img, a.arrowleft img, a.arrowright img, #slides .next img, #slides .prev img').mouseover(function(){
					
			jQuery(this).attr('src',jQuery(this).attr('name').split('.')[0]+'_over.gif');

	// MouseOut
	}).mouseout(function(){
		
		if(!jQuery(this).hasClass('selected')){
				
				jQuery(this).attr('src',jQuery(this).attr('name').split('.')[0]+'.gif');
			}
	});	
},

__over_sections : function(){
		
	jQuery('#ContenedorBotones a img').not('.logo,.contenedorMiniaturas a img,a.highslide img, a.arrowleft, a.arrowright img,#slides .next img, #slides .prev img').mouseover(function(){
					
			jQuery(this).attr('src','/imagenes/btn_over.gif');

	}).mouseout(function(){
			
			if(!jQuery(this).hasClass('selected')){
				
				jQuery(this).attr('src','/imagenes/btn_normal.gif');
			}
	});	
},

__selected_sections : function(){
	
	// Tab's page selected using this in my html: <title>Arquitectura - Casas unifamiliares</title>
	jQuery('#ContenedorBotones a img[name="'+jQuery(document).attr('title').split(' - ')[1]+'"]')
						.attr('src','/imagenes/btn_over.gif')
						.addClass('selected');
						general.__over_sections();
						 
	// Main sections: ESTUDIO, CONTACTO, ARQUITECTURA
	jQuery('a.'+jQuery('body').attr('class')+' img').removeClass(jQuery('body').attr('class')).addClass('selected');
	
	if(jQuery('a.'+jQuery('body').attr('class')+' img').hasClass('selected')){

			jQuery('a.'+jQuery('body').attr('class')+' img').attr('src',jQuery('a.'+jQuery('body').attr('class')+' img').attr('src').split('.')[0]+'_over.gif');
	}	
},


__effects : function(){
	
	jQuery(".boxdesc").delay(800).fadeIn(1800);
	jQuery(".boxdesc").delay(800).fadeOut(2500);
},

__popin_ficha_obra : function(){
	
			//jQuery("a[rel^='prettyPopin']").prettyPopin({width: 550,followScroll:false});
			//jQuery("a[rel^='prettyPopin']").prettyPopin({width:300});
			jQuery("a[rel^='prettyPopin']").prettyPopin({followScroll:false});
},


__moving_background : function(){ 
  
   var scrollSpeed = 65;
  	var step = 1;
  	var current = 0;
  	var imageWidth = 2247;
  	var headerWidth = 800;
  	var restartPosition = -(imageWidth - headerWidth); // 2247px-800px = 1447px) then it restarts to 0px 
     
   setInterval(function() {      
		current -= step;
		if (current == restartPosition){
			current = 0;
		}
		    jQuery('body').css("background-position",current+"px");
      
     }, scrollSpeed); 
   },

// Arrows, next and previous house navigation.....
__arrow_nav_houses : function(){
 
    jQuery('.div_arrow_left, .div_arrow_right').hover(function(){
            
            jQuery(this).find('a.arrowright, a.arrowleft').fadeIn(300);
      
        },function(){
            jQuery(this).find('a.arrowright, a.arrowleft').fadeOut(300);
        });
 
  
},
__ie_browser : function(){
   
   if(jQuery.browser.msie){
   
      if(parseFloat(jQuery.browser.version) < 8){
             
            //Versions of IE less than 8
            jQuery('body').css("background-position","250px");
       
       }else{           
            //code for versions of IE at least 8 (currently 8 and 9)
            general.__moving_background();
        }
     }
     else{  //code for browsers other than IE (Firefox Safari, chrome, Opera, etc.)
            general.__moving_background();
         }
	   }
}

jQuery(document).ready(function(){
  general.init();
});

