/*

Project:	Input Placeholder Text
Title:		Automatic population of form fields with contents of title attributes
Author      Jon Gibbins (aka dotjay)
Created:	13 Aug 2005
Modified:	26 Oct 2009



Notes:

Add the following classes to text inputs or textareas to get the 
desired behaviour:

auto-select
	Will pre-populate the input with the title attribute and select the
	text when it receives focus.

auto-clear
	Will pre-populate the input with the title attribute and clear the 
	text when it receives focus. Note: if auto-select and auto-clear 
	are set, auto-select takes precedence.

populate
	Will just populate the input with the title attribute.

NB: A class name of "placeholder" is set on form inputs that have 
placeholder text in them. This allows you to style the inputs 
differently when there is user input versus placeholder text, e.g.
input.placeholder,
textarea.placeholder{
color: #777;
}



Potential additions:

Add in handling of default text if an initial value is detected (line 
60, line 93, etc) using something like:
if (!el.defaultValue) continue;
el.onfocus = function() {
	if (this.value == this.defaultValue) this.value = "";
}
el.onblur = function() {
	if (this.value == "") this.value = this.defaultValue;
}


*/

function hasClass(el,cls) {
	return el.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(el,cls) {
    if (!this.hasClass(el,cls)) el.className += " "+cls;
}
function removeClass(el,cls) {
    if (hasClass(el,cls)) {
        var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
        el.className = el.className.replace(reg,' ');
    }
}
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function initFormPlaceholders() {

	if (!document.getElementsByTagName) return true;

	ourForms = document.getElementsByTagName('form');

	// go through each form
	var numForms = ourForms.length;
	for (var i=0;i<numForms;i++) {

		// go through each form element
		var numFormElements = ourForms[i].elements.length;
		for (var j=0;j<numFormElements;j++) {

			var el = ourForms[i].elements[j];

			// ignore submit buttons
			if (el.type == "submit") continue;

			// if we got a text type input or textarea
			if ((el.type == "text") || (el.type == "textarea")) {
				// only populate if we want it to
				// note: might want title attribute but no pre-population of inputs
				var ourClassName = el.className;
				if (ourClassName.match('auto-select') || ourClassName.match('auto-clear') || ourClassName.match('populate')) {
					// only populate if empty
					if (el.value == '') {
					    addClass(el, "placeholder");
					    el.value = el.title;
					}
				}

				// add auto select if class contains auto-select
				// note: else if below so auto-select takes precedence (assuming select is better than clear)
				if (el.className.match('auto-select')) {
					el.onfocus = function () {
						if (this.value == this.title) {
						    removeClass(this, "placeholder");
						    this.select();
						}
					}
					if (el.captureEvents) el.captureEvents(Event.FOCUS);

					el.onblur = function () {
						if (this.value == '') {
						    this.value = this.title;
						}
						if (this.value == this.title) {
						    addClass(this, "placeholder");
						}
					}
					if (el.captureEvents) el.captureEvents(Event.BLUR);
				}

				// add auto clear if class contains auto-clear
				else if (el.className.match('auto-clear')) {
					el.onfocus = function () {
						if (this.value == this.title) {
						    removeClass(this, "placeholder");
						    this.value = '';
						}
					}
					if (el.captureEvents) el.captureEvents(Event.FOCUS);

					el.onblur = function () {
						if (this.value == '') {
						    this.value = this.title;
						}
						if (this.value == this.title) {
						    addClass(this, "placeholder");
						}
					}
					if (el.captureEvents) el.captureEvents(Event.BLUR);
				}
			}

		}

	}

}

addLoadEvent(initFormPlaceholders);
;
function sendMail(email, subject) {
  if (subject) {
    var fullAddress = "mailto:"+email+"@rightmarktonderzoek.nl?subject="+subject;
    window.self.location = fullAddress;
  }
  else {
    var fullAddress = "mailto:"+email+"@rightmarktonderzoek.nl";
    window.self.location = fullAddress;
  }
};


function InitOpdrachtgevers(){
	/* =============================================
	*	Opdrachtgever images width or height
	*	Move to preprocess page
	*/
	
	jQuery.each(jQuery(".view-opdrachtgevers .opdrachtgeverafbeelding img"), function(){
		var height = jQuery(this).height();
		var width = jQuery(this).width();
		
		//check waar hij het verst over zit
		var diffHeight = height - 50;
		var diffWidth = width - 120;
		
		if(diffHeight > diffWidth){	
			if(height > 50){
				var newHeight = height - diffHeight - 10;
				jQuery(this).css("height", newHeight + "px");
			}
		}else {
			
			if(width > 120){
				var newWidth = width - diffWidth - 20;
				jQuery(this).css("width", newWidth + "px");
			}
		}
		
	});
}

function SloganAnimation(){

	var spanStyles = "position:absolute; right: 116px; opacity: 0;filter: alpha(opacity=0); line-height: 60px;";
	
	var animateOptions = {
		"opacity":".3",
		"right": "60",
		"line-height": "100",
		"bottom": "30",
		"font-size":"500%"
	};

	
if((jQuery.browser.msie)&&(jQuery.browser.version < 8)){
	return false;
	/*
	spanStyles = "position:absolute; text-align:right; right: 116px; opacity: 0; line-height: 60px; bottom:0; line-height: 60px;";
	animateOptions = {
		"opacity":".3",
		"right": "60",
		"font-size":"500%",
		"line-height": "100",
		"bottom": "-10px"
		};
    */		
	}

	// split each word of slogan into array.
	var text = jQuery("#site-slogan").html().split(" ");
	// Put the word Echt in a span with id echt and give its correct css settings
	var echt = "<span id='echt' style='" + spanStyles + "'>" + text[3] + "</span>";
	// Attach it to the slogan container	
	jQuery("#site-slogan").append(echt);
	// Reset slogan css.
	jQuery("#site-slogan").css({
		"right": 0,
		"opacity": 0
	});
	// Start the animation.
	jQuery("#site-slogan").animate({
			// Fade in the text in 2 seconds.
			"opacity":1
		}, 2000, function() {
			// When fading is complete. Display the word Echt with fade and increasing size in 2 seconds.
			jQuery("#echt").animate(animateOptions, 600, function(){
				// If the word Echt is big on the screen hide it in .4 seconds
				jQuery("#echt").animate({
					"opacity":0
				} , 400);
			});
			// simultaneously move the text to the left in 8 seconds.
			jQuery("#site-slogan").animate({
				"right": +80
			}, 8000)
			// Move the text quickly to the far left of the screen and hide it in the progress.
			.animate({
				"right":"600px",
				"opacity":0
			},300, function(){
			// At the end of the function, clean up the created span and start it over in 10 seconds.
				jQuery("#echt").remove();
				setTimeout("SloganAnimation()", 10000);
			});
		}
	); // End of animation
};
jQuery(document).ready(function(){
	/* =============================================
	*	Attentions
		When td.children is empty set the background to none
	*/
	jQuery("#header img.slide").css("display","block");
	jQuery("#site-slogan").css("color", "#" + Drupal.settings.right.sloganColor);
	jQuery("*").removeClass("right-hide-no-js");
	
	//Check children
	var td = jQuery(".view-attentions-view td");
	
	jQuery.each(td, function(){
		if(jQuery(this).children().size() == 0){
			jQuery(this).css("background", "none");
		}
	});
	
	// Create Clickable TD's
	jQuery(".view-attentions-view td").click(function(){
		var url = jQuery(this).find("a").first().attr("href");
		window.location =url;
	});
	
	//hover
	jQuery(".view-attentions-view td").hover(
		function(){			
			jQuery(this).find(".attentiontitle a").css("cssText", "color: #1baaa9 !important");
			jQuery(this).find(".attentiontitle").css("cssText", "color: #1baaa9 !important");
		}, 
		function(){
			jQuery(this).find(".attentiontitle a").css("cssText", "color: #000 !important");
			jQuery(this).find(".attentiontitle").css("cssText", "color: #000 !important");
	});	

	/* =============================================
	*	Replace the custom panels | #opdrachtgeverPanel, #casesPanel to go before the #content .field-name-body
	*/
	//first check if we have a #opdrachtgeverPanel, #casesPanel
	if(jQuery("#opdrachtgever-case-panel-wrapper").length > 0){
		jQuery("#content .field-name-body").before(jQuery("#opdrachtgever-case-panel-wrapper"));
	}
	
	/* =============================================
	*	Language bar
	*/
	jQuery("#menu-duits").html("");
	jQuery("#menu-engels").html("");
	
	/* =============================================
	*	Search frame
	*/
	jQuery("#cse-search-results").find("iframe").height(1000);
	
	/* =============================================
	*	Right button meer info hack
	*/
	jQuery(".extra-right-button").each(function(){
		jQuery(this).appendTo(".field-name-body");
	});
	
	/* =============================================
	*	Animate header text
	*	And dirty fix for dirty browser
		Dit moet gewoon in een ie7.css ?
	*/ 	
	/*if(jQuery.browser.msie && jQuery.browser.version == "7.0"){
		
		jQuery("#site-slogan").css({"right":"-100px","line-height":"28px"});
		jQuery("#search-box input[type='submit']").css("margin-top","10px");
	}*/
	if(!Drupal.settings.right.disableSlogan){
		SloganAnimation();
	}
	
	if(Drupal.settings.right.hideSlogan){
		jQuery("#site-slogan").hide();
	}
	
	setTimeout("InitOpdrachtgevers()", 500);
	
	//remove h3 from sectormenu
	jQuery("h3", ".sectormenu").remove();
});;

