//IE Pseudo HTML Tag Bug
jQuery.appInit.IEBug = function(){
	if(jQuery.browser.msie){
		var tags = new Array('ok','error','fatalerror');
		jQuery.each(tags,function(k , tag){
			if(jQuery(tag)){
				jQuery(tag).each(function(k,v){
					var Styles = jQuery().getStyleSheet(tag);
					Styles = Styles.replace(/\.\.\//g, "/design/");
					jQuery(this).after('<div style="'+Styles+'"></div>');
					jQuery(this).remove();
				});
			}
		});
	}
}
jQuery.appInit.Search = function(){
	jQuery("input").each(function(){
		if(jQuery(this).attr("autocomplete") == "on"){
			function formatItem(row) {
				return "<b>"+row[0]+":</b> "+row[1];
			}
			function formatResult(row) {
				return row[1];
			}
			jQuery(this).autocomplete("/ajax/getContent.php?file=search", {
				width: 260,
			 	selectFirst: false,
			 	scroll: true,
				submitForm: false,
				scrollHeight: 300,
				formatItem: formatItem,
				formatResult: formatResult
			});
		}
	});
}
//Zoom Main Page
function initWorld(){
	var RUN = false;
	var EVENT;
	var BIG_WIDTH = 1024;
	var BIG_HEIGHT = 585;
	var SHOW_WIDTH = 500;
	var SHOW_HEIGHT = 296;
	var DEF_WIDTH = 222;
	var DEF_HEIGHT = 131;
			
	function getPosition(){
		e = EVENT;
				
		var pos = jQuery('#worldBox').offset();
		//Mouseposition on World
		var left = (e.clientX - pos.left) ; 
		var top = (e.clientY - pos.top);
					
		//Centerpoint on big World
		var bleft = BIG_WIDTH / 2 ;
		var btop = BIG_HEIGHT / 2;		
		
		//  f(x) = 					m					 * x	  +		b				  - Differenz
		var pleft = ( ( ( BIG_WIDTH * -1 ) / DEF_WIDTH ) * left ) + ( BIG_WIDTH - bleft ) -35;
		var ptop = ( ( ( BIG_HEIGHT * -1 ) / DEF_HEIGHT ) * top ) + ( BIG_HEIGHT - btop ) -10;
		
		pleft -= DEF_WIDTH;
		ptop -= DEF_HEIGHT;
		
		return {
			left: parseInt(pleft),
			top: parseInt(ptop)};
	}
		
	jQuery('#bigWorldBox').css({
		width:DEF_WIDTH,
		height:DEF_HEIGHT
	});
	jQuery('#defworld').css({
		opacity: 1,
		display: 'block',
		width: DEF_WIDTH,
		height: DEF_HEIGHT
	});
	jQuery('#bigWorld').css({
		display: 'none',
		width: SHOW_WIDTH,
		height: SHOW_HEIGHT,
		overflow: 'hidden',
		float: 'right',
		backgroundImage: 'url(design/img/images/fadenkreuz.gif)',
		backgroundPosition: '240px 131px',
		backgroundRepeat: 'no-repeat',
		position:'relative'
	});
	jQuery('#world').css({
		display: 'block',
		opacity: 0.5,
		width: DEF_WIDTH,
		height: DEF_HEIGHT,
		position: 'relative'
	});
	jQuery('#worldBox').css({
		width:DEF_WIDTH,
		height:DEF_HEIGHT,
		overflow:'hidden',
		margin:'0 auto',
		position:'relative',
		zIndex:1,
		cursor: 'crosshair',
		float:'left'
	}).mousemove(function(e){
		EVENT = e;
		if(RUN == true){
			pos = getPosition();
			jQuery('#world').css({
				top: pos.top,
				left: pos.left
			});
		}
	}).hover(function(e){
		jQuery('#bigWorld').css({
			display: "block"
		});
		jQuery('#world').animate({
			width: BIG_WIDTH,
			height: BIG_HEIGHT
		},'slow',function(e){
			pos = getPosition();
			jQuery('#world').animate({
				top: pos.top,
				left: pos.left
			},'slow',function(){
				RUN = true;
			});
		});
		
	},function(){
		RUN = false;
		jQuery('#world').animate({
			width: DEF_WIDTH,
			height: DEF_HEIGHT,
			left: 0,
			top: 0
		},'slow', function(){
			jQuery('#bigWorld').css({
				display: "none"
			});
		});
	});
}
