
/* alleen voor online */
/*
splitUrl(location.hostname);

function splitUrl(url)
{
   if(url.indexOf("www") >= 0){
     
   }   
   else
   {
    var sUrl = document.location.href;
      var urlArray = sUrl.split('//');
      document.location.href = urlArray[0] + "//www." + urlArray[1];
     //alert(urlArray[0] + "//www." + urlArray[1]);
   }
}

*/


function initPopups()
{
    var arrPopUp = $$(".openPopup");
        arrPopUp.each(function(el){
        el.addEvent("click",function(){
           // showFlagForm(el.getProperty("id"));
        });
    });
    
}

function setIE6hovers()
{
	if ( Browser.Engine.trident4 )
	{
		var tuinen = $$('.gbl-tuin-article');
		var searchresults = $$('.result-item');

		if ( tuinen != '' )
		{
			tuinen.each(function(el)
				{ 
					el.addEvent("mouseenter", function(){ this.addClass('gbl-tuin-article-hover-ie'); }); 
					el.addEvent("mouseleave", function(){ this.removeClass('gbl-tuin-article-hover-ie'); });
				});
		}
		if ( searchresults != '' )
		{
			searchresults.each(function(el)
				{ 
					el.addEvent("mouseenter", function(){ this.addClass('result-item-hover'); }); 
					el.addEvent("mouseleave", function(){ this.removeClass('result-item-hover'); });
				});
		}
	}
}

function SetWrapper()
{

}

function SetContentWrapper() {

	var boolResizeBody = ($$("body.tuinroute").length > 0) ? false : ($$("body.tuintripplanner").length > 0) ? false : true ;
	
	

	var elLeftCol = $$(".gbl-left-coll");
	var elRightCol = $$(".gbl-right-coll");

	var boolResizeCols= false;
	if ((elLeftCol != null && elLeftCol.length > 0) && (elRightCol != null && elRightCol.length > 0) ) {
		boolResizeCols =  true;
	}

	var boolResizeMarker = true;
	/*if(!boolResizeBody){
		//var allMarkers = allMarkers;
		alert(allMarkers);
		if (allMarkers.length >= 3) {
			boolResizeMarker = true;
		} else {
			boolResizeMarker = false;
		}
		
	}*/

	if(boolResizeBody && boolResizeCols) {
		var cHeight = window.getScrollSize().y;
		elLeftCol = elLeftCol[0];
		var iLeftHeight = elLeftCol.getScrollSize().y;

		elRightCol = elRightCol[0];
		var iRightHeight = elRightCol.getScrollSize().y;

		
		if((iRightHeight > iLeftHeight) && (elRightCol != null && elLeftCol != null)){
			var elLeftContent = $$(".gbl-lc-content")[0];
			var elNavHeight = $$(".gbl-navigation")[0].getScrollSize().y;
			var iNewHeight = iRightHeight - elNavHeight - 40;
			elLeftContent.setStyle("height", iNewHeight);
		} else if((iRightHeight < iLeftHeight) && (elRightCol != null && elLeftCol != null)){
			//var iNewHeight = iLeftHeight;
			//elRightCol.setStyle("height", iNewHeight);
		}
	}
	//schep meuk
	var boolResizeHome = ($$("body.home").length > 0) ? true : false;
	var elDeco = $$(".gbl-decorative-schrijf-in");
	boolResizeHome = (elDeco.length > 0) ? true : false;
	//var boolResizeHome = false;
	if(boolResizeHome){
		
		var elDeco = $$(".gbl-decorative-schrijf-in")[0];
		elDecoHeight = elDeco.getSize().y;
		
		elWrap = $("gbl-wrapper");
		elWrapHeight = elWrap.getSize().y;
		elWrap.setStyle("height",elDecoHeight + elWrapHeight);

		//elDeco.setStyle("bottom",-elDecoHeight);

	}
	
}


function goBackInHistory()
{
	var el = $$('.btn-terug');

	if (el != '')
	{
		el.each(function(el){ el.addEvent("click", function(){ history.back(); } ); } );
	}
}

function bookmark()
{
	var el = $$('.btn-bookmarken');
	var url = document.location;

	if ( el != '')
	{
		el.each(function(el){ el.addEvent("click", bookmarkCurrent);});
		
	}
	function bookmarkCurrent()
	{
		 if (Browser.Engine.trident)
		  {
			window.external.AddFavorite(url, "Voeg een kleine bescrijving toe");
		  }
		  else if (window.sidebar)
		  {
			  window.sidebar.addPanel("Voeg een kleine bescrijving toe", url, "");
		  }
	}
}

function setCollums()
{
	
	var leftcoll = $$('.gbl-left-coll');
	var rightcoll = $$('.gbl-right-coll');

	var leftcollHeight = leftcoll.getStyle('height');
	var rightcollHeight = rightcoll.getStyle('height');

	if ( leftcollHeight > rightcollHeight )
	{
		var height = leftcollHeight;
		rightcoll.setStyle("height", height);
	}
	else if ( leftcollHeight < rightcoll.getStyle('height'))
	{	
		var offset = "70";
		var height = parseInt(rightcoll.getStyle('height'));
		finalHeight = height - offset;

		$$('.gbl-lc-content').setStyle("height", finalHeight.toString() + "px");
	}
	
}

function SetCheckboxes()
{
	var checkers = $$("input'[type=checkbox]");

	if (checkers != '')
	{
		checkers.each(function(el)
		{ 
			
			
		});
	}
}

function InitGallery()
{
	//hiding elements
	var arrImages = $$('.image-gallery-large');
	arrImages.each(function(el){ el.setStyle('display', 'none'); });

	//setting thumbs
	var arrThumbs = $$('.gbl-profiel-image-gallery .image-gallery-thumb');
	
	var sCur = arrThumbs.getLast();
	if (sCur != null)
	{
		var currentImg = sCur.getProperty('id');

		$('large-'+currentImg).setStyle("display", "block");
	
		arrThumbs.each(function(el){
			el.addEvent('click', function(){
				sId = el.getProperty('id');
				
				if ( sId != '' && sId != currentImg )
					{
						$('large-'+currentImg).setStyle('display','none');
						$('large-'+sId).setStyle('display','block');
						currentImg = sId;
					}
				});
			});
	}
}

function resetInputValues()
{
	var el = $$(".onclickReset");

    el.each(function(el){ el.addEvent("click", function(){ this.value=''; }); });

}

function readClientHeight()
{
	var Cheight = document.body.clientHeight;
	
	var el = $('gbl-wrapper');

	el.setStyle("display", "none !important");
}




  // end flag review scripts

	function copyFileValues()
{	
	var el = $('profielfoto');
	var elFake = $('fake-profiel-foto');
	
	el.addEvent("click", function()
	{
		var waarde = el.getProperty('value');

		
		elFake.setProperty('value', waarde);

	});	
}

function OverBox()
{ 
	var wrapperHeight = document.body.clientHeight;
	var wrapperWidth = document.body.clientWidth;

	var elTrigger = $$('.keuring-wrapper a.btn-afkeuren');
	var elClose = $$('.overbox-content a.close-overbox-btn');
	
	elTrigger.addEvent("click", function()
	 {
		var overlay = $$('.overbox-main-wrapper');
		overlay.setStyles({ display: 'block', height: wrapperHeight, width: wrapperWidth });
	 });

	 elClose.addEvent("click", function()
	 {
		var overlay = $$('.overbox-main-wrapper');

		overlay.setStyle("display", "none");
		
	 });
}


function addEventsSearchedItems() {
		$$(".result-item").each(function(el) {
			el.addEvent("click", function(){
				var sAddId = this.getProperty("garden_id");
				window.location.href="/garden.aspx?id=" + sAddId;
			});
		});
}

function addToPlanner(){
	var aMessages = {
	"alert-added":"Deze tuin is toegevoegd aan de Tuintripplanner. Ga naar de Tuintripplanner voor een lijst en een kaartje.",
	"alert-removed":"Deze tuin is verwijderd van de Tuintripplanner",
	"add": "Voeg toe aan Tuintripplanner",
	"remove": "Verwijder van Tuintripplanner"
	 };

	$$(".gbl-search-result-items .btn-voeg-aan-tuintrip", ".gbl-profiel-overview .btn-voeg-aan-tuintrip", "#gardenroutes .btn-voeg-aan-tuintrip").each(function(el){

		var sAction = "add";
		var sText = "";
		var sId = el.getProperty('garden_id');
		var sIds = _sTuinTripPlannerIds;
		if(sIds != '' || sIds != null) {
			var sIds = _sTuinTripPlannerIds;
			var arrCurIds = sIds.split(',');
			if(arrCurIds.contains(sId)) {
				sText = aMessages["remove"];
				sAction = "remove";
			} else { 
				sText = aMessages["add"]
				sAction = "add";
			}
		}
		el.set('text',sText);

		el.addEvent('click', function(e){
			
			e = new Event(e).stop();
			var myRequest = new Request({
			url: "/tuintripplanner/service.aspx",
			method: 'get',
			onSuccess: function(responseText){
					
					if(sAction == "remove") { 
						adjustPlannerCount(sAction);
						alert(aMessages["alert-removed"]);
						sText = aMessages["add"];
					}
					else {
						adjustPlannerCount(sAction);
						alert(aMessages["alert-added"]);
						sText = aMessages["remove"];
					}
					
					if(sAction == "remove") { sAction = "add"; }
					else if (sAction == "add") { sAction = "remove";  }
					
					el.set('text',sText);
					
				},
			onFailure: function(){
					//alert('Sorry, kon tuin niet toevoegen of verwijderen.');
				}
			}).send('action='+sAction+'&id='+sId);
			
			;
		});
	});
}
function adjustPlannerCount(sAction){

	var el = $("ttp-i");
	var i = "";
	if(el != null){
		i = el.get('text');
		i = i.toInt();
	} else { return false; }
	
	if(sAction == "remove" && i > 0){
		i = i - 1;
	} else {
		i = i + 1;
	}
	el.set('text',i);
}

function setFlash()
{
 swfobject.embedSWF("/assets/project/flash/gbl-banner-shop.swf", "adv-alt", "216", "216", "9.0.0");
}

function initSifr() 
{  
	 var frutiger = {
      src: '/assets/project/flash/frutiger.swf'
      ,ratios: [7, 1.32, 11, 1.31, 13, 1.24, 14, 1.25, 19, 1.23, 27, 1.2, 34, 1.19, 42, 1.18, 47, 1.17, 48, 1.18, 69, 1.17, 74, 1.16, 75, 1.17, 1.16]
    };

	  sIFR.activate(frutiger);

    sIFR.replace(frutiger, {
	   wmode: 'transparent'
      ,selector: 'h2'
      ,css: [
        '.sIFR-root { color:#366366; font-size:13px; }'
      ]
    });

	   sIFR.replace(frutiger, {
	   wmode: 'transparent'
      ,selector: 'h2.kalender'
      ,css: [
        '.sIFR-root { color:#366366; font-size:16px; text-align:center !important; }'
      ]
    });
}

function JSFX_FloatDiv(id, sx, sy) {

    var el = dF.getElementById ? dF.getElementById(id) : dF.all ? dF.all[id] : dF.layers[id];
    var px = document.layers ? "" : "px";

    window[id + "_obj"] = el;
    if (dF.layers) el.style = el;
    el.cx = el.sx = sx; el.cy = el.sy = sy;
    el.sP = function(x, y) { this.style.left = x + px; this.style.top = y + px; };

    el.floatIt = function() {
        var pX, pY;
        pX = (this.sx >= 0) ? 0 : ns ? innerWidth :
			    document.documentElement && document.documentElement.clientWidth ?
			    document.documentElement.clientWidth : document.body.clientWidth;
        pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ?
			    document.documentElement.scrollTop : document.body.scrollTop;
        if (this.sy < 0)
            pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ?
			    document.documentElement.clientHeight : document.body.clientHeight;
        this.cx += (pX + this.sx - this.cx) / 8; this.cy += (pY + this.sy - this.cy) / 8;
        this.sP(this.cx, this.cy);
        setTimeout(this.id + "_obj.floatIt()", 10);
    }
    return el;
}
function showFlagForm() {

    var wrapperHeight = document.body.clientHeight;
    var wrapperWidth = document.body.clientWidth;

    var elClose = $$('.overbox-content a.close-overbox-btn');
    var elSendFrm = $('btnSend');
    var overlay = $$('.overbox-main-wrapper');

    //overlay.setStyles({ display: 'block', height: wrapperHeight, width: wrapperWidth });

    var iTop = window.getHeight() / 2;
    var iLeft = window.getWidth() / 2;

    if ($('passWAlert')) $('passWAlert').setStyles({ "display": "block", "z-index": "999", "position": "absolute", "top": iTop, "left": iLeft });

    JSFX_FloatDiv("passWAlert", 100, 300).floatIt();

    //$('frmSucces').setStyle("display", "none");     

    elClose.addEvent("click", function() {
    if ($('passWAlert')) { $('passWAlert').setStyle("display", "none"); }
    });

    elSendFrm.addEvent("click", function() {

        $('frmSendPsw').onsubmit = function() {
            $('frmSendPsw').set('send', {
                onComplete: function(txt) {
                    if (txt != "ok") {
                        $('pswResponse').set('html', txt);
                    } else {
                        $('pswResponse').set('html', txt);
                        $('pswResponse').removeClass('error');
                    }

                }
            });
            this.send();

            return false;
        }
    });
}


function showPassw() {

    var wrapperHeight = document.body.clientHeight;
    var wrapperWidth = document.body.clientWidth;

    var elClose = $$('.overbox-content a.close-overbox-btn');
    var elSendFrm = $('btnSendPsw');
    var overlay = $$('.overbox-main-wrapper');

    //overlay.setStyles({ display: 'block', height: wrapperHeight, width: wrapperWidth });

    var iTop = window.getHeight() / 2;
    var iLeft = window.getWidth() / 2;

    if ($('passWAlert')) $('passWAlert').setStyles({ "display": "block", "z-index": "999", "position": "absolute", "top": iTop, "left": iLeft });

    JSFX_FloatDiv("passWAlert", 100, 300).floatIt();

    //$('frmSucces').setStyle("display", "none");     

    elClose.addEvent("click", function() {
        if ($('passWAlert')) { $('passWAlert').setStyle("display", "none"); }
    });

    elSendFrm.addEvent("click", function() {

      
        $('frmSendPsw').onsubmit = function() {
            $('frmSendPsw').set('send', {
                onComplete: function(txt) {
                    if (txt != "ok") {
                        $('pswResponse').set('html', txt);
                    } else {
                        $('pswResponse').set('html', txt);
                        $('pswResponse').removeClass('error');
                    }

                }
            });
            this.send();

            return false;
        }
    });
}

/*
Script: PlaceholderInput.js
	Sets a default message for input type="text" and textareas

	License:
		MIT-style license.

	Authors:
		Guillermo Rauch
*/

var PlaceholderInput = new Class({
  
  initialize: function(element, klass){
    this.klass = klass || 'input_placeholder';
    this.element = $(element).store('placeholder', this);    
    this.placeholder = this.element.get('placeholder');
    this.element.addEvents({
      'focus': this.focus.bind(this),
      'blur': this.blur.bind(this)
    }).removeClass(this.klass).set('autocomplete', 'off');
    this.reset();
  },
  
  focus: function(){
    if(this.placeholder && (this.element.get('value', true) == this.placeholder) && this.active) {
      this.element.set('value', '', true).removeClass(this.klass);
			this.active = false;
    }
  },
  
  blur: function(){
    if(this.placeholder && this.element.get('value', true) == '') {
      this.element.addClass(this.klass).set('value', this.placeholder, true);
      this.active = true;
    }
  },
  
  reset: function(){
    this.focus();
    this.blur();
    return this;
  },
  
  setText: function(v){
    this.placeholder = v;
    this.element.set('placeholder', v).set('value', '');
  }
  
});

Element.Properties.value = {

  get: function(real){
    var value = this.value, place = this.retrieve('placeholder');
    if(real || ! place) return value;
    if(place && place.active) return '';
    return value;
  },

  set: function(value, real){
    var place = this.retrieve('placeholder');
    this.value = value;
    if(place && ! real) place.reset();
  }
  
};

function initOverTextLogin(){
	if($('loginName') != null && $('loginPassword') != null){
		new PlaceholderInput($('loginName'));
		new PlaceholderInput($('loginPassword'));
	}
};


function initDomReady() {

    if ($('reminderAlert')) { $('reminderAlert').setStyle("display", "none"); }
    if ($('passWAlert')) { $('passWAlert').setStyle("display", "none"); }
    
    if ($('wachtwoord')) {
        $('wachtwoord').addEvent('click', function() {
           
            showPassw();
        });
	}
        
	initPopups();
	SetWrapper();
	resetInputValues();
	if($("print") == null) { InitGallery(); }
	SetCheckboxes();
	//setCollums();
	//search
	if($$("body.search").length > 0){
		addEventsSearchedItems();
		addToPlanner();
	}
	//profiel
	if($$("body.profiel").length > 0){
		addEventsSearchedItems();
		addToPlanner();
	}
	
	bookmark();
	goBackInHistory();
	setIE6hovers();
	//initSifr();
	setFlash();
	SetContentWrapper();
	initOverTextLogin();

}

function initLoad(){
	
}


function setForeground(){
	var shovel = document.getElementById("shovel");
	var sign = document.getElementById("sign");

	shovel.style.top = alertSize() + getScrollXY();
	alert(shovel.style.top);
}

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return scrOfY;
}

var dF = document;
var ns = (navigator.appName.indexOf("Netscape") != -1);
    
window.addEvent('domready', initDomReady);
window.addEvent('load', initLoad);
