var so;
var init = false
var mmap;
var rules = {
   '#irot' : function(el) { 
   		var url =  $w(el.className)[0];
   		so = new SWFObject('fileadmin/libs/imagerotator.swf','mpl','620','460','9');
  		so.addParam('allowfullscreen','false');
  		so.addParam('flashvars','file='+ url +'&rotatetime=8&width=620&height=460&transition=random&shownavigation=false&autostart=true');
     },
     '#bgi' : function(el) {
			Effect.Appear($('bg'),{duration:2,from:0.2,afterFinish:function() {
				if (!init) var page = $('page');new Effect.MoveBy(page, 0, 750,{duration:1,afterFinish:function(){
					init=true;
					setTimeout(function(){so.write($('irot'));},2000);}});
					Element.setOpacity(page,0.88);
					new Draggable(page);page.style.cursor = 'move';}});    		
     },
     '#meta' : function(el) {
     	el.onclick = function() {
			Element.show('map');
			var pos = $('map').getStyle('left');
	  	    if (!mmap) gInit();
	   		var x = (pos.substr(0,pos.length-2) > 0) ? -130 : 130;
     		new Effect.Appear($('map'),0,x);
     	}
     },
     '#map' : function(el) {
//     	Element.hide(el);
     }
 };

Event.observe(window, 'load', init_app);
Event.observe(window, 'resize',function() {window.reload;});


function init_app(event) { 
  Behaviour.register(rules);
  Behaviour.apply(rules);
  smartBG('fileadmin/img/bg.jpg');
  Behaviour.apply(rules);
}


function gInit() {
 	     mmap = new google.maps.Map2($("mapdiv"));
	   alert('');
	   mmap.setCenter(new google.maps.LatLng( 53.582463, 10.015842),16);
	   mmap.enableContinuousZoom();
	   mmap.enableDoubleClickZoom();
	   var bottomleft = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(8,8));
	   mmap.addControl(new GSmallZoomControl(),bottomleft);
	   mmap.setMapType(G_HYBRID_MAP);
 	   var marker = createMarker(new GLatLng( 53.582463, 10.015842),'','<span style="color:#333">THAYSEN FASHION<br/>Gertigstrasse 37<br />Telefon: 040 279 89 79</span>');
	   mmap.addOverlay(marker); 	   
 }
 
 
function createMarker(point,name,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
}

 
function smartBG(img) {
  var objBody = document.getElementsByTagName("body").item(0);
  var h= window.innerHeight || self.innerHeight || document.body.clientHeight;
  h = $('page').getHeight();

  
  var div1 = document.createElement('div');
  div1.setAttribute('id','bg');
  div1.style.width='100%';
  div1.style.height= h + 'px';
  div1.style.overflow='hidden';
  div1.style.zIndex='-1';
  
  div1.style.display='none';
  objBody.appendChild(div1);

  var div2 = document.createElement("div");
  div2.style.height='200%';
  div2.style.left = '-50%';
  div2.style.position='absolute';
  div2.style.top='-50%';
  div2.style.width='200%';
  div1.appendChild(div2);

  var tab = document.createElement("table");
  tab.setAttribute('id','bg');
  tab.setAttribute('cellpadding','0'); 
  tab.setAttribute('cellspacing','0'); 
  var row = tab.insertRow(0);
  var cell = row.insertCell(0);
  cell.innerHTML='<img style="margin:0 auto;min-height:50%;min-width:50%;display:block" height="100%" id="bgi" src="'+img+'" />';  
  div2.appendChild(tab);
}
