



var Base = Class.create();
Base.prototype = {

	// ******************************************************************************
	// Constants
	// ******************************************************************************
	Version: '1.0',


	// ******************************************************************************
	// vars
	// ******************************************************************************

	pageTracker: {}, // GA Pagetracker object

	// DOM Elemente
	// werden beim Initialisieren gemapt. siehe {options : selectors}
	elm : {},

	baseURL : '',

	options : {

		// selectors
		selectorPrefix : '',
		selectors : {
			stageA : '#stageA',
			stageB : '#stageB',

			logoA : '#logoA',
			brunchA : '#brunchA',
			brunchB : '#brunchB',
			brunchC : '#brunchC',
			circlesLeft : '#circlesLeft',
			circlesRight : '#circlesRight',

			button : '#stageA .button',

			popup : '.popup',


			dummy : 'weil ich immer vergesse das komma in der letzten zeile zu entfernen'
		},

		resPath : 'typo3conf/ext/strabag_ppsearch/pi1/res/',
   		imagePath : 'pix/',

	    mapZoom : null,

		dummy : 'weil ich immer vergesse das komma in der letzten zeile zu entfernen'
	},


	// ******************************************************************************
	// Constructor
	// ******************************************************************************
	initialize: function()
	{
		if((typeof Prototype=='undefined') || (typeof Element == 'undefined') || (typeof Element.Methods=='undefined') || parseFloat(Prototype.Version.split(".")[0] + "." + Prototype.Version.split(".")[1]) < 1.6)
			throw("dieses Script benötigt das Prototype JavaScript framework >= 1.6.0");


		document.observe('dom:loaded', this.pageLoadHandler.bindAsEventListener(this), false);
		Event.observe(window, 'load', this.onLoadHandler.bind(this), false);

	},

	pageLoadHandler: function() {

	    try {
		this.pageTracker = _gat._getTracker("UA-7517276-2");
		this.pageTracker._trackPageview();
	    } catch(err) {}


	    //this.baseURL = $$('base').first().href,
	    //this.imagePath = this.baseURL + this.options.resPath + this.options.imagePath;

	    // map all selectors to objects in this.elm
   		$H(this.options.selectors).each(function(pair){
   				this.elm[pair.key] = $$(this.options.selectorPrefix + pair.value).first();
   			}.bind(this));


   		this.elm.button.observe('click', this.buttonClickHandler.bindAsEventListener(this), false);
   		//this.elm.logoA.observe('click', this.test.bindAsEventListener(this), false);

		this.elm.popup.observe('click', this.popup.bindAsEventListener(this), false);

	},


	onLoadHandler: function()
	{
   		this.elm.stageA.morph('top: 0px;', {
   			duration: 2.0
   		});
   	},


   	buttonClickHandler : function(ev){
   		ev.stop();

		if(is.ie) {
			var rotationElm = this.elm.brunchB;
		} else {
			var rotationElm = this.elm.brunchA;
		}

   		this.elm.stageA.morph('top: -540px;', {
   			duration: 2.0,
   			queue : 'end'
   		});


   		this.elm.stageB.morph('top: 0px;', {
   			duration: 2.0,
   			queue : 'end'
   		});


   		new Effect.Parallel([
            new Effect.Morph(this.elm.circlesLeft, {
            	style: 'left: -93px; top: 419px',
            	sync: true,
            	mode: 'relative'
            }),
            new Effect.Morph(this.elm.circlesRight, {
            	style: 'right: -90px; top: 427px',
            	sync: true,
            	mode: 'relative'
            }),
            new Effect.Morph(this.elm.logoA, {
            	style: 'width: 266px; height: 180px; left: -58px; top: -12px;',
            	sync: true,
            	mode: 'relative'
				    }),
            new Effect.Rotate(rotationElm, 15, {
            	duration: 1,
            	sync: true,
            	beforeSetup: function(e){

            		if(is.ie) {
            			this.elm.brunchA.hide();
            			this.elm.brunchB.show();
            		}
            	}.bind(this),
            	afterFinish: function(e){

            		if(is.ie) {
            			this.elm.brunchB.hide();
            			this.elm.brunchC.show();
            		}

		    $('ar').show();

			var vars = {};
			var params = {wmode: 'transparent', base: 'swf', scale:'noScale', menu: 'false'};
			var attributes = {id:'main', name:'main', bgcolor:'0x000000'};
			swfobject.embedSWF('swf/cat.swf', 'ar', '100%', '100%', '10.0.0', 'swf/expressInstall.swf', vars, params, attributes);

			this.pageTracker._trackPageview('/showAr');


            	}.bind(this)
            })
   	      ], {
   	        duration: 1.5,
   	        queue : 'end'
   	      });

   	},




	closeLinkClick : function(ev){
	  ev.stop();
	  window.close();
	},


	popup : function(ev){
	  ev.stop();
	  elm = ev.findElement('a');
	    var res = elm.rel.split(':');




	    popup = new Popup({
				   url:elm.href,
				  name:'sosiehtsaus',
				   width:res[0],
				   height:res[1],
				   status:'no',
				  scrollbars:'no',
				  location:'no',
				  resizable:'no',
				  menubar:'no',
				   center:true,
				   focus:true
			       });
	    popup.open();

	},

	anchorLinkClick : function(ev){
	  ev.stop();
	  elm = ev.findElement('a');
	  hash = elm.href.split('#')[1];
	  scrollElm = $$('a[name='+ hash  +']').first();

	  new Effect.ScrollTo(scrollElm);

	},

	// ***********************************************************************************************
	// Dummy end func
	// ***********************************************************************************************
	dummy: function(){
	}
};

Popup = Class.create({
  Popup: null,

  options: {
    url:        null,
    width:      600,
    height:     500,
    name:       '_blank',
    location:   'no',
    menubar:    'no',
    toolbar:    'no',
    status:     'yes',
    scrollbars: 'yes',
    resizable:  'yes',
    left:       null,
    top:        null,
    normal:     false,
    center:     false,
    focus:      false
  },

  initialize: function(options, element)
  {
    Object.extend(this.options, options || {});

    if (this.options.normal) {
      this.options.menubar  = 'yes';
      this.options.status   = 'yes';
      this.options.toolbar  = 'yes';
      this.options.location = 'yes';
    }

    if (Object.isElement(element) && this.options.url == null &&
        element.readAttribute('href') != null) {
      this.options.url = element.readAttribute('href');
    }

    this.options.width  = this.options.width < screen.availWidth ? this.options.width : screen.availWidth;
    this.options.height = this.options.height < screen.availHeight?  this.options.height : screen.availHeight;
  },

  open: function()
  {
    var openoptions = 'width=' + this.options.width
      + ', height=' + this.options.height
      + ', location=' + this.options.location
      + ', menubar=' + this.options.menubar
      + ', toolbar=' + this.options.toolbar
      + ', scrollbars=' + this.options.scrollbars
      + ', resizable=' + this.options.resizable
      + ', status=' + this.options.status

    if (this.options.center) {

	var border = 16;
	if(Prototype.Browser.WebKit) border = 0;



      this.options.left = (screen.availWidth - (parseInt(this.options.width) + border)) / 2;
      this.options.top  = (screen.availHeight - this.options.height) / 2;

    }
    if (this.options.top != null) {
      openoptions+= ',top=' + this.options.top;
    }
    if (this.options.left != null) {
      openoptions+= ',left=' + this.options.left;
    }

    if (Object.isUndefined(window[this.options.name]) || window[this.options.name].closed) {
      window[this.options.name] = this.popup = window.open(this.options.url, this.options.name, openoptions);
    } else {
      window[this.options.name].location.href = this.options.url;
    }


    this.popup = window[this.options.name];


    if (this.popup) {
      if (this.options.focus) {
        this.focus();
      }

      return true;
    } else {
      return false;
    }
  },

  close: function() {
    if (thispopup != null) {
      this.popup.close();
      window[this.options.name] = null;
    }
  },

  focus: function() {
    if (this.popup != null) {
      this.popup.focus();
    }
  }
});



myBase = new Base();


var deg2radians = Math.PI * 2 / 360;


Effect.Rotate = function(element, deltaDeg, options) {
  element = $(element);



  if(is.ie){

	  element.show();

	  var el = element;

	  width  = el.getWidth();
	  height = el.getHeight();

	  top2   = el.positionedOffset()[1];
	  left   = el.positionedOffset()[0];


  }


  return new Effect.Tween(element, 0, deltaDeg, options,
    function(pos) {

	  if(is.ie){
	    rad = pos * deg2radians ;
	    costheta = Math.cos(rad);
	    sintheta = Math.sin(rad);
	    oObj = this;


	    oObj.filters.item(0).M11 = costheta;
	    oObj.filters.item(0).M12 = -sintheta;
	    oObj.filters.item(0).M21 = sintheta;
	    oObj.filters.item(0).M22 = costheta;

	    oObj.style.pixelTop=top2-(oObj.offsetHeight-height)/2;
	    oObj.style.pixelLeft=left-(oObj.offsetWidth-width)/2;

	  } else {

		  if(typeof this.getStyle('-webkit-transform') != 'undefined') {
			  this.setStyle("-webkit-transform: rotate(" + pos + "deg);");
		  } else if (typeof this.getStyle('-moz-transform') != 'undefined') {
			  this.setStyle("-moz-transform: rotate(" + pos + "deg);");
		  } else if (typeof this.getStyle('transform') != 'undefined') {
			  this.setStyle("transform: rotate(" + pos + "deg);");
		  } else {

			  var newTop = top2 - parseInt(100 / deltaDeg * pos);
			  this.setStyle("top: " + newTop + "px");
		  }

	  }


    }
  );
};



