Effect.Size = Class.create();
Object.extend(Object.extend(Effect.Size.prototype, Effect.Base.prototype), {
  initialize: function(element, w, h) {
    this.element = $(element);
    if(!this.element) throw(Effect._elementDoesNotExistError);
    var options = Object.extend({
      widthTo: w,
      heightTo: h
    }, arguments[3] || {});
    this.start(options);
  },
  setup: function() {
    this.element.makePositioned();
    this.originalWidth = parseFloat(this.element.getStyle('width') || '0');
    this.originalHeight  = parseFloat(this.element.getStyle('height')  || '0');
    this.options.dx = this.options.widthTo - this.originalWidth;
    this.options.dy = this.options.heightTo - this.originalHeight;
  },
  update: function(position) {
  	if (this.options.dx > 0)
	    this.element.setStyle({
	      width: Math.round(this.options.dx  * position + this.originalWidth) + 'px'
	    });
  	if (this.options.dy > 0)
	    this.element.setStyle({
	      height:Math.round(this.options.dy  * position + this.originalHeight)  + 'px'
	    });
  }
});

	function createLogo(name,maxSlice)
	{
	     var html="";

	     for (var i = 1; i <=maxSlice;i++)
	     {
	         html += "<img id='i"+ i + "' src='gfx/ls/" +name + "-" + i +".jpg' />";
	     }
	     $("logo").update(html);
	     html="";

	     for (var i = 1; i <=maxSlice;i++)
	     {
	         html += "<img id='iw"+ i + "' src='gfx/ls/" +name + "w-" + i +".jpg' />";
	     }
	     $("logow").update(html);
	}

     function createGallery(name,count,caption)
     {
     	var html= "";
         html += "<p><span class='h1'>";
         html += caption;
         html += "</span></p><p>";

         for (var i = 1; i <= count;i++)
         {
         	html += "<a href='gfx/gallery/" + name + "/pic" + i + ".jpg' rel='lightbox["+ name + "]' title=' '>";
             html += "<img class='inlineimg' src='gfx/gallery/" + name + "/thumb/pic" + i + ".jpg' border='0'></img></a>";
         }
         html += "</p>";

         $("gallery").update(html);

     }



     function disappearElem(evt)
     {
	     var child = Event.element(evt)     ;
          if (child)
			$(child).setStyle({visibility:'hidden'});
     }

     function appearElem(evt)
     {
	     var child = Event.element(evt)    ;
          if (child)
			$(child).setStyle({visibility:'visible'});
     }

     function refreshLinks()
     {
		Event.unloadCache();
         Element.getElementsByClassName($("content"),"link").each(function(item){
          	Event.observe(item,'click', showContent);
         });
     }

     var imgOffset = 0;
     var imgPos = [7,112,217,322,427,532,637,742];

     function refreshPics()
     {

     	imgOffset = rand(90);

         for(var i = 0; i <8;i++)
         	if (i <7)
	             new Effect.Move('img'+(i+1),{y:0,x:430,mode:'absolute',duration:0.3});
             else
	             new Effect.Move('img'+(i+1),{y:0,x:430,mode:'absolute',duration:0.3,afterFinish:reloadPics});

     }

     function reloadPics()
     {
	     Element.getElementsByClassName($("imgbar"),"barimage").each(function(item){
          	imgOffset++;
             var html = "<a href='gfx/pool/big/img"+imgOffset+".jpg' rel='lightbox[imgbar]' title=' '><img border='0' src='gfx/pool/thumb/img"+imgOffset+".jpg'></img></a>";
          	$(item).update(html);
         });

		myLightbox.updateImageList();


         for(var i = 0; i <8;i++)
             new Effect.Move('img'+(i+1),{y:0,x:imgPos[i],mode:'absolute',duration:0.3});

     }

     function getContent(id)
     {
     	var mEntry = menuIds[id];

         if (mEntry)
     	{

         	document.title = "..:: " + mEntry.cpt +  " ::.." ;
	          new Ajax.Request('content/'+mEntry.pg+'?d='+rand(32768), {
	            method: 'get',
	            onSuccess: function(transport) {
	             $('page').update(  transport.responseText);
                  refreshPics();
                  refreshLinks();
	            }
	          });
         }

     }

     function requestContact()
     {

       $('contactResult').update("Nachricht wird übermittelt...");
          new Ajax.Request('evalcontact.php', {
            method: 'POST',
            parameters: $('kontakt').serialize(),
            onSuccess: function(transport) {
             $('contactResult').update(transport.responseText);
            },
            onFailure: function(transport) {
                $('contactResult').update("Fehler bei der Übertragung, bitte versuchen Sie es zu einem späteren Zeitpunkt.");

            }
          });

     }



     function showContent(evt)
     {
	     var child = Event.element(evt)     ;
          if (child)
	          getContent(child.id);
     }


     function rand(max)
     {
     	return Math.floor(Math.random()*max);
     }

/* video related stuff */

function playVideo(fileName,vWidth,vHeight,containerId, contentId)
{
    var params = {
        scale: "noscale",
        allowfullscreen: "true",
        salign: "tl",
        bgcolor: "#000000",
        flashvars: "playerpath=./flash&"+
	          "contentpath=./video&"+
	          "video=" + fileName + "&"+
	          "skincolor=0x404040&"+
	          "skin=skin-applestyle.swf&"+
	          "skinscalemaximum=5&"+
	          "autoscale=true&"+
	          "autoplay=false&"+
	          "videowidth=" + vWidth+"&"+
	          "videoheight=" + vHeight};

    var attributes = {
	    data:"./flash/flvplayer.swf",
	   id: "player",
        align: "left",
        width: vWidth - 2,
        height:vHeight + 25};

      doCreateSWF(attributes, params,"video","player");
}

function doCreateSWF(attributes, params,containerId,contentId)
{


	var c = document.getElementById(contentId);
  	if (c)
		swfobject.removeSWF(contentId);
	c = document.getElementById(contentId);
  	if (!c) {
	     var d = document.createElement("div");
	     d.setAttribute("id", contentId);
	     document.getElementById(containerId).appendChild(d);
  	}
	swfobject.createSWF(attributes,params,contentId);
}
