  
/* hide body to prevent FOUC */ 
 document.write('<style type="text/css">body{display:none}</style>');
  
 var viewportwidth;
 	 var viewportheight;
 
	/* define getViewport in function for executuion on resize */  
 function getViewport() {
 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
	      viewportwidth = window.innerWidth,
	      viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	 
	 else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0)
	 {
	       viewportwidth = document.documentElement.clientWidth,
	       viewportheight = document.documentElement.clientHeight
	 }	
 
 }

/* getViewport on load */ 
 getViewport();
 

/* Google Map */
 function GoogleMapInitialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(41.391186,2.138364), 16);
		map.addControl(new GSmallMapControl());
		
		 function createMarker(point, nombre) { 
      var marker = new GMarker(point); 
         GEvent.addListener(marker, 'click', function() { 
         	 marker.openInfoWindowHtml(nombre); 
      	 }); 
      return marker; 
   } 
 
   
        
        // Add markers
  var bounds = map.getBounds();
  var southWest = bounds.getSouthWest();
  var northEast = bounds.getNorthEast();
  var lngSpan = northEast.lng() - southWest.lng();
  var latSpan = northEast.lat() - southWest.lat();
    var point = new GLatLng(41.391186,2.138364);
    var nombre = "Din\u00e1micas S.L.<br />Marketing Relacional<br />Av. Diagonal, 535<br />08029 Barcelona"; 
    var marker = createMarker (point, nombre); 
   map.addOverlay(marker); 
      }
    }
/* end Google Map */  
	

	
/* flash call */  

function flashCall() {
	jQuery('#menuLinkTra').click();	
}

/* end flash call */  



  jQuery(document).ready(function()	
	{
		
		
	/* if sound is on, insert elements for sound effects */
	if (window.name=="on") {
		jQuery('#cabecera').before('<img src="http://www.dinamicas.com/wpdinamicas/wp-content/themes/dinamicas/img/tattaaa.gif" width="391" height="426" alt="Tattaaa!" id="tattaaa" class="sound" /><img src="http://www.dinamicas.com/wpdinamicas/wp-content/themes/dinamicas/img/fumm.gif" width="343" height="334" alt="Ffummm!" id="fumm" class="sound" /><img src="http://www.dinamicas.com/wpdinamicas/wp-content/themes/dinamicas/img/zas.gif" width="295" height="404" alt="Zzzaaasss!" id="zas" class="sound" /><img src="http://www.dinamicas.com/wpdinamicas/wp-content/themes/dinamicas/img/tlic.gif" width="81" height="68" alt="Tlic!" id="tlic" class="sound" /><img src="http://www.dinamicas.com/wpdinamicas/wp-content/themes/dinamicas/img/zunn.gif" width="130" height="35" alt="Zzzunn!" id="zunn" class="sound" />');
	}
	
	/* get element offsets for animation */
	var offsetContent=parseInt(viewportheight/2-100)+parseInt(jQuery("#cabecera").css("height"))+parseInt(jQuery("#competencias").css("height"))+parseInt(jQuery("#titulo").css("height"))+parseInt(jQuery("#content").css("height"));
	var offsetMenu=parseInt(viewportheight/2-300)+parseInt(jQuery("#cabecera").css("height"))+parseInt(jQuery("#competencias").css("height"))+parseInt(jQuery("#titulo").css("height"))+parseInt(jQuery("#content").css("height"))+parseInt(jQuery("#menu").css("height"));	
	
	/*bind resize to changing offset variables */	
	jQuery(window).resize(function() {
		getViewport();
	 	offsetContent=parseInt(viewportheight/2-100)+parseInt(jQuery("#cabecera").css("height"))+parseInt(jQuery("#competencias").css("height"))+parseInt(jQuery("#titulo").css("height"))+parseInt(jQuery("#content").css("height"));
		offsetMenu=parseInt(viewportheight/2-300)+parseInt(jQuery("#cabecera").css("height"))+parseInt(jQuery("#competencias").css("height"))+parseInt(jQuery("#titulo").css("height"))+parseInt(jQuery("#content").css("height"))+parseInt(jQuery("#menu").css("height"));	
	});
	
	
	/* adapt body to viewportsize, move elements out of viewport, deactivate scrollbar for animation, show everyting */ 
	jQuery("body").css("height", viewportheight+"px");
	if (!jQuery("body").hasClass("home")) {
		jQuery("#content").css("top", -offsetContent+"px");
		jQuery("#menu").css("top", 450+offsetMenu+"px");
		jQuery("#competencias").css("top", "-34px");
	}
	jQuery(".menuDesc").css("display", "none");
	jQuery("html").css("overflow", "hidden");
	jQuery("body").css("display", "block");

	
    /* if not on home page, slide in elements and activate scrollbar (as callback), different animation for SOUND (if-loop with window.name=="on") */ 
    if (!jQuery("body").hasClass("home")) {
	    if (window.name=="on"){
		    jQuery('#zas').delay(400).fadeToggle(350).delay(300).fadeToggle(1000);
		    jQuery("#menu").animate({ "top": ["-="+offsetMenu, "swing"] }, 400, jQuery("#menu").css("display", "block"));
	   		jQuery("#competencias").delay(150).animate({ "top": ["+=34", "swing"] }, 200, function() {
		    	jQuery("#content").animate({ "top": ["+="+offsetContent, "swing"] }, 500, function() {
		    		jQuery("html").css("overflow", "auto");	
			    	});
		    	});
	    } else {
	    jQuery("#menu").animate({ "top": ["-="+offsetMenu, "swing"] }, 400, jQuery("#menu").css("display", "block"));
	    jQuery("#competencias").delay(150).animate({ "top": ["+=34", "swing"] }, 200, function() {
		     jQuery("#content").animate({ "top": ["+="+offsetContent, "swing"] }, 500, function() {
		    		jQuery("html").css("overflow", "auto");	
			    	});
		     });
	    }
    } else {
	    jQuery("html").css("overflow", "auto");	
	}
	
    /* bind click on outLinks to animation, cancel evenet and simulate click when animation is finished, different animation for SOUND (if-loop with window.name=="on") */ 
	jQuery('.outLink').click(function(event){
  		event.preventDefault();
  		var self=this;		
		jQuery("html").css("overflow", "hidden"); /* prevent scrollbar during animation */
		if(window.name=="on"){
	  		jQuery('#fumm').fadeToggle(150).delay(500).fadeToggle(1000);
	  		jQuery("#content").animate({ "top": ["-="+offsetContent, "swing"] }, 400);
    		jQuery("#menu").animate({ "top": ["+="+offsetMenu, "swing"] }, 400, function() {
		    	var myTime=window.setTimeout(function(){ window.location=self.href; }, 1600);	   		
		 	});
  		}else {
	  		jQuery("#content").animate({ "top": ["-="+offsetContent, "swing"] }, 400);
	    	jQuery("#competencias").delay(150).animate({ "top": ["-=34", "swing"] }, 200);
	    	jQuery("#menu").animate({ "top": ["+="+offsetMenu, "swing"] }, 400, function() {
		   		 window.location=self.href;
		 	});
	 	}
	});
	
	
	    
	
		/* query-adjustment, hover and click functions for competencias-links */
	var blockComp = "false"
	
	var query = window.location.search;
	var h=query.substr(1,query.length);
    if(h!="") {
	    jQuery("#"+h).addClass('sel');
		var selectorPr = "a."+h+" > div";
		 	jQuery(selectorPr).css('display', 'block');	
		var bu= jQuery("a."+h).parent();
		jQuery(selectorPr).addClass('shadow');
		 	jQuery(bu).css('z-index', '1800');
		 	jQuery(selectorPr).css('z-index', '1500');
		 	jQuery(selectorPr).delay('900').animate({
    						width: '123',
							height: '104',
							top: '-=10',
							left: '-=10',
							fontSize: '+=2'
						    }, 300 );
		blockComp = "";
	}
	
	jQuery("ul#listaComp > li").mouseenter(
	  function () {
		  if (blockComp=="false") {
		 	jQuery(this).addClass('sel');
		 	var selectorPr = "a."+this.id+" > div";
		 	jQuery(selectorPr).css('display', 'block');	 	
		var bu= jQuery("a."+this.id).parent();
		 	jQuery(selectorPr).addClass('shadow');
		 	jQuery(bu).css('z-index', '1800');
		 	jQuery(selectorPr).css('z-index', '1500');
		 	jQuery(selectorPr).animate({
    						width: '123',
							height: '104',
							top: '-=10',
							left: '-=10',
							fontSize: '+=2'
						    }, 300 );
		  }
	  }); 
	  
	  
	jQuery("ul#listaComp > li").mouseleave(
	  function () {  
		if (blockComp=="false") {
		 	jQuery(this).removeClass('sel');
		 	var selectorPr = "a."+this.id+" > div";	
		 	var bu= jQuery("a."+this.id).parent();
		 	jQuery(selectorPr).animate({
    						width: '95',
							height: '76',
							top: '+=10',
							left: '+=10',
							fontSize: '-=2'
						    }, 300, function() {
								jQuery(selectorPr).removeClass('shadow'); 	
							 	jQuery(selectorPr).css('z-index', '5');	
							 	jQuery(bu).css('z-index', '5');
		 						jQuery(selectorPr).css('display', 'none');
							});
		 	
		}
	  });
	
	
	jQuery("ul#listaComp > li").click(
	  function (event) {
		if (jQuery("body").hasClass("todos")) {
			event.preventDefault();
			if (blockComp=="false") {
				blockComp="true";
			} else {
				var selectorPr = "a."+this.id+" > div";
		 		jQuery(selectorPr).css('display', 'block');
				var bu= jQuery("a."+this.id).parent();
			 	jQuery('.sel').removeClass('sel');
			 	jQuery(this).addClass('sel');
			 	var b = jQuery('.shadow:last').attr('alt');
			 	jQuery('.shadow').animate({
	    						width: '95',
								height: '76',
								top: '+=10',
								left: '+=10',
								fontSize: '-=2'
							    }, 300, function() {	
								 	jQuery('.shadow').css('z-index', '5');
								 	jQuery('.shadow').parent().parent().css('z-index', '5');
								    jQuery('.shadow').removeClass('shadow');	 
								   	if (jQuery(this).attr("alt")==b){
									   	jQuery(selectorPr).addClass('shadow');
									 	jQuery(bu).css('z-index', '1800');	
									 	jQuery(selectorPr).css('z-index', '1500');	
									 	jQuery(selectorPr).animate({
							    						width: '123',
														height: '104',
														top: '-=10',
														left: '-=10',
														fontSize: '+=2'
													    }, 300 );
								   	}
								});		
			   }
		  }
 	  }
	);
	
		
	jQuery("ul#listaComp > li").dblclick(
	  function (event) {
		event.preventDefault();
		if (blockComp!="false") {
			blockComp="false";
		} else {
		 	jQuery(this).click();
		}
	  }
	);
	
	  
	/* mouseover functions for project-links */
	jQuery('.prImg').mouseenter(function(event){
  		var self=this;
  		descID="div."+self.id;
  		jQuery(descID).fadeIn("450");
	})
	
	jQuery('.prImg').mouseleave(function(event){
  		var self=this;
  		descID="div."+self.id;
  		jQuery(descID).fadeOut("450");
	})
	
	
	
	/* mouseover functions for menu-links, require hiding of description-elements on pageload */
	jQuery('.menuLink').mouseover(function(event){
  		var self=this;
  		descID="a#"+self.id+" > span.menuDesc";
  		jQuery(descID).show();
	})
	
	jQuery('.menuLink').mouseout(function(event){
  		var self=this;
  		descID="a#"+self.id+" > span.menuDesc";
  		jQuery(descID).hide();
	})
	
	
	
	/* START hover and click functions for equipo-li and img */
	var block = "false"
	
	jQuery("ul#equipo > li").hover(
	  function () {
		  if (block=="false") {
		 	jQuery(this).fadeTo('fast', 1);
		 	var selectorLi = "ul#equipo > li[class!="+jQuery(this).attr("class")+"]";
		 	jQuery(selectorLi).fadeTo('fast', 0.5);
		 	jQuery("div#content > img").css("display", "none");
			var selectorImg = "img."+jQuery(this).attr("class");
	   	 	jQuery(selectorImg).fadeIn();
		  }
	  }, 
	  function () {  
		if (block=="false") {	
			var selectorImg = "img."+jQuery(this).attr("class");
	    	jQuery(selectorImg).fadeOut();
		}
	  }
	);

	jQuery("ul#equipo > li").click(
	  function () {
		if (block=="false") {
			block="true";	
		} else {
			jQuery(this).fadeTo('fast', 1);
		 	var selectorLi = "ul#equipo > li[class!="+jQuery(this).attr("class")+"]";
		 	jQuery(selectorLi).fadeTo('fast', 0.5);
		 	jQuery("div#content > img").css("display", "none");
			var selectorImg = "img."+jQuery(this).attr("class");
	   	 	jQuery(selectorImg).fadeIn();	
		}
	  }
	);
	/* END hover and click functions for equipo-li and img */

	
	

	/* activate and deactivate sound effects */
	jQuery('#soundLink').click(function(event){
  		event.preventDefault();
  		var self=this;
  		if(window.name=="on"){
	  		window.name="";
	  		jQuery('.sound').remove();
		}else{
	  		window.name="on";
		
    		jQuery('#cabecera').before('<img src="http://www.dinamicas.com/wpdinamicas/wp-content/themes/dinamicas/img/tattaaa.gif" width="391" height="426" alt="Tattaaa!" id="tattaaa" class="sound" /><img src="http://www.dinamicas.com/wpdinamicas/wp-content/themes/dinamicas/img/fumm.gif" width="343" height="334" alt="Ffummm!" id="fumm" class="sound" /><img src="http://www.dinamicas.com/wpdinamicas/wp-content/themes/dinamicas/img/zas.gif" width="295" height="404" alt="Zzzaaasss!" id="zas" class="sound" /><img src="http://www.dinamicas.com/wpdinamicas/wp-content/themes/dinamicas/img/fumm.gif" width="343" height="334" alt="Ffummm!" id="fumm" class="sound" /><img src="http://www.dinamicas.com/wpdinamicas/wp-content/themes/dinamicas/img/tlic.gif" width="81" height="68" alt="Tlic!" id="tlic" class="sound" /><img src="http://www.dinamicas.com/wpdinamicas/wp-content/themes/dinamicas/img/zunn.gif" width="130" height="35" alt="Zzzunn!" id="zunn" class="sound" />');
    		jQuery('#tattaaa').fadeToggle(200).delay(200).fadeToggle(1500);
    	}
	}) 


	/* SOUND: click and scroll */	
	jQuery(document).mousedown(function(e){		
		if(window.name=="on"){
			if (e.target.id=="scroller") {
				jQuery('#zunn').css("left", e.pageX+"px");
			    jQuery('#zunn').css("top", e.pageY+"px");
			    jQuery('#zunn').fadeToggle(150).delay(100).fadeToggle(550);
			} else {
		      	jQuery('#tlic').css("left", e.pageX+"px");
		      	jQuery('#tlic').css("top", e.pageY+"px");
		      	jQuery('#tlic').fadeToggle(150).delay(220).fadeToggle(150);
     		}
  		}
	});
	
	
	/* initialize slideshow, if body has class "caso" */
	if (jQuery("body").hasClass("single-casos")) {
		jQuery('#slideshow').cycle({ 
			fx:      'scrollLeft', 
			speed:    800, 
			timeout:  4000, 
		    next:   '#slideshow', 
		    pause: 1 
		});
	}
	
		
	/* initialize map, if body has class "page-template-contacto-php"  */
		if (jQuery("body").hasClass("page-template-contacto-php")) {			
		GoogleMapInitialize();
	}
			
		
	/* change cursor on li when on "dinamicas.html"  */
		if (jQuery("body").hasClass("page-template-dinamicas-php")) {
		jQuery("ul#equipo > li").css("cursor", "pointer");
	}

	
    
	});		
		
		

