/*-------------------------------------------------------------------
 General stuff
-------------------------------------------------------------------*/

/* jQuery */

 
  $(document).ready(function () {
  		
  		
  	// ScrollPane content
  		$(function()
		{
		$('#middlecontent').jScrollPane({scrollbarMargin:5,showArrows:false, scrollbarWidth: 10, arrowSize: 16});
		
		});
		
		// Scrollpane-rem archiv / Concert-Selector
		var $concertselectorscroll = $('div#rem_concert_selector');
		var urlAnchor = $.getURLParam("k");
		$concertselectorscroll.jScrollHorizontalPane({scrollbarMargin:15,wheelSpeed:19,animateTo:true,showArrows:true, scrollbarHeight: 0, arrowSize: 20});
			if (urlAnchor!=null){					
				var targetElementSelectorString = urlAnchor;
				var scrollToContainer = 'a#selectorlnk_'+targetElementSelectorString;	
				var position = $(scrollToContainer).position().left;
				$concertselectorscroll[0].scrollTo(position-280,800, {axis:'x'});									 
			/*	
				$('a.selectorlnk').css("display","none");
				$('a.selectorlnk').fadeIn('slow', function() {
        // Animation complete
      });
*/
				
				//$concertselectorscroll[0].scrollTo(scrollToContainer,800, {axis:'x'},{offset: {top:-5, left:-30} });
				return false;
			}
			
      
  	   // Vibrate logos
  	   //  $('.leftcontent').rotate(-25);
  	
 		var interval = 30;
  		var duration= 100000;
  		var shake= 3;
		var vibrateIndex1 = 0;
		var vibrateIndex2 = 0;
  		var vibeSelector1 = $('img#pgnm_biglogo');
  		var mapSelector1 = $('map#pgnm-biglogo');
  		var vibeSelector2 = $('img#rem_biglogo');
  		var mapSelector2 = $('map#rem-biglogo');
	
	
		$(mapSelector1).mouseover(
		function(){	
		vibrateIndex1 = setInterval(vibrate1, interval);
		setTimeout(stopVibration1, duration);
		});
		
		$(mapSelector2).mouseover(
		function(){	
		vibrateIndex2 = setInterval(vibrate2, interval);
		setTimeout(stopVibration2, duration);
		});
		
		$(mapSelector2).mouseout(
		function(){	
		 clearInterval(vibrateIndex2);
		 $(vibeSelector2).stop(true,false)
		.css({position: 'static', left: '0px', top: '0px'});
		});
		
		$(mapSelector1).mouseout(
		function(){	
		 clearInterval(vibrateIndex1);
		 $(vibeSelector1).stop(true,false)
		.css({position: 'static', left: '0px', top: '0px'});
		});
		
		var vibrate1 = function(){
		$(vibeSelector1).stop(true,false)
		.css({position: 'relative', 
		left: Math.round(Math.random() * shake) - ((shake + 1) / 2) +'px', 
		top: Math.round(Math.random() * shake) - ((shake + 1) / 2) +'px'});
		}
		
		var vibrate2 = function(){
		$(vibeSelector2).stop(true,false)
		.css({position: 'relative', 
		left: Math.round(Math.random() * shake) - ((shake + 1) / 2) +'px', 
		top: Math.round(Math.random() * shake) - ((shake + 1) / 2) +'px'});
		}

		var stopVibration1 = function() {
		clearInterval(vibrateIndex1);
		$(vibeSelector1).stop(true,false)
		.css({position: 'static', left: '0px', top: '0px'});
		};
		
		var stopVibration2 = function() {
		clearInterval(vibrateIndex2);
		$(vibeSelector1).stop(true,false)
		.css({position: 'static', left: '0px', top: '0px'});
		};
  	
  	
  	 	
});

// Vibrate logos

$(function() {
  var interval = 30;
  var duration= 1000;
  var shake= 3;
  var vibrateIndex = 0;
  var selector = $('#frame');
	$('#activate').click(
	function(){	
	vibrateIndex = setInterval(vibrate, interval);
	setTimeout(stopVibration, duration);
	});

	var vibrate = function(){
	$(selector).stop(true,false)
	.css({position: 'relative', 
	left: Math.round(Math.random() * shake) - ((shake + 1) / 2) +'px', 
	top: Math.round(Math.random() * shake) - ((shake + 1) / 2) +'px'});
	}
	
	var stopVibration = function() {
	clearInterval(vibrateIndex);
	$(selector).stop(true,false)
		.css({position: 'static', left: '0px', top: '0px'});
	};

});



function sendForm(name){
	document.getElementById(name).submit();
	return false;						
}
function sendFormCtrl(name,faction){
	strLen = faction.length;
	if(strLen>1){
		document.getElementById(name).action = faction;
	}
	document.getElementById(name).submit();
	return false;						
}
function alarm(){
	alert('test');
}
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}
function decision(message, url){
if(confirm(message)) location.href = url;
}

function centerfix_div(name,element_width,element_height){
	var pSize=getPageSize();	 
		var thisWidth=element_width;
		var thisHeight=element_height;
		if((window.innerHeight)){
			innerH=window.innerHeight;
		} else if (document.body.clientHeight){ 
			innerH=document.body.clientHeight;
			}
		var pLeft=((pSize[0]-thisWidth)/2)+'px';
 		var pTop=((innerH-thisHeight)/2)+'px';
 	 document.getElementById(name).style.position = 'fixed'; 	 
 	 document.getElementById(name).style.left= pLeft;
 	 document.getElementById(name).style.top= pTop;
	 
}

function getPageSize(){
	if (window.innerHeight) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	// alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	
	return arrayPageSizeWithScroll;
}

function getPageSizeWithScroll(){
	if (window.innerHeight) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	//alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );
	return arrayPageSizeWithScroll;
}


function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}



function lock_mainpage(lock){

	if (lock==1){
		var pSize=getPageSize();
		document.getElementById('ajax_lock_mainpage').style.width= pSize.width+'px';
		document.getElementById('ajax_lock_mainpage').style.height= pSize.height+'px';	
		document.getElementById('ajax_lock_mainpage').style.display='block';
		
	} else {
		document.getElementById('ajax_lock_mainpage').style.display='none';
	}

}


function centerfix_div(name,element_width,element_height){
	 
	 // Div centern für Browser die position:fixed unterstützen
	 var windowSize=window.size();		 
 	 document.getElementById(name).style.position = 'fixed'; 	 
 	 document.getElementById(name).style.width= element_width+'px';
 	 document.getElementById(name).style.height= element_height+'px';
 	 document.getElementById(name).style.left= (windowSize.width-element_width)/2+'px';
 	 document.getElementById(name).style.top= (windowSize.height-element_height)/2+'px';	
 	 
 	 // Div centern für Browser die position:fixed NICHT unterstützen (IE6)
 	 if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
		 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number 				
 					if (ieversion==6){
 						// alert ('Du verwendest einen ver'); 
 					var center=window.center({width:element_width,height:element_height});	 
 					document.getElementById(name).style.position = 'absolute'; 
 					document.getElementById(name).style.width= element_width+'px';
 	 				document.getElementById(name).style.height= element_height+'px';
 	 				document.getElementById(name).style.left= center.x+'px';
 	 				document.getElementById(name).style.top= center.y+'px';	 			
 					}
				}
 	 
 	 
}

var isMSIE;
/*@cc_on
    isMSIE = true;
@*/

function getPageSize () {
    var d = document,
        db = d.body,
        de = d.documentElement,
        mode = d.compatMode;
        w = 0, h = 0;
    if (db && mode == "BackCompat" && isMSIE) {
        w = db.scrollWidth;
        h = db.scrollHeight;
    } else {
        w = Math.max(db && db.scrollWidth || 0,
                     de && de.scrollWidth || 0);
        h = Math.max(db && db.scrollHeight || 0,
                     de && de.scrollHeight || 0);
    }
    return {width: w, height: h};
}

window.size = function()
{
	var w = 0;
	var h = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
		
		
		
	}
	
	return {width:w,height:h};
}

window.center = function()
{
	var hWnd = (arguments[0] != null) ? arguments[0] : {width:0,height:0};

	var _x = 0;
	var _y = 0;
	var offsetX = 0;
	var offsetY = 0;

	//IE
	if(!window.pageYOffset)
	{
		//strict mode
		if(!(document.documentElement.scrollTop == 0))
		{
			offsetY = document.documentElement.scrollTop;
			offsetX = document.documentElement.scrollLeft;
		}
		//quirks mode
		else
		{
			offsetY = document.body.scrollTop;
			offsetX = document.body.scrollLeft;
		}
	}
	//w3c
	else
	{
		offsetX = window.pageXOffset;
		offsetY = window.pageYOffset;
	}

	_x = ((this.size().width-hWnd.width)/2)+offsetX;
	_y = ((this.size().height-hWnd.height)/2)+offsetY;


	return{x:_x,y:_y};
}