if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed wmode=\"transparent\" type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();_19+="<param name=\"wmode\" value=\"opaque\" />";for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

function getRectangle(elem) {
	var pos = elem.cumulativeOffset();
	var dim = elem.getDimensions();
	return {
		x: pos.left,
		y: pos.top,
		w: dim.width + pos.left,
		h: dim.height + pos.top
	}
}

function isInRect(x, y, rect) {
	return ( x >= rect.x && x <= rect.w && y >= rect.y && y <= rect.h );  
}

function navResize() {
	var newScreenDim = document.viewport.getDimensions();
	var delta = Math.round((currDimensions.width - newScreenDim.width) / 2);
	$$(".subMenu").each( function(element) {
		var dimElem = element.getDimensions();
		element.setStyle({
			left: (parseInt(element.getStyle("left").replace(/px/, "")) - delta) + "px"
		});
	});
	currDimensions = newScreenDim;
	
}

var currDimensions = document.viewport.getDimensions();

function initNav() {
		Event.observe(document, "mousemove", function(e){
			var mouseX = e.pointerX();
			var mouseY = e.pointerY();
			
			$$(".activatedSubMenu").each(function(subMenu) {
				if(! isInRect(mouseX, mouseY, getRectangle(subMenu)) && ! isInRect(mouseX, mouseY, getRectangle($(subMenu.parentNode)))) {
					subMenu.removeClassName("activatedSubMenu");
					subMenu.hide();
				}
			} );
		
			$$(".activatedMenu").each( function(menu) {
				if(! isInRect(mouseX, mouseY, getRectangle(menu)) && ! isInRect(mouseX, mouseY, getRectangle($(menu.parentNode)))) {
					if(menu.select(".activatedSubMenu").length == 0) {
						menu.removeClassName("activatedMenu");
						menu.hide();
					}
				}
			} );			
		});
	
	$$(".subMenu").invoke("hide");
	$$(".subMenu").reverse().each(function(elem) {
		var parentNode = $(elem.parentNode);
		var originalW = parentNode.getDimensions().width + "px"
		elem.show();
		elem.identify();

		var dimElem = elem.getDimensions();
		elem.absolutize();
		elem.setStyle({
			width: dimElem.width + "px", 
			height: dimElem.height + "px"
		});

		elem.select(".subSubMenu").reverse().each(function(subElem) {
			subElem.show();
			subElem.identify();
			var dim = subElem.getDimensions();
			subElem.absolutize();
			var dimParent = $(subElem.parentNode).getDimensions();
			var posParent = $(subElem.parentNode).positionedOffset();
			subElem.setStyle( {
				width: dim.width + "px", 
				height: dim.height + "px", 
				left: (dimParent.width - 1) + "px", 
				top: posParent.top + "px"
			} );
			
			$(subElem.parentNode).observe("mouseover", function(e){ this.addClassName("activatedSubMenu"); this.show() }.bindAsEventListener(subElem));
			
			subElem.hide();				
		});

		$(elem.parentNode).observe("mouseover", function(e){ this.addClassName("activatedMenu"); this.show() }.bindAsEventListener(elem));
		elem.hide();
		parentNode.setStyle({width: originalW});
	});
}

function handleLinks(container) {
	if(! container) {
		container = $$("body").first();
	}
	
	container.select("a.print").invoke("observe", "click", function(e) {
		e.stop();
		var link = e.element();
		window.open(link.href, "printWindow", "width=800,height=600");
	});
	
/*
container.select("a[href*=-popin-]").each(function(link) {
		new Control.Modal(link, {
			className: "modal",
			iframeshim: false,
			closeOnClick: false,
			offsetLeft: 150,
			parameters : {popin: true},
			fade: true,
			onComplete: function(res) {
				this.container.down("#popinCloser").observe("click", this.closeHandler);
				handleLinks(this.container);
			},
			onRemoteContentLoaded : function() {
				this.container.innerHTML.evalScripts();
				pageTracker._trackPageview(link.href );
			}
		});
	});
*/	
	container.select("a.hideShow").each( function(link) {
		link.observe("click", function(e){
			e.stop();
			$$("a.hideShow[rel=" + this.readAttribute("rel") + "]" ).each(function(sameGroupLink) {
				var elemID = sameGroupLink.href.substr(sameGroupLink.href.indexOf("#") + 1);
				if($(elemID)) {
					$(elemID).hide();
				}
			});
			var elemID = this.href.substr(this.href.indexOf("#") + 1);
			if($(elemID)) {
				$(elemID).show();
			}
			this.fire("wedia:afterHideShow")
		}.bindAsEventListener(link));
	});
	
	container.select("a.hideShow[rel=groupContact]").each(function(link) {
		link.observe("wedia:afterHideShow", function() {
			var parentLi = this.up("li");
			parentLi.siblings().invoke("removeClassName", "active");
			parentLi.addClassName("active");
		}.bindAsEventListener(link));
	});
}

Event.observe(window, "load", function(e) {
	handleLinks();
});



var FormValidator = Class.create({
	initialize : function(form, options) {
		this.element = $(form);
		this.waitDiv = $(this.element.parentNode).down(".waitDiv");
		this.options = Object.extend( {
			errorMessage : "The form is invalid", 
			globalErrorTemplate : "#{errorMessage} <ul>#{fieldsErrors}</ul>", 
			fieldErrorTemplate : "<li>#{currErrorMessage}</li>",
			afterThank : Prototype.emptyFunction
		}, options || {});
		this.errorPlace = this.element.down(".errors") || null;
		this.fields = new Array();
		this.element.down("input[type=submit]").hide();
		this.element.down("input[name=submitMode]").value="ajax";
		this.element.down(".submit .sbmButton").show();
		this.element.down(".submit .sbmButton a").observe("click", function(e) {
			e.stop();
			this.submit();
		}.bindAsEventListener(this) );
	},
	
	validate : function() {
		var errors = new Array();
		if(this.errorPlace) {
			this.errorPlace.update("");
		}
		for(var i=0; i< this.fields.length; i++) {
			var field = this.fields[i];
			if(! field.isValid()) {
				errors.push(this.options.fieldErrorTemplate.interpolate(field));
			}
		}
		if(errors.length > 0) {
			var errMessage = this.options.globalErrorTemplate.interpolate({errorMessage: this.options.errorMessage, fieldsErrors: errors.join("")});
			if(this.errorPlace) {
				this.errorPlace.update(errMessage)
			} else {
				alert(errMessage)
			}
			return false;
		}
		return true;
	},
	
	addField : function(fieldName, type, madatory, pattern, errorMessage, patternError) {
		if(type == "radio") {
			this.fields.push( new RadioField(this, fieldName, madatory, pattern, errorMessage, patternError) );
		} else if(type == "checkbox") {
			this.fields.push( new CheckBoxField(this, fieldName, madatory, pattern, errorMessage, patternError) );
		} else if(type == "select" || type == "selectmulti") {
			this.fields.push( new SelectField(this, fieldName, madatory, pattern, errorMessage, patternError) );
		} else if(type == "textarea") {
			this.fields.push( new TextAreaField(this, fieldName, madatory, pattern, errorMessage, patternError) );
		} else {
			this.fields.push( new FormField(this, fieldName, madatory, pattern, errorMessage, patternError) );
		}
	},
	
	submit : function() {
		if(this.validate() ) {
			var parent = $(this.element.parentNode);
			this.element.remove();
			if(this.waitDiv) {
				this.waitDiv.show();
			}
			new Ajax.Updater(parent, this.element.action, {
				parameters : this.element.serialize(),
				evalScripts : true,
				onComplete : function() {
					this.waitDiv.hide();
					this.options.afterThank();
				}.bindAsEventListener(this)
			});
		}	
	} 
});
	
var FormField = Class.create({
	initialize : function(formValidator, fieldName, madatory, pattern, errorMessage, patternErrorMessage) {
		this.field = formValidator.element.select(this.getTagName() + "[name=" + fieldName + "]");
		this.mandatory = madatory;
		this.pattern = pattern;
		this.errorMessage = errorMessage || "the field '" + fieldName + "' is mandatory";
		this.patternErrorMessage = patternErrorMessage || "the field '" + fieldName + "' is invalid";
		this.currErrorMessage = ""
	},
	
	getTagName : function() {
		return "input"
	},
	
	getValue : function()  {
		return $F(this.field.first()).strip();
	},
	
	isValid : function() {
		this.currErrorMessage = "";
		if(this.mandatory && this.getValue() == "") {
			this.currErrorMessage = this.errorMessage;
			return false;
		}
		if(! this.isRegExpValid()) {
			this.currErrorMessage = this.patternErrorMessage;
			return false;
		}
		return true;
	},
	
	isRegExpValid : function() {
		if(this.pattern.strip() == "") {
			return true;
		}
		var re = new RegExp(this.pattern);
		return re.test(this.getValue());
	}
});

var TextAreaField = Class.create(FormField,{
	getTagName : function() {
		return "textarea"
	}	
});

var SelectField = Class.create(FormField,{
	getTagName : function() {
		return "select"
	}	
});

var RadioField = Class.create(FormField,{
	getValue : function()  {
		var res = "";
		this.field.each(function(radio) {
			if(radio.checked) {
				res = radio.value;
			}
		});
		return res;
	}
});

var CheckBoxField = Class.create(FormField,{
	getValue : function()  {
		var res = new Array();
		this.field.each(function(cb) {
			if(cb.checked) {
				res.push( cb.value );
			}
		});
		return res.join(",");
	}
});


var myTransition = function() {
	
}

Effect.Slide = Class.create(Effect.Base, {
	initialize : function(element) {
		var options = arguments[1] || {};
		this.element = $(element);
		
		options = Object.extend({top:0, right:0, bottom: 0, left: 0, mode: 'relative'}, options);
		
		this.margins = {
			top : parseInt(this.element.getStyle("margin-top").replace(/[^-\d]/g, "")),
			right : parseInt(this.element.getStyle("margin-right").replace(/[^-\d]/g, "")),
			bottom : parseInt(this.element.getStyle("margin-bottom").replace(/[^-\d]/g, "")),
			left : parseInt(this.element.getStyle("margin-left").replace(/[^-\d]/g, ""))
		};
		for(var margin in this.margins) {
			if(isNaN(this.margins[margin])) {
				this.margins[margin] = 0;
			}
		}
		this.targetMargins = {
			top : (options.mode == 'relative') ? this.margins.top + options.top : options.top,
			right : (options.mode == 'relative') ? this.margins.right + options.right : options.right, 
			bottom : (options.mode == 'relative') ? this.margins.bottom + options.bottom : options.bottom,
			left : (options.mode == 'relative') ? this.margins.left + options.left : options.left
		};
		this.deltas = {
			top : this.targetMargins.top - this.margins.top,
			right : this.targetMargins.right - this.margins.right,
			bottom : this.targetMargins.bottom - this.margins.bottom,
			left : this.targetMargins.left - this.margins.left
		}
		this.start(options);
	},
	update : function(position) {
		this.element.setStyle({
			marginTop : Math.round(this.margins.top + (this.deltas.top * position)) + "px",
			marginRight : Math.round(this.margins.right + (this.deltas.right * position)) + "px",
			marginBottom : Math.round(this.margins.bottom + (this.deltas.bottom * position)) + "px",
			marginLeft : Math.round(this.margins.left + (this.deltas.left * position)) + "px"
		});
	}
});


