/* ================================ +
   	       WESTERGASFABRIEK
 + ================================ */



/* 
** Made by: Studio Parkers / Edgar Vijgeboom, Thomas Lievestro
** Email:	info@studioparkers.nl
** Website:	www.studioparkers.nl
*/

/* ================================ +
                GENERAL
 + ================================ */

	var $j = jQuery.noConflict();

	var	CarrouselTimeoutTime = 5000;
	var	KeepNumbers = Array();
	var Numbers;
	var last_object_interval;
	
	
 
	(function($j){

		/* Preload images */
		var cache = [];
		// Arguments are image paths relative to the current page.
		$j.preLoadImages = function() { 
		var args_len = arguments[0].length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
				cacheImage.src = arguments[0][i];
				cache.push(cacheImage);
			}
		}
		
		//Shuffle function 
		$j.fn.shuffle = function() {
		    return this.each(function(){
		      var items = $j(this).children();
		      return (items.length)
		        ? $j(this).html($j.shuffle(items))
		        : this;
		    });
		}
 
		$j.shuffle = function(arr) {
			for(
				var j, x, i = arr.length; i;
			      j = parseInt(Math.random() * i),
			      x = arr[--i], arr[i] = arr[j], arr[j] = x
			);
			return arr;
		}
	})(jQuery);


	function initCufon(){
  
	    Cufon.replace('#menu-urbanscreen > li > a', {
	       fontFamily: 'TradeGothicLT',
	       hover: true
	      });
        
     Cufon.replace('#menu-urbanscreen-en > li > a', {
         fontFamily: 'TradeGothicLT',
         hover: true
        });
        
        
     Cufon.replace('#menu-hoofdnavigatie > li > a', {
         fontFamily: 'TradeGothicLT',
         hover: true
        });
        
     Cufon.replace('#menu-hoofdnavigatie-en > li > a', {
         fontFamily: 'TradeGothicLT',
         hover: true
        });
      
			
	    Cufon.replace('#menu_home #menu-homenavigatie > li  a', {
	     fontFamily: 'TradeGothicLT',
	     hover: true
	     });
       
     Cufon.replace('#menu_home #menu-homenavigatie-en > li  a', {
       fontFamily: 'TradeGothicLT',
       hover: true
       });
			 
	   Cufon.replace('#footer #menu-homenavigatie > li  a', {
	     fontFamily: 'TradeGothicLT',
	      hover: true
	    });
      
     Cufon.replace('#footer #menu-homenavigatie-en > li  a', {
       fontFamily: 'TradeGothicLT',
        hover: true
      });
      
	   Cufon.replace('#footer h1', {
	      fontFamily: 'TradeGothicLT'
	    });
      
	    Cufon.replace('.item h3', {
	      fontFamily: 'TradeGothicLT',
	      hover: true
	    });
	    Cufon.replace('#items h3', {
	      fontFamily: 'TradeGothicLT',
	      hover: true
	    });
	    
	    Cufon.replace('#item_page_nav .prev, #item_page_nav .next', {
	      fontFamily: 'TradeGothicLT',
	      hover: true
	    });
	    Cufon.replace('.day_title', {
	      fontFamily: 'TradeGothicLT'
	    });
	    Cufon.replace('.item h5', {
	      fontFamily: 'TradeGothicLT',
	       hover: true
	    });
	    Cufon.replace('#content_container  h1', {
	      fontFamily: 'TradeGothicLTBold'
	    });
	    
	    Cufon.replace('#content_container h1 span', {
	      fontFamily: 'TradeGothicLT'
	    });
	    
	    Cufon.replace('#view li', {
	      fontFamily: 'TradeGothicLTBold',
	      hover: true
	    });
	    Cufon.replace('#months li a', {
	      fontFamily: 'TradeGothicLTBold',
	      hover: true
	    });
	    Cufon.replace('#days li a', {
	       fontFamily: 'TradeGothicLTBold',
	       hover: true
	     });
	    Cufon.replace('#right_column #sidebar h5', {
	      fontFamily: 'TradeGothicLTBold'
	    });
	    Cufon.replace('#right_column #alwaystodo h4', {
	      fontFamily: 'TradeGothicLTBold'
	    });
	    Cufon.replace('#left_column_small h3', {
	      fontFamily: 'TradeGothicLTBold'
	    });
	    Cufon.replace('#ngg-gallery-description h3, #ngg-related-description h3', {
	      fontFamily: 'TradeGothicLTBold'
	    });
	    Cufon.replace('h2.agendadatum', {
	      fontFamily: 'TradeGothicLTBold'
	    });
	    Cufon.replace('#alwaystodo h4,#huurders  h4, a.knop_zakelijk, .get_contact,#zakelijk_tehuur h4  ', {
	      fontFamily: 'TradeGothicLTBold',
	      hover: true
	    });
	    Cufon.replace('#huurders h5, #alwaystodo h5, #zakelijk_tehuur h5, .content h5, .agendaspeellijst h5', {
	      fontFamily: 'TradeGothicLTBold'
	    });
	    Cufon.replace('#footer #aanmelden h5', {
	      fontFamily: 'TradeGothicLT'
	    });
	    Cufon.replace('#right_column .sidebar h5, #right_column h4 ', {
	      fontFamily: 'TradeGothicLTBold',
	      hover: true
	    });
	    Cufon.replace('#sub_sub_nav ', {
	      fontFamily: 'TradeGothicLTBold',
	      hover: true
	    });
	    Cufon.replace('.altijdtedoen-subnav a', {
	      fontFamily: 'TradeGothicLTBold',
	      hover: true
	    });
	    Cufon.replace('.altijdtedoen-subnav span', {
	      fontFamily: 'TradeGothicLT'
	    });
      
     Cufon.replace('#social-holder p', {
        fontFamily: 'TradeGothicLTBold'
      });
      
     Cufon.replace('.mashmeup-timeline .timeline-title h1', {
        fontFamily: 'TradeGothicLT'
      });
      
     Cufon.replace('h1.agendaheader', {
        fontFamily: 'TradeGothicLT'
      }); 

      Cufon.replace('h2.agendatitel', {
        fontFamily: 'TradeGothicLTBold',
        hover: true
      }); 
      
      Cufon.replace('h1.agendaheader', {
        fontFamily: 'TradeGothicLT'
      }); 

      Cufon.replace('#mashup-home h4', {
        fontFamily: 'TradeGothicLT'
      }); 
      
      Cufon.replace('.banner-home h4', {
        fontFamily: 'TradeGothicLT'
      }); 
      
     Cufon.replace('a.meeragenda', {
        fontFamily: 'TradeGothicLT',
        hover: true
      }); 
      
      
      
	  }
		
	
	function initBackgroundGallery(){
		
		var img_array = [];
		
		/* description blokje tonen, niet op homepage carouse, dan zit deze al in de html*/
		if(!$j('body.home').html()){
		  $j('<div>').attr('id','ngg-gallery-description').prependTo($j('#adventure_layer .ngg-galleryoverview')).append($j('<h3>')).append($j('<p>'));
		  $j('.ngg-gallery-thumbnail a:first').addClass('active');
		} else {
		   $j('li.ngg-gallery-thumbnail-box:first').addClass('active');
		}

		if($j('#left_column_small .ngg-galleryoverview').length > 0){ 
			$j('#left_column_small .ngg-galleryoverview .ngg-gallery-thumbnail a').removeClass('active');
		}
		
		// for each gallery thumb 
		$j('.ngg-galleryoverview .ngg-gallery-thumbnail-box').each(function(){
						
			// get href, title and description and at them to a array's | 
			if($j('body.home').html()) {
			   var img_href     = $j('a',this).attr('rel');
         var img_description = '';
			} else {
			   var img_href 		= $j('a',this).attr('href');
			   var img_description = $j('span',this).html();
			   
			   var titles = $j('a',this).attr('title').split('|');
         var img_title   = titles[0];  
       /* Languages wordkaround for  Nexgen gallery:
       * The title is used to show after a photo is slected in gallery, when language is English (html LANG tag) than select the english text. 
       * The Imgage description in Nexgen Gallery should be entered with a seperator (|) like this: "De tekst in Nederlands | The text in English" 
       * so we can create an array afertward and get the right position.
       */
         
          if($j('html').attr('lang') == "en-US") {
            var img_title   = titles[1];  
			     }

			
			}
			
		
			img_array.push(img_href);


			// When we are on the homepage do mouseover else do click		
			if ($j('body.home').html()) {
				

        
				$j('.ngg-gallery-thumbnail',this).mouseover(function(){		
					
					$j('.ngg-gallery-thumbnail-box').removeClass('active');
					$j(this).parent().addClass('active');
					
					// append img element and remove old one
          if($j('#bg_image_container img').attr('src') == "") {
            $j('#bg_image_container img').attr('src',img_href);   
            
          } else if ($j('#bg_image_container img').attr('src') == img_href) {
            // do nothing

          } else {
  					$j('#bg_image_container').append($j('<img>').css({'display':'none'}).attr('src',img_href));		
            $j('#bg_image_container img:first').remove();
            $j('#bg_image_container img').fadeIn(500);
          }
	

					
					
				  /*	Disabled function, not needed
				   if($j('#left_column_small .ngg-galleryoverview').length > 0){ 
						  $j('#location_intro_img img').attr('src',img_href);
						  $j('#location_intro_img img').removeAttr('width').removeAttr('height');
					} 
					*/
			
				});
				
			}	else {
			  
					// set onclick 
					$j('a',this).click(function(){		
					
					$j('#location_intro_img img').show();
					$j('#videoplayer').remove();
					
					/* Videoplayer functionaliteit, wanneer in de carrousel / gallery een title met youtube link zit, dan de gallery ruimte gebruiken voor video */
					if($j('img',this).attr('title').indexOf('http://www.youtube.com') !=-1) {
	
						/* Als adventure layer zichtbaar is, deze sluiten en dan video embedden */
						var margin = $j('#content_layer').css('margin-left');
		
				        if(margin == '-944px'){
				        	$j('#flupje').jani.stop();
				        	$j('#flupje').jani({ frameWidth: 34, frameHeight: 57, speed: 2000, totalFrames: 2 });
				        	$j('#content_layer').animate({'margin-left':'0'});
				        	$j('#flupje').removeClass('active');
				        	$j('#header').css({'position': 'absolute'});
						 }
														
						/* Video URL van Youtube uit de tile halen */
						var videourl = $j('img',this).attr('title');
						videourl = videourl.replace('watch?v=','\/v\/');
						
						/* Embed code voor video opbouwen */
						var embedvideo = ''+
						'<div id="videoplayer">'+
						'<object width="430" height="323">'+
						'<param name="movie" value="'+videourl+'?fs=1&amp;hl=en_US&autoplay=1"></param>'+
						'<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>'+
						'<embed src="'+videourl+'?fs=1&amp;hl=en_US&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" autoplay="true" width="430" height="323"></embed>'+
						'</object>'+
						'</div>';
						$j('#location_intro_img img').hide();
						$j('#location_intro_img').append(embedvideo);
						
					}
					/* 360player functionaliteit, wanneer in de carrousel / gallery een title met -360 zit, dan de gallery ruimte gebruiken voor 360player */					
					else if($j('img',this).attr('title').indexOf('-360') !=-1 || $j('img',this).attr('title').indexOf('-360_2') !=-1) {

							/* Als adventure layer zichtbaar is, deze sluiten en dan video embedden */
							var margin = $j('#content_layer').css('margin-left');
			
					        if(margin == '-944px'){
					        	$j('#flupje').jani.stop();
					        	$j('#flupje').jani({ frameWidth: 34, frameHeight: 57, speed: 2000, totalFrames: 2 });
					        	$j('#content_layer').animate({'margin-left':'0'});
					        	$j('#flupje').removeClass('active');
					        	$j('#header').css({'position': 'absolute'});
							 }
															
							/* Video URL van Youtube uit de tile halen */
							var panorama_url = 'http://www.westergasfabriek.nl/wp-content/uploads/360panoramas/'+$j("img",this).attr("title")+'.swf';
							
							/* Embed code voor video opbouwen */
							var embedvideo = ''+
							'<div id="videoplayer">'+
							'<object width="430" height="323">'+
							'<param name="movie" value="'+panorama_url+'"></param>'+
							'<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>'+
							'<embed src="'+panorama_url+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowFullScreen="true" autoplay="true" width="430" height="323"></embed>'+
							'</object>'+
							'</div>';
							$j('#location_intro_img img').hide();
							$j('#location_intro_img').append(embedvideo);
							
						}
					

					
					$j('.ngg-gallery-thumbnail a').removeClass('active');
					$j(this).addClass('active');
					
					// append img element and remove old one
					$j('#bg_image_container').append($j('<img>').attr('src',img_href));		
					$j('#bg_image_container img:first').remove();
					
					/* Wanneer het een carousel gallery betreft, dan andere indeling van de description blokje */
					if ($j('.ngg-gallery-thumbnail-box.carousel').html()) {
						$j('#ngg-gallery-description').html(img_description);
						Cufon.replace('#ngg-gallery-description h2', { fontFamily: 'TradeGothicLTBold' });
						Cufon.replace('#ngg-gallery-description h6', { fontFamily: 'TradeGothicLT' });
						Cufon.replace('#ngg-gallery-description .carousel-link', { fontFamily: 'TradeGothicLT' });
					}else {
						$j('#ngg-gallery-description p').html(img_title);
					}
					
					if($j('#left_column_small .ngg-galleryoverview').length > 0){
						$j('#location_intro_img img').attr('src',img_href);
						$j('#location_intro_img img').removeAttr('width').removeAttr('height');
					}
					
					return false;
					
				});
			}
		});
		
		if ($j('body.home').html()) {
     
      
			/* first load of page activate the first in carousel */
			var firstCar = $j('.ngg-galleryoverview .ngg-gallery-thumbnail-box').first();
			var img_href = $j('a', firstCar).attr('rel');

			//$j('#bg_image_container').append($j('<img>').attr('src', img_href));
			//$j('#bg_image_container img:first').remove();
			
			
			
			//CARROUSEL
			

			// carrousel on mouse over and out
			$j(".ngg-gallery-thumbnail, #ngg-gallery-description")
			.mouseover(function(){
				stopRotate()
				return false;
			})
			.mouseout(function(){
				startRotate();
				clearInterval(last_object_interval)
				return false;
			})	
			
			for(i=0; i < img_array.length; i++){
				KeepNumbers.push(i);
			}
			Numbers = KeepNumbers.slice();		
			autoRotate();
			
      
			// When we are at the homepage do mouseover else doe click		
			//if ($j('body.home').html()) {
     //   $j(".ngg-gallery-thumbnail").mouseover(function(){ 
			//	$j('a',this).attr('href',$j('.carousel-link',this).attr('href'));
      //  })
			//}
      
          /* Preload images */
    jQuery.preLoadImages(img_array);
	   }
		
		// append first img to background
		if ($j('#location_intro h1').html()) {
		  $j('#ngg-gallery-description h3').html($j('#location_intro h1').html());
	  }


		
	}
	
  
	// Function for start rotating the carrousel
	function startRotate(){
		rotateTimer=setTimeout(function(){
			autoRotate();
		},CarrouselTimeoutTime);
	}
	
	// Function for auto Rotate the carrousel
	function autoRotate(){
		showItem();
		rotateTimer = setTimeout(function(){
			autoRotate();
		},CarrouselTimeoutTime);
	}


	// Function for stop rotating the carrousel
	function stopRotate(){
		if(typeof rotateTimer != 'undefined'){
			clearTimeout(rotateTimer);
		}
	}

	// Function for show carrousel item
	function showItem(){
		
		$j('.ngg-galleryoverview .ngg-gallery-thumbnail-box .ngg-gallery-thumbnail > a:eq('+Numbers[0]+')').mouseover();
		Numbers.shift();
		
		if(Numbers.length == 0){
			Numbers = KeepNumbers.slice();	
		}
	}
	
	
	


/* Function for the ook te doen blokjes */
function initTheRelatedImages(){
    
    var img_array = [];
    
    /* description blokje tonen, niet op homepage carouse, dan zit deze al in de html*/
    if(!$j('body.home').html()){
      $j('<div>').attr('id','ngg-related-description').prependTo($j('#adventure_layer .ngg-related-gallery')).append($j('<h3>')).append($j('<p>'));
			$j('#ngg-related-description h3').html('Ook te doen');
    }
    // for each gallery thumb 
    $j('.ngg-related-gallery .shutterset_Related').each(function(){
            
      // get href, title and description and at them to a array's | 
      var img_href    = $j(this).attr('href');
      var img_description = $j('img',this).attr('alt');
      var img_title   = $j('img',this).attr('title');
      img_array.push(img_href);

      // set onclick 
      $j(this).click(function(){    
        // append img element and remove old one
        $j('#bg_image_container').append($j('<img>').attr('src',img_href));   
        $j('#bg_image_container img:first').remove();
        //$j('#ngg-related-description h3').html('Ook te doen');
				$j('#ngg-related-description p').html(img_description);
        return false;
				
				});
      });
 
    /* Preload images */
    //jQuery.preLoadImages(img_array);
       
  }


/* function to change the Background image on Agenda detail pagina to HighRes version*/
function agendaBGImage(){
  var bgImageAgenda = $j('.agendafoto').attr('src');
  bgImageAgenda = (bgImageAgenda.replace("/L/", "/XL/"));
  $j('.attachment-bg_image').attr('src', bgImageAgenda);
  }




	function initSearch(){
    
    /* language defaults */
    var helesitelabel  = "Hele site";
    var agendalabel     = "Agenda";
    var zoeklabel       = "Zoeken";
    
    if(icl_lang == 'en') {
       helesitelabel = "Site" 
       agendalabel   = "Calendar";
       zoeklabel     = "Search";
       }
    
		if($j('#searchform #s').val() == ''){ $j('#searchform #s').val(zoeklabel)};

		$j('#searchform #s')
		.focus(function(){
      
			if($j(this).val() == zoeklabel){ $j(this).val('')
			} else {
        $j(this).select();
			};
			
			/* fix or when submitting search on agenda search form */
			if ($j('body.page-template-whatson-zoeken-php').html() && ($j('#s_type').val() == 'agenda')) {
        $j('#s').attr('name','agendakeyword');
        $j('#searchform').attr('action','/whats-on/agenda/zoeken');
      }
			
		})
		.blur(function(){
				if($j(this).val() == ''){ $j(this).val(zoeklabel)};
		});
		
    
		$j('#searchform').append(
				  $j('<select>').attr('id','s_type').append(
              
              
						  $j('<option>').val('hele-site').html(helesitelabel),		
						  $j('<option>').val('agenda').html(agendalabel)
				  )
	
		);

		/* Add custom hidden search field to exclude some categories from the search */
		$j('#searchform').append($j('<input>').attr('id','excludefromsearch').attr('type','hidden').attr('name','cat').attr('value','-33'));

		
		if ($j('body.page-template-whatson-zoeken-php').html()) {
		  $j('#s_type').val('agenda');
	  }

    /* activate the fancy search box */
		$j("#s_type").selectbox();

		$j('#s_type').change(function() {
			if($j('#s_type').val() == 'hele-site'){
        $j('#s').attr('name','s');
				$j('#searchform').attr('action','/');
			}else{
        $j('#s').attr('name','agendakeyword');
				$j('#searchform').attr('action','/whats-on/agenda/zoeken');
			}
		});

		Cufon.replace('.jquery-selectbox-item, .jquery-selectbox-currentItem', { fontFamily: 'TradeGothicLT', hover: true });
	}
	
  
  
  /* Functie voor aanmelden bij de nieuwsbrief zakelijk of publiek 
   * door het probleem dat Crossdomain XML niet mogelijk is, is er een XMLproxy gebruikt. 
   */
  
  function aanmeldenNieuwsbrief(){
    
   go = true;
   
   if (!$j('#naam').val() || $j('#naam').val() == 'Naam') {
     $j('#naam').css("border","1px solid red");
     go = false;
   }
   
   if (!$j('#email').val() || $j('#email').val() == 'E-mail') {
     $j('#email').css("border","1px solid red");
     go = false;
   }
   
   if (!$j('#mailing-algemeen:checked').length && !$j('#mailing-nieuwsbrief:checked').length) {
     go = false;
   }

   if (go) {

     var clientString = $j('#aanmelden_nieuwsbrief').serialize();
     
     $j.ajax({
       type: "POST",
       url: "http://www.westergasfabriek.nl/wp-content/themes/toolbox/xmlproxy.php?proxy_url=http://www.mailinglijst.eu/api/Default.aspx",
       data: clientString,
       dataType: "XML",
       success: function(xml){
         $j(xml).find("description").each(function(){
           var description = ($j(this).text());
           aanmeldennieuwsbriefCallback(description);
         })
       }
     })
     
   }
  
  }
	
	function aanmeldennieuwsbriefCallback(description){
    $j('#aanmelden_nieuwsbrief').hide();
    $j('#confirmation span').html(description);
    $j('#confirmation').show()
  }
	
	

	  
	  

	/* ================================ +
	           SKILFUL FUNCTIONS
	 + ================================ */

	function getBrowserSize() {
		        
	    var theWidth, theHeight;
		// Window dimensions: 
		if (window.innerWidth) {
		theWidth=window.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientWidth) {
		theWidth=document.documentElement.clientWidth;
		}
		else if (document.body) {
		theWidth=document.body.clientWidth;
		}
		if (window.innerHeight) {
		theHeight=window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
		theHeight=document.documentElement.clientHeight;
		}
		else if (document.body) {
		theHeight=document.body.clientHeight;
		}

		return [theWidth,theHeight];
	}

	function getPageSize() {
		        
	    var xScroll, yScroll;
	    
	    var OS = BrowserDetect.OS;
		var browser = BrowserDetect.browser;
		var version = BrowserDetect.version;
		
		if((OS == "Windows") && (browser == "Explorer") && (version == "7")){    	
			xScroll = document.body.parentNode.scrollWidth;
			yScroll = document.body.parentNode.scrollHeight;
	    }else{ 
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
		}
		
		var windowWidth, windowHeight;
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	

		
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}



	var BrowserDetect = {
		init: function () {
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},
		searchString: function (data) {
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				var dataProp = data[i].prop;
				this.versionSearchString = data[i].versionSearch || data[i].identity;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
						return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		dataBrowser: [
			{
				string: navigator.userAgent,
				subString: "Chrome",
				identity: "Chrome"
			},
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari",
				versionSearch: "Version"
			},
			{
				prop: window.opera,
				identity: "Opera"
			},
			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]

	};
	BrowserDetect.init();
	
	
	
  /* Flickr display in adventure layer 
  * When the field flickr_tags in post is used, this will be active 
  * 1.12.2010 - By Parkers : Edgar Vijgeboom 
  */
	
	 function flickrImages(taglist) {
	 	
		$j('#social-twitter-content').hide();
	  $j('#social-flickr-content').html('');

		$j.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",
	  {
	    tags: taglist,
	    tagmode: "all",
	    format: "json"
	  },
	  function(data) {
	    $j.each(data.items, function(i,item){
				
	      var p = item.media.m;
				var thumb = p.replace('_m.jpg','_s.jpg');
				var large = p.replace('_m.jpg','_b.jpg');  
				var link = '<a href="#" onclick="setbg(\''+large+'\')"><img src="'+thumb+'"/></a>' ;
				$j(link).appendTo("#social-flickr-content");
			
	      if ( i == 13 ) return false;
	    });
			
			$j('#social-flickr-content').show();
	  });
	
	
	};
		 
		 
 /* Twitter feed display in adventure layer 
  * When the field twitter_tags in post is used, this will be active 
  * 1.12.2010 - By Parkers : Edgar Vijgeboom 
  */
   
	 function	twitterShowFeed(tags){
     
	 	$j('#social-flickr-content').hide();
	  $j('#social-twitter-content').html('');

    // Declare variables to hold twitter API url and user name
    var twitter_api_url = 'http://search.twitter.com/search.json';
    var twitter_user    = 'lupomontero';
    var twitter_tag     = tags;
		
    // Enable caching
    $j.ajaxSetup({ cache: false });

    $j('#social-twitter-content').show();

		lastTweetid = 0;
    getTwitterFeed(lastTweetid,'3');

    // Send JSON request
    // The returned JSON object will have a property called "results" where we find
    // a list of the tweets matching our request query
		function getTwitterFeed(lastTweetId,amount){
			
			//var lastTweetId = tweetid.toString();
			$j.getJSON(twitter_api_url + '?callback=?&rpp='+amount+'&q=' + twitter_tag, //from:' + twitter_user,
			
			
			 function(data){
					
						$j.each(data.results.reverse(), function(i, tweet){
							// Uncomment line below to show tweet data in Fire Bug console
							// Very helpful to find out what is available in the tweet objects
						  //	console.log(tweet);
							
							// Before we continue we check that we got data
							if (tweet.text !== undefined && tweet.id_str != lastTweetId) {
								// Calculate how many hours ago was the tweet posted
								var date_tweet = new Date(tweet.created_at);
								var date_now = new Date();
								var date_diff = date_now - date_tweet;
								var hours = Math.round(date_diff / (1000 * 60 * 60));
								
								// Build the html string for the current tweet
								var tweet_html = '<p>';
								tweet_html += '<a href="http://www.twitter.com/';
								tweet_html += tweet.from_user + '/status/' + tweet.id + '">' + tweet.from_user;
								tweet_html += ': <\/a>' + tweet.text + '<\/p>';
								// Append html string to tweet_container div
					      $j('#social-twitter-content').prepend(tweet_html);
								lastTweetId = tweet.id_str;
							}

						});
						
						    setTimeout(function() {
                getTwitterFeed(lastTweetId,1);
            }, 7000);
					});
				
			}
   };
		
     
     
function setbg(photo) {
	$j('#bg_image_container img').attr('src', photo);
	return false;
}
			

	
	
	
	/* document ready functions */
	$j(document).ready(function(){	
		
		initCufon();
		
		initSearch();
		
		initBackgroundGallery();
		
		initTheRelatedImages();
			

		$j('#map_canvas').css("height",(getPageSize()[1]-150));			//Make the height 100%
		
		if($j('#map_canvas').length > 0){
			initializeGoogleMaps();
		}

		if($j('#flupje').length > 0){
		//	$j('#flupje').jani({ frameWidth: 34, frameHeight: 57, speed: 2000, totalFrames: 5 });
			$j('#flupje').jani({ frameWidth: 34, frameHeight: 57, speed: 2000, totalFrames: 2 });
			$j('#flupje').jani.play();
			$j('#flupje').mouseover(function(){
				$j('#flupje').jani.stop();
			//	$j('#flupje').css('background-position','0 -285px');
				$j('#flupje').css('background-position','0 -57px');
				$j('#flupje.active').css('background-position','0 0');
			}).mouseout(function(){
				$j('#flupje').css('background-position','0 0');
				$j('#flupje').jani.play();
			});
		

			$j('#flupje, #fullscreen').click(function() {
					
          $j('#flupje').jani.stop();
          
          var margin = $j('#content_layer').css('margin-left');

				if(margin != '-944px'){
					$j('#flupje').jani({ frameWidth: 34, frameHeight: 57, speed: 2000, totalFrames: 2 });
					$j('#content_layer').animate({'margin-left':'-944px'});
					$j('#flupje').addClass('active');
					$j('#header').css({'position': 'fixed'});

				}else{

					$j('#flupje').jani({ frameWidth: 34, frameHeight: 57, speed: 2000, totalFrames: 2 });
					$j('#content_layer').animate({'margin-left':'0'});
			        $j('#flupje').removeClass('active');
			        $j('#header').css({'position': 'absolute'});

				}
			});
		}

		
		if($j('#agenda_browser').length > 0){
			if($j('#agenda_date').val() == '' || $j('#agenda_date').length == 0){
				$j('#agenda_browser').calendar();
			}else{
				var current_date = $j('#agenda_date').val().split('-');
				$j('#agenda_browser').calendar({
					date:				new Date(current_date[2],current_date[1] -1, current_date[0]),
				  current_year: 		new Date(current_date[2],current_date[1] -1, current_date[0]).getFullYear(),
				  current_month: 		new Date(current_date[2],current_date[1] -1, current_date[0]).getMonth(),
				  current_day: 		  new Date(current_date[2],current_date[1] -1, current_date[0]).getDate()
				});
			}
		}
		
		
		$j('.attachment-bg_image').removeAttr('width').removeAttr('height');
		
		if($j('#menu_home #menu-homenavigatie').length > 0){
			$j('#menu_home #menu-homenavigatie > li').mouseover(function(){
				$j('#menu_home #menu-homenavigatie > li').removeClass('current_block');
				$j(this).addClass('current_block');
				Cufon.replace('#menu_home #menu-homenavigatie > li  a', { fontFamily: 'TradeGothicLT', hover: true });
			});
			$j('#menu_home #menu-homenavigatie > li:first').addClass('current_block');
		}
		
        if($j('#menu_home #menu-homenavigatie-en').length > 0){
      $j('#menu_home #menu-homenavigatie-en > li').mouseover(function(){
        $j('#menu_home #menu-homenavigatie-en > li').removeClass('current_block');
        $j(this).addClass('current_block');
        Cufon.replace('#menu_home #menu-homenavigatie-en > li  a', { fontFamily: 'TradeGothicLT', hover: true });
      });
      $j('#menu_home #menu-homenavigatie-en > li:first').addClass('current_block');
    }
    
    /* Add this sharing function activation */
   if ($j('#addthis_box').length) {
	   $j('#addthis_box').html('');
     var tbx = document.getElementById("addthis_box"), svcs = {
       facebook: 'Facebook',
       twitter: 'Twitter',
       print: 'Print',
       email: 'Email',
       expanded: 'More'
     };
     
     for (var s in svcs) {
       tbx.innerHTML += '<a class="addthis_button_' + s + '"></a>';
     }
     addthis.toolbox("#addthis_box");
 
   }
   
   
   	$j('#naam').click(function() {
      if ($j('#naam').val() == 'Naam') $j('#naam').val('');
      $j('#nieuwsbriefkeuze').slideDown();
      
    })
    
    $j('#email').click(function() {
      if ($j('#email').val() == 'E-mail') $j('#email').val('');
      $j('#nieuwsbriefkeuze').slideDown();
      
    })
    
   $j('#aanmelden_nieuwsbrief').submit(function() {
      aanmeldenNieuwsbrief();
      return false;
    }) 
    
    $j('a.form-reset').click(function() {
      $j('#confirmation').hide();
      $j('#aanmelden_nieuwsbrief').show();
      $j('#nieuwsbriefkeuze').show();
      return false;
    }) 
		
    $j(function() {
      $j( "#social-container" ).draggable({ cursor: 'pointer' });
      $j( "#social-container" ).resizable();
  
    });
		
		
	 if ($j('.ngg-galleryoverview').html()) {
	 	$j('.ngg-galleryoverview .ngg-gallery-thumbnail-box').each(function(){
            
			if($j('img',this).attr('title').indexOf('http://www.youtube.com') !=-1) {
				var playicon ='<div class="photo-icon" style="background: url(http://www.westergasfabriek.nl/wp-content/themes/toolbox/images/play-icon.png) no-repeat;"></div>';
				$j('a',this).append(playicon);
			}
			else if($j('img',this).attr('title').indexOf('-360') !=-1) {
				var playicon ='<div class="photo-icon" style="background: url(http://thomas.studioparkers.nl/westergasfabriek.nl/trunk/wp-content/themes/toolbox/images/360-icon.png) no-repeat;"></div>';
				$j('a',this).append(playicon);
			}
			});

    }
		
		/* Scrolling script for the Agenda on urbanscreens */
		$j('#agenda-scroll a.up').click(function() {
      $j('html, body').animate({
        scrollTop: '-=500px'
      }, 500);
      return false;

    });
      
   $j('#agenda-scroll a.down').click(function() {
			$j('html, body').animate({
				scrollTop: '+=500px'
			}, 500);
			return false;

		});
    
    $j('#menu-item-4120 > a').click(function() {
      history.back();
      return false;

    });
    
		
	

});	
	
	
	
	
