// version 0.2
var MadeByPi = {};
MadeByPi.SmoothImageLoader = Base.extend({
    constructor :   function (baseimage){
                        this.baseimage = baseimage;
                        callWhenDOMLoaded(Lib.delegate(this, this.init));
    },
    init :          function (){
                        this.preloads = [];
                        this.images = [];
                        var imageholders = Lib.Dom.getElementsByClassName(document, 'div', 'imageholder');
                        for (var i=0; i<imageholders.length; i++){
                          this.images.push(Lib.Dom.Elm.first(imageholders[i], 'img'));
                        }
                        for (var i=0; i<this.images.length; i++){
                          this.images[i].oldsrc = this.images[i].src;
                          this.images[i].src = this.baseimage;
                          var preload = new Image(240,55);
                          Lib.Dom.Elm.Style.add(this.images[i], {
                            'visibility' : 'hidden'
                          });
                          Lib.Dom.Elm.Style.addClass(this.images[i].parentNode, "loading");
                          Lib.Dom.addEvent(preload, "load", Lib.delegate(this, this.imageLoaded, this.images[i]));
                          preload.src = this.images[i].oldsrc;
                          this.preloads.push(preload);
                        }
    },
    imageLoaded :   function (e,img){
                      Lib.Dom.Elm.Style.add(img, {
                            'visibility' : 'visible'
                          });
                      Lib.Dom.Elm.Style.removeClass(img.parentNode, "loading");
                      img.src = img.oldsrc;
    }
});
MadeByPi.Forms = Base.extend({
    constructor :   function (){
                  callWhenDOMLoaded(Lib.delegate(this, this.init));
    },
    init :          function (){
                  this.forms = document.getElementsByTagName('form');
                  for (var i=0; i<this.forms.length; i++){
                    var a = new MadeByPi.Form(this.forms[i].id);
                  }
    }
});
MadeByPi.Form = Base.extend({
    constructor :   function (formid){
                    this.formid = formid;
                    callWhenDOMLoaded(Lib.delegate(this, this.init));
    },
    init :          function (){
                    this.inputelms = [];
                    this.form = $(this.formid);
                    this.parseInputElements();
                    this.parseTextareaElements();
                    this.submitbtn = Lib.Dom.getElementsByClassName(this.form, 'input', 'submit_button')[0];
                    Lib.Dom.addEvent(this.submitbtn, "mouseover", Lib.delegate(this, this.rollover));
                    Lib.Dom.addEvent(this.submitbtn, "mouseout", Lib.delegate(this, this.rollout));
                    Lib.Dom.addEvent(this.form, "submit", Lib.delegate(this, this.clear));

    },
    rollover :  function (){
                    Lib.Dom.Elm.Style.addClass(this.submitbtn, "Hover");
    },
    rollout : function (){
                    Lib.Dom.Elm.Style.removeClass(this.submitbtn, "Hover");
    },
    parseInputElements : function (){
                     var inputelements = this.form.getElementsByTagName("input");
                     for (var i=0; i<inputelements.length; i++){
                        if (inputelements[i].type.toLowerCase() == "text"){
                            if (inputelements[i].value == "") inputelements[i].value = inputelements[i].title;
                            
                            Lib.Dom.addEvent(inputelements[i], "focus", Lib.delegate(this, this.focused, inputelements[i]));
                            Lib.Dom.addEvent(inputelements[i], "blur", Lib.delegate(this, this.blured, inputelements[i]));
                            this.inputelms.push(inputelements[i]);
                        }
                     }
    },
    parseTextareaElements : function (){
                     var textareaelements = this.form.getElementsByTagName("textarea");
                     for (var i=0; i<textareaelements.length; i++){
                        if (textareaelements[i].value == "") textareaelements[i].value = textareaelements[i].title;
                        Lib.Dom.addEvent(textareaelements[i], "keydown", Lib.delegate(this, this.grow, textareaelements[i]));
                        Lib.Dom.addEvent(textareaelements[i], "focus", Lib.delegate(this, this.focused, textareaelements[i]));
                        Lib.Dom.addEvent(textareaelements[i], "blur", Lib.delegate(this, this.blured, textareaelements[i]));
                        this.inputelms.push(textareaelements[i]);
                     }
    },
    grow : function (e, elm){
                
                if (elm.scrollHeight > (150-22)){
                    Lib.Dom.Elm.Style.add(elm, {
                        'overflow' : 'hidden',
                        height : elm.scrollHeight + 'px'
                    });
                }

    },
    focused :   function (e, elm){
                    if (elm.value == elm.title){
                        elm.value = "";
                    }
    },
    blured :   function (e, elm){
                    if (elm.value == ""){
                        elm.value = elm.title;
                    }
    },
    clear :     function (e, elm){
                    for (var i=0; i<this.inputelms.length; i++){
                        if (this.inputelms[i].value == this.inputelms[i].title){
                            this.inputelms[i].value = "";
                        }
                    }
    }
});
MadeByPi.ShadowTastic = Base.extend({
    constructor : function (divid, shadowpath){
                  this.shadowpath = shadowpath; //../common/img/workshadow.png
                  this.containerdivid = divid;
                  callWhenDOMLoaded(Lib.delegate(this, this.init));
    },
    init :        function (){
                this.shadows = Lib.Dom.getElementsByClassName($(this.containerdivid), 'div', 'shadow');
                for (var i=0; i<this.shadows.length; i++){
                  if(Lib.Browser.get().isIE){
                    Lib.Dom.Elm.Style.add(this.shadows[i], {
                        'filter' : 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+this.shadowpath+'\', sizingMethod=\'crop\')'
                    });
                  }else {
                    Lib.Dom.Elm.Style.add(this.shadows[i], {
                        'backgroundImage' : 'url('+this.shadowpath+')'
                    });
                  }
                }
    }
});
MadeByPi.PlottedMap = Base.extend({
                constructor :   function (elmid,pathtopin,pathtoshadow, location){
                        this.elmid = elmid;
                        this.pathtopin = pathtopin;
                        this.pathtoshadow = pathtoshadow;
                        this.location = location;
                        if (GBrowserIsCompatible()) {
                         callWhenDOMLoaded(Lib.delegate(this, this.init));
                        }
                },
                init :  function (){
                        this.mapelm = $(this.elmid);
                        this.map = new GMap2(this.mapelm);
                        
                        this.piOffice = new GLatLng(53.84461513829119,-1.5129053592681884);
                        if (this.location != ""){
                         this.locationparts = this.location.split(",");
                         this.piOffice = new GLatLng(this.locationparts[0], this.locationparts[1]);
                        }
                        this.map.setCenter(this.piOffice, 10);
                        
                        this.control = new GSmallMapControl();
                        this.map.addControl(this.control);
                        
                        this.baseIcon = new GIcon();
                        this.baseIcon.image = this.pathtopin;//"../common/img/pin.png";
                        this.baseIcon.iconSize = new GSize(50, 48);
                        this.baseIcon.shadow = this.pathtoshadow;//"../common/img/pin_shadow.png";
                        this.baseIcon.shadowSize = new GSize(65, 50);
                        this.baseIcon.iconAnchor = new GPoint(7, 48);
                        this.baseIcon.infoWindowAnchor = new GPoint(9, 2);
                        this.baseIcon.infoShadowAnchor = new GPoint(18, 25);
                        
                        this.map.addOverlay(this.createMarker(this.piOffice));
                },
                createMarker : function (point){
                          var markerOptions = { icon:this.baseIcon };
                          var marker = new GMarker(point, markerOptions);
                          return marker;
                        
                }
});

MadeByPi.ParagraphCollapser = Base.extend({
    constructor :   function (baseid){
                        this.baseelementid = baseid;
                        callWhenDOMLoaded(Lib.delegate(this, this.init));
    },
    init :          function (){
                        this.baseelement = $(this.baseelementid);
                        this.paras = Lib.Dom.getElementsByClassName(this.baseelement, "div", "cont");
                        Lib.Dom.Elm.Style.addClass(this.paras[this.paras.length-1].parentNode.parentNode.parentNode, 'bottom');
                        for (var i=0; i<this.paras.length; i++){
                        	Lib.Dom.Elm.Style.add(this.paras[i].parentNode, {
                        		'height' : '260px'
                        	});
                        	
                    	    var totalheight = 20;
                            var h4 = Lib.Dom.Elm.first(this.paras[i].parentNode, "h4");
                            totalheight += this.getElmHeight(h4);


                            var ul = Lib.Dom.Elm.first(this.paras[i].parentNode, "ul");
                            totalheight += this.getElmHeight(ul);
                            var setHeight = '7em';
                            if (Lib.Browser.get().isIE){
	                            setHeight = '12.8em';
	                            if (totalheight > 120){
	                                setHeight = '10.9em';
	                            }
	                            if (totalheight > 140){
	                                setHeight = '9em';
	                            }
                            }else {
	                            if (totalheight > 150){
	                                setHeight = '7em';
	                            }else if (totalheight > 130){
	                                setHeight = '9em';
                        	    }else if (totalheight > 110){
                        	        setHeight = '11em';
                        	    }else if (totalheight > 90){
                        	        setHeight = '13em';
                        	    }
                        	}
                        	
                    	    Lib.Dom.Elm.Style.add(this.paras[i], {
                    		    'overflow' : 'hidden',
                    		    'height'   : setHeight
                    	    });

                        	var scrollHeight = this.getScrollHeight(this.paras[i]);
                        	var elmHeight = this.getElmHeight(this.paras[i]);
                        	if ((scrollHeight - elmHeight) > 35){
                        		this.addMoreButton(this.paras[i]);
                        	}else {
                         	    Lib.Dom.Elm.Style.add(this.paras[i], {
                        		    'height' : 'auto'
                        	    });  
                        	    Lib.Dom.Elm.Style.add(this.paras[i].parentNode, {
                        		    'height' : 'auto'
                        	    });  
                        	}
                        }
    },
    addMoreButton : function (elm){
    			var morelink = Lib.Dom.Elm.create("div");
    			morelink.className = "readmorelink";
    			var readmoretag = Lib.Dom.Elm.create("a");
    			readmoretag.href = 'javascript:void(0);';
    			
                Lib.Dom.addEvent(readmoretag, "click", Lib.delegate(this, this.startExpandElement, readmoretag, elm));
    			readmoretag.appendChild(document.createTextNode("...more"));
    			morelink.appendChild(readmoretag);
    			elm.parentNode.insertBefore(morelink,elm.nextSibling);
    			return morelink;
    			
    },
    startExpandElement : function (e, link, cont){
                            Lib.Dom.Elm.Style.add(cont.parentNode, {
                                'height' : 'auto'
                            });
                            link.parentNode.removeChild(link);
                            this.expandElement(cont);
    },
    expandElement :     function (cont){
                            if (cont.clientHeight < cont.scrollHeight){
                                Lib.Dom.Elm.Style.add(cont, {
                                    'height' : (cont.clientHeight + ((cont.scrollHeight-cont.clientHeight)/3))+'px'
                                });
                                setTimeout(Lib.setTimeoutDelegate(this, this.expandElement, cont), 50);
                            }
    },
    getElmHeight : function (elm){
    	        return (elm.clientHeight>0?elm.clientHeight:elm.offsetHeight);
    },
    getScrollHeight: function (elm){
    	        return elm.scrollHeight;
    }

});


MadeByPi.Testimonials = Base.extend({
    constructor :   function (bubbleid){
                        this.bubbleid = bubbleid;
                        this.timeout = false;
                        callWhenDOMLoaded(Lib.delegate(this, this.init));
    },
    init :      function (){
                        this.bubble = $(this.bubbleid);
                        this.maininnerdiv = Lib.Dom.Elm.first(this.bubble, 'div');
                        this.bubbles = Lib.Dom.getElementsByClassName(document, 'blockquote', 'testimonial');
                        this.wrappers = [];
                        this.wrapperheights = [];
                        this.currentbubbleid = 0;
                        this.nextbubbleid = 1;
                        for (var i=0; i<this.bubbles.length; i++){
                          var wrapper = Lib.Dom.Elm.create("div", {
                            'padding': '0px',
                            'margin' : '0px',
                            'backgroundImage' : 'none',
                            'zoom' : 1,
                            'overflow' : 'hidden'
                          });
                          var innerdiv = Lib.Dom.Elm.first(this.bubbles[i], 'div');
                          var children = [];
                          for (var a=0; a<innerdiv.childNodes.length; a++){
                            children.push(innerdiv.childNodes[a]);
                          }
                          for (var a=0; a<children.length; a++){
                            innerdiv.removeChild(children[a]);
                            wrapper.appendChild(children[a]);
                          }
                          this.maininnerdiv.appendChild(wrapper);
                          this.wrappers.push ({'wrapper' : wrapper, 'height' : (wrapper.clientHeight>0?wrapper.clientHeight:wrapper.offsetHeight)});
                          if (this.bubbles[i].id != this.bubbleid){
                            Lib.Dom.Elm.Style.add(wrapper, {
                                'display' : 'none'
                            });
                            Lib.Dom.Elm.Style.add(this.bubbles[i], {
                                'display' : 'none'
                            });
                          }
                        }
                       //Lib.Dom.Elm.Opacity.changeOpac(20, this.wrappers[this.currentbubbleid].wrapper);
                       
                       
                        clearInterval(this.interval);
                        this.interval = setTimeout(Lib.setTimeoutDelegate(this, this.fadeOutElement), 10000);
    },
    fadeOutElement : function (){
    
                        if (this.wrappers[this.currentbubbleid].opacity == null){
                            this.wrappers[this.currentbubbleid].opacity = 100;
                        }
                        if (this.wrappers[this.currentbubbleid].opacity > 0){
                            this.wrappers[this.currentbubbleid].opacity = Math.floor(this.wrappers[this.currentbubbleid].opacity/1.5);
                            Lib.Dom.Elm.Opacity.changeOpac(this.wrappers[this.currentbubbleid].opacity, this.wrappers[this.currentbubbleid].wrapper);
                        }
                        if (this.wrappers[this.currentbubbleid].opacity > 0){
                            this.interval = setTimeout(Lib.setTimeoutDelegate(this, this.fadeOutElement), 20);
                        }else {
                           this.changeSize();
                        }
    },
    fadeInElement : function (){
                        if (this.wrappers[this.currentbubbleid].opacity == null){
                            this.wrappers[this.currentbubbleid].opacity = 1;
                        }
                        if (this.wrappers[this.currentbubbleid].opacity < 100){
                            this.wrappers[this.currentbubbleid].opacity = Math.ceil(this.wrappers[this.currentbubbleid].opacity*1.5);
                            Lib.Dom.Elm.Opacity.changeOpac(this.wrappers[this.currentbubbleid].opacity, this.wrappers[this.currentbubbleid].wrapper);
                        }
                        if (this.wrappers[this.currentbubbleid].opacity < 100){
                            clearInterval(this.interval);
                            this.interval = setTimeout(Lib.setTimeoutDelegate(this, this.fadeInElement), 20);
                        }else {
                            clearInterval(this.interval);
                            this.interval = setTimeout(Lib.setTimeoutDelegate(this, this.fadeOutElement), 10000);
                        }
    },
    changeSize :    function (){
                        
                        var currentWrapper = this.wrappers[this.currentbubbleid].wrapper;
                        var currentHeight = (currentWrapper.clientHeight>0?currentWrapper.clientHeight:currentWrapper.offsetHeight);
                        var nextWrapperID = this.nextbubbleid;
                        var targetHeight = this.wrappers[nextWrapperID].height;
                        var toHeight = currentHeight + ((targetHeight-currentHeight)/2);
                        if (Math.ceil(currentHeight) != Math.ceil(targetHeight) && Math.floor(currentHeight) != Math.floor(targetHeight)){
                            Lib.Dom.Elm.Style.add(currentWrapper, {
                                'height' : toHeight + 'px'
                            });
                            
                        }
                        if (Math.floor(toHeight) != Math.floor(targetHeight) && Math.ceil(toHeight) != Math.ceil(targetHeight)){
                            clearInterval(this.interval);     
                            this.interval = setTimeout(Lib.setTimeoutDelegate(this, this.changeSize), 50);
                        }else {
                           clearInterval(this.interval);     
                           Lib.Dom.Elm.Style.add(currentWrapper, {
                            'display' : 'none',
                            'height' : 'auto'
                           });
                           
                           this.wrappers[nextWrapperID].opacity = 1;
                           Lib.Dom.Elm.Opacity.changeOpac(this.wrappers[nextWrapperID].opacity,  this.wrappers[nextWrapperID].wrapper);
                           this.increaseBubbleId();
                           Lib.Dom.Elm.Style.add(this.wrappers[nextWrapperID].wrapper, {
                            'display' : 'block'
                           });
                           this.fadeInElement();
                        }
    },
    increaseBubbleId  : function (){
                            if (this.currentbubbleid >= (this.wrappers.length-1)){
                                this.currentbubbleid = 0;
                            }else {
                                this.currentbubbleid++;
                            }
                            if (this.nextbubbleid >= (this.wrappers.length-1)){
                                this.nextbubbleid = 0;
                            }else {
                                this.nextbubbleid++;
                            }
                            
    }
});
function replace(){

    if (document.getElementById('replace')){
            var replacement = document.getElementById('replace');
			var flashvars = {};
			var params = {};
			params.wmode = "transparent";
			var attributes = {};
			attributes.id = "replace";
			switch (replacement.className){
			    case "home":
			        width = 275;
			        height = 40;
			        url = mediaurl+"common/swf/title_home.swf";
			        break;
			    case "about":
			        width = 375;
			        height = 100;
			        url = mediaurl+"common/swf/title_about.swf";
			        break;
			    case "contact":
			        width = 425;
			        height = 70;
			        url = mediaurl+"common/swf/title_contact.swf";
			        break;
			    case "careers":
			        width = 410;
			        height = 70;
			        url = mediaurl+"common/swf/title_careers.swf"; 
			        break;
			    case "blog":
			        width = 400;
			        height = 40;
			        url = mediaurl+"common/swf/title_blog.swf"; 
			        break;
			    case "games":
			      	width = 590;
			        height = 70;
			        url = "common/swf/title_games.swf";
			        break;
			    case "download":
			      	width = 340;
			        height = 40;
			        url = mediaurl+"common/swf/title_download.swf";
			        break;
			}
			swfobject.embedSWF(url, "replace", width, height, "9.0.0", false, flashvars, params, attributes);
	}
}
callWhenDOMLoaded(Lib.delegate(this, this.replace));
MadeByPi.RelatedWorkLinkElement = Base.extend({
    constructor :   function (){
                        callWhenDOMLoaded(Lib.delegate(this, this.init));
                        
    },
    init :          function (){
                        this.workitems = Lib.Dom.getElementsByClassName($('content'), "div", "workitem");
                        for (var i=0; i<this.workitems.length; i++){
                          this.linkupWorkItem(this.workitems[i]);
                        }
    },
    linkupWorkItem :  function (elm){
                        var h4 = Lib.Dom.Elm.first(elm, "h4");
                        var links = h4.getElementsByTagName("a");
                        if (links.length > 0){
                          
                            var link = links[0];
                            var cont = h4.parentNode.getElementsByTagName("div")[0];
                            
                            var image = Lib.Dom.getElementsByClassName(h4.parentNode.parentNode.parentNode, "div", "imageholder")[0];
                           
                            var linkedElements = [link, cont, image];
                            this.styleAsLinks(linkedElements);
                           
                            Lib.Dom.addEvent(image, "click", Lib.delegate(this, this.go, link.href));
                            Lib.Dom.addEvent(cont, "click", Lib.delegate(this, this.go, link.href));
                            Lib.Dom.addEvent(h4, "click", Lib.delegate(this, this.go, link.href));
                            
                            Lib.Dom.addEvent(image, "mouseout", Lib.delegate(this, this.mouseout, linkedElements));
                            Lib.Dom.addEvent(cont, "mouseout", Lib.delegate(this, this.mouseout, linkedElements));
                            Lib.Dom.addEvent(h4, "mouseout", Lib.delegate(this, this.mouseout, linkedElements));
                            Lib.Dom.addEvent(image, "mouseover", Lib.delegate(this, this.mouseover, linkedElements));
                            Lib.Dom.addEvent(cont, "mouseover", Lib.delegate(this, this.mouseover, linkedElements));
                            Lib.Dom.addEvent(h4, "mouseover", Lib.delegate(this, this.mouseover, linkedElements));
                        }
    },
    styleAsLinks    : function (linkedElements){
                        for (var i=0; i<linkedElements.length; i++){
                           Lib.Dom.Elm.Style.add(linkedElements[i], {
                            'cursor' : 'pointer'
                           });
                        }
    },
    mouseover :        function (e,linkedElements){
                        for (var i=0; i<linkedElements.length; i++){
                            Lib.Dom.Elm.Style.addClass(linkedElements[i], "Hover");
                        }
    },
    mouseout :        function (e,linkedElements){
                        for (var i=0; i<linkedElements.length; i++){
                            Lib.Dom.Elm.Style.removeClass(linkedElements[i], "Hover");
                        }
    },
    go :        function (e,linkhref){
                        location.href = linkhref;
    }
});
MadeByPi.RelatedLinkElement = Base.extend({
    constructor :   function (){
                        callWhenDOMLoaded(Lib.delegate(this, this.init));
    },
    init :          function (){
                        this.links = document.getElementsByTagName("a");
                        for (var i=0; i<this.links.length; i++){
                            
                            if (this.links[i].rel != null && this.links[i].rel != ''){
                            
                                var relatedlink = this.links[i].rel;
                                if (relatedlink == 'on'){
                               
                                  var p = false;
                                  var img = false;
                                  
                                  var paras = this.links[i].parentNode.parentNode.getElementsByTagName("p");
                                  if (paras.length > 0){
                                    var p = paras[0];
                                    Lib.Dom.addEvent(p, "mouseover", Lib.delegate(this, this.mouseover, p, img,this.links[i]));
                                    Lib.Dom.addEvent(p, "mouseout", Lib.delegate(this, this.mouseout, p, img, this.links[i]));
                                    Lib.Dom.addEvent(p, "click", Lib.delegate(this, this.click, this.links[i]));
                                  }
                                  
                                  
                                  var images = this.links[i].parentNode.parentNode.parentNode.getElementsByTagName("img");
                                  if (images.length > 0){
                                    var img = images[0];
                                    Lib.Dom.addEvent(img, "mouseover", Lib.delegate(this, this.mouseover, p, img,this.links[i]));
                                    Lib.Dom.addEvent(img, "mouseout", Lib.delegate(this, this.mouseout, p, img, this.links[i]));
                                    Lib.Dom.addEvent(img, "click", Lib.delegate(this, this.click, this.links[i]));     
                                  }
                                                               
                                  Lib.Dom.addEvent(this.links[i], "mouseover", Lib.delegate(this, this.mouseover, p, img, this.links[i]));
                                  Lib.Dom.addEvent(this.links[i], "mouseout", Lib.delegate(this, this.mouseout, p, img, this.links[i]));
                                }
                            }
                        }
    },
    mouseover :     function (e, p, img, elm){
                    if (p) Lib.Dom.Elm.Style.addClass(p, "Hover");
                    if (img) Lib.Dom.Elm.Style.addClass(img, "Hover");
                    Lib.Dom.Elm.Style.addClass(elm, "Hover");
    },
    mouseout :  function (e, p, img, elm){
                    if (p) Lib.Dom.Elm.Style.removeClass(p, "Hover");
                    if (img) Lib.Dom.Elm.Style.removeClass(img, "Hover");
                    Lib.Dom.Elm.Style.removeClass(elm, "Hover");
    },
    click : function (e, elm){
                    location.href = elm.href;
    }

});

MadeByPi.Lightbox = Base.extend({
	constructor : 			function (){
							this.pagex = 700;
							this.pagey = 400;
							this.padding = [0, 0, 0, 0];
							this.hasiframe = false;
							this.fullscreen = false;
							this.closeimg = 'close.png';
							this.loadingimg = mediaurl+'common/img/lightbox/loader.gif';
							this.loadingimgwidth = 16;
							this.loadingimgheight = 16;
							callWhenDOMLoaded(Lib.delegate(this, this.initiate));
							
	},
	initiate :          function (){
	                        this.create();
							if (!this.hasiframe){
								this.hasiframe = true;
								this.iframe = Lib.Dom.Elm.create("iframe", {'width': '100%', 'height':'100%', 'border' : '0px solid #000'});
								this.iframe.frameBorder = '0';
								this.iframe.scrolling = 'auto';
								this.iframe.border = '0';
								this.contentviewer.appendChild(this.iframe);
							}
	},
	updateDim : 			function (){
							this.dim = Lib.Browser.dim();
	},
	setSize : 			function (width, height){
							this.pagex = width;
							this.pagey = height;
	},
	create :			function (){
							this.fullscreen = Lib.Dom.Elm.create("div", {
											'display' : 'none'	
											});
							this.fullscreen.id = 'lightbox_fullscreen';
							this.contentviewer = Lib.Dom.Elm.create("div", {
											'visibility'		: 'hidden',
											'backgroundColor'	: '#FFFFFF',
											'position'		: 'absolute',
											'top'			: '-4000px',
											'left'			: '-4000px',
											'zIndex'		: '1000001',
											'border'		: '1px solid #6b6a65'
											});
		
							var preloadimg = new Image();
							preloadimg.src = this.loadingimg;
							this.updateDim();

							this.elmloadingimg = Lib.Dom.Elm.create("img", {
									'display'	: 'none',
									'top'		: '0px',
									'left'		: '0px',
									'width'		: this.loadingimgwidth + 'px',
									'height'	: this.loadingimgheight + 'px',
									'position'	: 'absolute',
									'zIndex'	: 1000001
										});
							this.elmloadingimg.src = this.loadingimg;
							document.body.appendChild(this.elmloadingimg);
									
									
							this.contentviewer.id = 'lightbox_content';
							this.createCloseButton();
							document.body.appendChild(this.contentviewer);
							document.body.appendChild(this.fullscreen);
	},
	open : 				function (link, width, height){
							this.updateDim();
							this.coverpage(link, width, height);
						
	},
	hide : 				function (){
							this.uncoverpage();
							this.hidePage();
							this.hideCloseButton();
	},
	close : 			function (){
							this.uncoverpage();
							this.hidePage();
							this.closePage();
							this.hideCloseButton();
	},
	coverpage : 			function (link, width, height){
							if (!this.fullscreen){
								this.create();
							}
							
							document.getElementById('gamesswf').style.visibility = 'hidden';
							Lib.Dom.Elm.Style.add(this.fullscreen, {
											'width'			: this.dim.xfull + 'px',
											'height'		: this.dim.yfull + 'px',
											'position'		: 'absolute',
											'top'			: '0px',
											'left'			: '0px',
											'display'		: 'block',
											'zIndex'		: '1000000',
											'backgroundColor' : '#000',
											'visibility' : 'hidden'
											});
							this.fullscreen._opacity = 0;
							this.interval = setInterval(Lib.setTimeoutDelegate(this, this.changeCoverOpacity, link, width, height), 105);
	},
	changeCoverOpacity : function (link, width, height){	
	                        if (this.fullscreen._opacity < 80){
	                            this.fullscreen._opacity += 20;
	                            Lib.Dom.Elm.Opacity.changeOpac(this.fullscreen._opacity, this.fullscreen);
	                            if (this.fullscreen._opacity <= 20){
							        Lib.Dom.Elm.Style.add(this.fullscreen, {
											'visibility' : 'visible'
									});
	                            }

	                        }else {
	                           clearInterval(this.interval);
	                           this.fullscreen._opacity = 80;
	                           Lib.Dom.Elm.Opacity.changeOpac(this.fullscreen._opacity, this.fullscreen);
	                           this.callIframePage(link, width, height);
	                        }
	},
	uncoverpage : 			function (){
	
							document.getElementById('gamesswf').style.visibility = 'visible';
						if (this.fullscreen){
							Lib.Dom.Elm.Style.add(this.fullscreen, {
											'width'			: '200px',
											'height'		: '200px',
											'display'		: 'none'
											});
						}
	},
	callIframePage : 		function (link, width, height){
							if (!this.hasiframe){
								this.hasiframe = true;
								this.iframe = Lib.Dom.Elm.create("iframe", {'width': width+'px', 'height':height+'px', 'border' : '0px solid #000'});
								this.iframe.frameBorder = '0';
								this.iframe.scrolling = 'auto';
								this.iframe.border = '0';
								this.contentviewer.appendChild(this.iframe);
							}
							this.iframe.src = link;
							this.iframeLoaded(width, height);
							//this.iframeLoaded();
	},
	iframeLoaded : 			function (width, height){
							this.updateDim();
							this.showPage(width, height);
							this.showCloseButton(width, height);	
	},
	showPage : 			function(width, height){
	 
							    if (!width || !height){
							      width = this.pagex;
							      height = this.pagey;
							    }
							
							    Lib.Dom.Elm.Style.add(this.contentviewer, {
									'visibility'		: 'visible',
									'width'			: width+'px',
									'height'		: height+'px',
									'left' 			: (this.dim.xfull/2)-(width/2) + 'px',
									'top' 			: (662/2)-(height/2) + 'px'
								});
							
								Lib.Dom.Elm.Opacity.changeOpac(100, this.contentviewer);
	},
	hidePage : 			function (){
						if (this.contentviewer){
							Lib.Dom.Elm.Style.add(this.contentviewer, {
										'visibility' 		: 'hidden',
										'width'			: '200px',
										'height'		: '200px',
										'left'			: '-4000px',
										'top'			: '-4000px'
							});
						}
	},
	closePage : 			function (){
						if (this.contentviewer){
						    var iframes = this.contentviewer.getElementsByTagName('iframe');
						    if (iframes.length > 0){
						 	  iframes[0].src = '';
							}
						}
	},
	createCloseButton : 		function (){
							this.closebutton = Lib.Dom.Elm.create("a", {
											'position'		: 'absolute',
											'display' 		: 'none',
											'width'			: '14px',
											'height'        : '14px',
											'border'        : '0px solid #fff',
											'zIndex'		: '1000002'
							});
							this.closebutton.href = 'javascript:void(0);';
							Lib.Dom.addEvent(this.closebutton, 'click', Lib.delegate(this, this.close));
							this.closebutton.innerHTML = "<img src=\""+mediaurl+"common/img/cross.gif\" />";
							this.closebutton.id = 'lightbox_close';
							document.body.appendChild(this.closebutton);
							
	},
	showCloseButton : 		function (width, height){
							if (!this.closebutton){
							  this.createCloseButton();
							}
							if (!width || !height){
							  width = this.pagex;
							  height = this.pagey;
							}
							Lib.Dom.Elm.Style.add(this.closebutton, {
											'position'		: 'absolute',
											'display' 		: 'block',
											'zIndex'		: '1000002',
											'textAlign'		: 'right',
											'left' 			: (this.dim.xfull/2)+(width/2)-14 + 'px',
											'top' 			: (662/2)-(height/2)-20 + 'px'
							});
	},
	hideCloseButton : 		function (){
						if (this.closebutton){
							Lib.Dom.Elm.Style.add(this.closebutton, {
											'display'		: 'none',
											'left'			: '0px',
											'top'			: '0px'
							});
						}
	}
});
var Boing = Base.extend({
    constructor : function (){
        callWhenDOMLoaded(Lib.delegate(this, this.init));
    },
    getIsBoingable : function (){
        var referrer = document.referrer == null?"":document.referrer;        
        var match = /pilot.*interactive/.test(referrer);
        return match && (referrer.indexOf("cms.") == -1);
    },
    init : function (){
       if (this.getIsBoingable()){
         this.dim = Lib.Browser.dim();
         this.cover = Lib.Dom.Elm.create("div", {
            'width' : this.dim.xfull + 'px',
            'height' : this.dim.yfull + 'px',
            'position' : 'absolute',
            'bottom' : '0px',
            'right' : '0px',
            'backgroundColor' : '#000'
         });
         this.cover.id = 'boing-cover';
         Lib.Dom.Elm.Opacity.changeOpac(0, this.cover);
         document.body.appendChild(this.cover);
         Lib.Dom.Elm.Opacity.opacity('boing-cover', 0, 80, 500);
         
         this.boinger = Lib.Dom.Elm.create("div", {
            'width' : '460px',
            'height' : '80px',
            'position' : 'absolute',
            'top' : ((this.dim.yview/2)-100)+'px',
            'left' : ((this.dim.xview/2)-230)+'px'
         });
         this.boinger.innerHTML = '<p>You have just discovered MadeByPi&reg; formerly known as Pilot Interactive</p>'+
                                  '<img class="bubble" src="'+mediaurl+'common/img/boing/boing.gif" alt="boing you have just discovered MadeByPi&reg;!" />'+
                                  '<div id="boinglink"><p><a href="javascript:void(0);" title="MadeByPi&reg;" id="boing-close">click here to read more about <strong>MadeByPi&reg;</strong></a></p>';
                                  
         this.boinger.id = 'boing';
         document.body.appendChild(this.boinger);
         document.body.style.cursor = 'pointer';
         this.removedlg = Lib.delegate(this, this.close);
         Lib.Dom.addEvent(document, "click", this.removedlg);
         
         
         Lib.Dom.Elm.Opacity.changeOpac(0, 'boing');
         Lib.Dom.Elm.Opacity.opacity('boing', 0, 100, 500);
         
         
       }
    },
    close : function (){
         document.body.style.cursor = 'auto';
         Lib.Dom.removeEvent(document, "click", this.removedlg);
         Lib.Dom.Elm.Opacity.opacity('boing-cover', null, 0, 500);
         Lib.Dom.Elm.Opacity.opacity('boing', null, 0, 500);
         setTimeout(Lib.delegate(this, this.remove), 500);
     },
     remove : function (){
        this.boinger.parentNode.removeChild(this.boinger);
        this.cover.parentNode.removeChild(this.cover);
     }
});
var boinger = new Boing();

var BlogExpander = new (Base.extend({
    constructor : function (){
        callWhenDOMLoaded(Lib.delegate(this, this.init));
    },
    init : function (){
        this.readMoreLink = document.createElement("a");
        this.readMoreLink.className = "readmorelink";
        this.readMoreLink.href = 'javascript:void(0);';
        this.readMoreLink.appendChild(document.createTextNode("more entries"));
        $('bloglist').parentNode.insertBefore(this.readMoreLink, $('bloglist').nextSibling);
        this.blogitems = $('bloglist').getElementsByTagName("li");
        this.fullheight = $('bloglist').clientHeight>0?$('bloglist').clientHeight:$('bloglist').offsetHeight;
        for (var i=0; i<this.blogitems.length; i++){
            if (i > 1){
                Lib.Dom.Elm.Style.add(this.blogitems[i], {
                    'display' : 'none'
                });
            }
        }
        this.cutheight = $('bloglist').clientHeight>0?$('bloglist').clientHeight:$('bloglist').offsetHeight;
        Lib.Dom.Elm.Style.add($('bloglist'), {
            'overflow' : 'hidden',
            'height'    : this.cutheight+ 'px'
        });
        for (var i=0; i<this.blogitems.length; i++){
            if (i > 1){
                Lib.Dom.Elm.Style.add(this.blogitems[i], {
                    'display' : 'block'
                });
            }
        }
        Lib.Dom.addEvent(this.readMoreLink, "click", Lib.delegate(this, this.startExpanding));
       
    },
    startExpanding : function(){
        Lib.Dom.Elm.Style.add(this.readMoreLink, {
            'display' : 'none'
        });
        this.onBlogReadMore();
    },
    onFinishExpanding : function (){
         Lib.Dom.Elm.Style.add($('bloglist'), {
            'paddingBottom' : '25px'
         });
    },
    onBlogReadMore : function (){
        var currentheight = $('bloglist').clientHeight>0?$('bloglist').clientHeight:$('bloglist').offsetHeight;
        Lib.Dom.Elm.Style.add($('bloglist'), {
            'height' : Math.ceil(currentheight+((this.fullheight-currentheight)/4)) + 'px'
        });
        var currentheight = $('bloglist').clientHeight>0?$('bloglist').clientHeight:$('bloglist').offsetHeight;
        if (currentheight < this.fullheight){
            setTimeout(Lib.setTimeoutDelegate(this, this.onBlogReadMore), 20);
        }else {
            this.onFinishExpanding();
        }
    }
}))();
