window.onload = function() {
	if(document.getElementById('slideshow')) {
		var flashvars = { slideshowXML: 'http://www.azdesign.se/slideshow.xml', timerLength: 60 };
		var params = { play: 'true', loop: 'true', wmode: 'transparent' };
		var attributes = {};

		swfobject.embedSWF("http://www.azdesign.se/swf/slideshow.swf", "slideshow", "900", "300", "9.0.0","/swf/expressInstall.swf", flashvars, params, attributes);
	}
	
	if(document.getElementById('imageright') && (!document.getElementById('products') || document.location.href.split('/')[3] == 'produkter.html')) {
		
		if(document.getElementById('contact')) {
			var section = 'contact';
		}else if(document.getElementById('produce')) {
			var section = 'produktion';
		}else if(document.getElementById('contact')) {
			var section = 'contact';
		}else if(document.getElementById('login')) {
			var section = 'login';
		}else if(document.getElementById('cad')) {
			var section = 'cad';
		}else if(document.getElementById('architect')) {
			var section = 'arkitekt';
		}else if(document.getElementById('retailer')) {
			var section = 'aterforsaljare';
		}else if(document.getElementById('designer')) {
			var section = 'designer';
		}else{
			var section = 'azdesign';
		}
	
		var flashvars = { slideshowXML: 'http://www.azdesign.se/image/slideshow/' + section + '/slideshow.xml', timerLength: 60 };
		var params = { play: 'true', loop: 'true', wmode: 'transparent' };
		var attributes = {};

		swfobject.embedSWF("http://www.azdesign.se/swf/slideshow650.swf", "imageright", "650", "250", "9.0.0","/swf/expressInstall.swf", flashvars, params, attributes);
	}
	
	if($("#contact_form").length > 0) {
	
		$("#contact_form").submit(function() {
		
			return validate_form();
		});	
	}
	
	if( $("#slogan").length > 0) {
		slider_text_change();
	}
	
}

function validate_form() {

	if($("#name").val() != "" && $("#profession").val() != "Valjhar" && $("#phone").val() != "" && $("#email").val() != "" && $("#message").val() != "") {
		
		if (/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test($('#email').val())) {
			return true;
		}
		else {
		
			alert("E-postadressen verkar fel.")
			return false;
		}
	}
	else {
	
		alert("Var vänlig och fyll i alla obligatoriska fält.")
		return false;
	}
}

var slider_text_change = function() {
	setTimeout(function(){
		$("#slogan").fadeOut();
		$("#slogan2").fadeIn();
	}, 7000 );
	
	setTimeout(function(){
		$("#slogan2").fadeOut();
		$("#slogan").fadeIn();
	}, 14000 );
	
	setTimeout(function(){
		slider_text_change();
	}, 14000 );
}
