// ü
//###################################################################################
//	Page
//###################################################################################
function Page() {
	
	var varia = new Array();
	var screen_w = 0;
	var screen_h = 0;
	var xhr = '';
	var arr_blendingfields = new Array();
	var divid = '';
		
	//------------------------------------------------------------------------------
	/**
	 * 
	 * @return void
	 */
	this.__construct = function() {
		this.request = new AjaxRequest();
	}
	
		
	
	//------------------------------------------------------------------------------
		
	
	this.CheckSmallScreenSize = function () {
	
		this.GetBrowserScreenSize();
	
		if (this.screen_w < 960) {
			this.MakeCssNode("style/style_gen1024.css");
		}
	}
	
	
	
	this.GetBrowserScreenSize = function () {
					
		//IE
		if (!window.innerWidth) {
			//strict mode
			if(!(document.documentElement.clientWidth == 0)) {
				this.screen_w = document.documentElement.clientWidth;
				this.screen_h = document.documentElement.clientHeight;
			} else {
			//quirks mode
				this.screen_w = document.body.clientWidth;
				this.screen_h = document.body.clientHeight;
			}
		} else {
		//w3c
			this.screen_w = window.innerWidth;
			this.screen_h = window.innerHeight;
		}		
	}
	
	
	
	
	this.MakeCssNode = function (cssfile) {
								
		loadcss = document.createElement('link');
		loadcss.setAttribute("rel", "stylesheet");
		loadcss.setAttribute("type", "text/css");
		loadcss.setAttribute("href", cssfile);
		document.getElementsByTagName("head")[0].appendChild(loadcss);
	}
	
	
	
	
	
	this.init = function() {
		
		// ------------------------------
		// Contact Slider 
		// ------------------------------
		
		if ( $("contact_slider") ) {
			
			var slider = $("contact_slider");
				
			
			slider.set('slide', {
				transition: Fx.Transitions.Quart.easeOut, 
				duration: 150,
				onComplete: function() {
					$("contact_expander").setStyle('visibility', 'visible');
					$("contact_slider").setStyle('visibility', 'visible');		
				}
			});
			
			slider.slide('out');	
			
			var mousearea = $("contact_expander");
			
			mousearea.addEvent("mouseout", function(e){
				slider.slide('out');
				e.stop();
			});
				 
			mousearea.addEvent("mouseover", function(e){
				slider.slide('in');
				e.stop();
			});
	}
	
	
			
		// ------------------------------
		// Meta Menu
		// ------------------------------
		
		var mboverlay = new overlay();
		
		var mb_meta_ajax = new multiBox('mb_lock', {
			overlay: mboverlay
		});
		
		var mb_meta_ajax = new multiBox('mb_lifebelt', {
			overlay: mboverlay
		});
		
        var mb_pics = new multiBox('mb_pics', { 
            overlay: mboverlay
        }); 
	}
	
	
	this.initStartSTCButtons = function() {
		
		// ------------------------------
		// Software/Technik/Consulting 
		// Button Fades
		// ------------------------------
		 
		var fade_in = 0.6;
		var fade_out = 1;
		
		// Software
		
		if ($('bto_dsoftware')) {
		
			$('bto_dsoftware').fade(fade_out);
			
			$('bto_dsoftware').addEvent('mouseover', function(){
				$('bto_dsoftware').fade(fade_in);
				$('bto_dsoftware').setStyle('cursor', 'pointer');	
			});
			
			$('bto_dsoftware').addEvent('mouseout', function(){
				$('bto_dsoftware').fade(fade_out);
			});
			
			$('bto_dsoftware').addEvent('click', function(){
				window.location.href="index.php?p=intro_sw";
			});
		}
		
		// Consulting
		
		if ($('bto_dconsulting')) {
		
			$('bto_dconsulting').fade(fade_out);
			
			$('bto_dconsulting').addEvent('mouseover', function(){
				$('bto_dconsulting').fade(fade_in);
				$('bto_dconsulting').setStyle('cursor', 'pointer');
			});
			
			$('bto_dconsulting').addEvent('mouseout', function(){
				$('bto_dconsulting').fade(fade_out);
			});
			
			$('bto_dconsulting').addEvent('click', function(){
				window.location.href="index.php?p=intro_cs";
			});
		}
		
		// Technik
		
		if ($('bto_dtechnik')) {
		
			$('bto_dtechnik').fade(fade_out);
			
			$('bto_dtechnik').addEvent('mouseover', function(){
				$('bto_dtechnik').fade(fade_in);
				$('bto_dtechnik').setStyle('cursor', 'pointer');
			});
			
			$('bto_dtechnik').addEvent('mouseout', function(){
				$('bto_dtechnik').fade(fade_out);
			});
				
			$('bto_dtechnik').addEvent('click', function(){
				window.location.href="index.php?p=intro_te";
			});
		}
	}
	
	
	this.initStartBodyFields = function() {
		
		// ------------------------------
		// body fields
		// ------------------------------
		
		var arr_bodyfield_type = new Array (
			'div.bodyfield_1x3_border',					  
			'div.bodyfield_1x1_border',
			'div.bodyfield_2x1_border',
			'div.bodyfield_3x2_border'
		);
		
		
		for (i=0; i<arr_bodyfield_type.length; i++) {
		
			$$(arr_bodyfield_type[i]).each(function(el){
				page.SetBFMouseActions(el); 
			});
		}	
	}
	
	
	
	// --------------------------------------------------
	// BLEND BODY FIELD
	// --------------------------------------------------
	
	
	this.initStartFieldBlender = function () {
		
		// set div (ID) that shall be blended:
		divid = 'blending_content';
		
		// load content of all stages (ajax):
		if ($(divid)) {
			
			// !!!! fp: no ".php" because of querystring  !!!!
			//this.getHTML('sd/sd_3x2_hometeaser_plain',false);
			this.getHTML('sd/sd_4x2_hometeaser_plain',false);
			this.getHTML('iclercher/iclercher_4x2_hometeaser_plain',false);
			this.getHTML('meda/meda_4x2_hometeaser_plain',false);
			this.getHTML('parostatus/paro_4x2_hometeaser_plain',false);
			this.getHTML('praxisgruendung/praxisgruendung_4x2_hometeaser_plain',false);
			this.getHTML('abrechnung/abrechnung_4x2_hometeaser_plain',true);
			//this.getHTML('home/home_3x2_wiimageteaser_plain',true);
		}
	}



	
	this.BlendField = function () {
		
		var div = $(divid);
			
		if (div) {
			// only run if divid was found on page	
					
			var myFx = new Fx.Tween(divid, {property: 'opacity', duration:2000});
			
			for (i=1; i<100; i++) {
				
				myFx.start(1,1).chain(
				
				/* Notice that "this" refers to the calling object (in this case, the myFx object). */
				
				function(){ this.start(1,0); },
				function(){ 
					div.innerHTML = arr_blendingfields[0];
					this.start(0,1); 
				},
				function(){ this.start(1,1); },  // still stay 100% for one period
				function(){ this.start(1,1); },  // still stay 100% for one period
				function(){ this.start(1,0); },
				function(){ 
					div.innerHTML = arr_blendingfields[1];
					this.start(0,1); 
				},
				function(){ this.start(1,1); },  // still stay 100% for one period
				function(){ this.start(1,1); },  // still stay 100% for one period
				function(){ this.start(1,0); },
				function(){ 
					div.innerHTML = arr_blendingfields[2];
					this.start(0,1); 
				},
				function(){ this.start(1,1); },  // still stay 100% for one period
				function(){ this.start(1,1); },  // still stay 100% for one period
				function(){ this.start(1,0); },
				function(){ 
					div.innerHTML = arr_blendingfields[3];
					this.start(0,1); 
				},
				
				function(){ this.start(1,1); },  // still stay 100% for one period
				function(){ this.start(1,1); },  // still stay 100% for one period
				function(){ this.start(1,0); },
				function(){ 
					div.innerHTML = arr_blendingfields[4];
					this.start(0,1); 
				},
				
				function(){ this.start(1,1); },  // still stay 100% for one period
				function(){ this.start(1,1); },  // still stay 100% for one period
				function(){ this.start(1,0); },
				function(){ 
					div.innerHTML = arr_blendingfields[5];
					this.start(0,1); 
				},
				function(){ this.start(1,1); },  // still stay 100% for one period
				function(){ this.start(1,1); }  // still stay 100% for one period
			);	
				
			}
		}				
	}
	
	
	
	this.getHTML = function (fp, startblending) {
		
		page.request.send({
			url:"xhr/getbodyfield.php",
			params:"fp=" + fp,
			onFailure:function( error ){}, 	
			onSuccess:function( text, xml )	{
				
				arr_blendingfields.push(text);
				
				if (startblending) {
					
					// div ID with transition inside
					page.BlendField();
				} 
			}
		});
	}
	
	
	
	
	// --------------------------------------------------
	
	
	
	
	this.SetBFMouseActions = function(el) {		
							
		// find link
		var url = '';
		ellink = $('a:' + el.get('id'));
		
		if (ellink == null) {
			return;
		} else {
			url = ellink.get('href');	
		}
				
		el.setStyle('cursor', 'pointer');		
		
		el.addEvent('mouseover', function(e) {
			e.stop();
			el.setStyle('border', '1px solid #99a');
			el.setStyle('opacity', '0.9');
			//alert('over');
		});
		
		el.addEvent('mouseout', function(e) {
			e.stop();
			el.setStyle('border', '1px solid #ccd');
			el.setStyle('opacity', '1');
			//alert('out');
		});
		
		el.addEvent('click', function(e) {
			e.stop();
			
			if (url.length > 0) {
				window.location.href = url;	
			}
			
		});
	}
	
	
	
	
	this.changeAjaxContent = function(direction) {
				
		page.request.send({
			url:"xhr/returndate.php",
			params:"testparam=" + "X300TEST",
			onFailure:function( error ){},
			onSuccess:function( text, xml )	{
				$('ajaxcontent').innerHTML = text;
			}
		});
	}
	


		
	this.changeTxt = function (id,txt) {
		$(id).innerHTML = txt;
	}
	
	
	
	//------------------------------------------------------------------------------
	this.__construct();
	//------------------------------------------------------------------------------
}

