// 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' : '240px'
                        	});

                    	    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/images/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'		: '5px solid #fff'
											});
		
							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('headFlash').style.visibility = 'hidden';
							document.getElementById('widgets1').style.visibility = 'hidden';
							document.getElementById('widgets2').style.visibility = 'hidden';
							document.getElementById('widgets3').style.visibility = 'hidden';
							document.getElementById('widgets4').style.visibility = 'hidden';
							document.getElementById('widgets5').style.visibility = 'hidden';
							document.getElementById('widgets6').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('headFlash').style.visibility = 'visible';
							document.getElementById('widgets1').style.visibility = 'visible';
							document.getElementById('widgets2').style.visibility = 'visible';
							document.getElementById('widgets3').style.visibility = 'visible';
							document.getElementById('widgets4').style.visibility = 'visible';
							document.getElementById('widgets5').style.visibility = 'visible';
							document.getElementById('widgets6').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;
							    }
							
							    function getWindowHeight() {
									var windowHeight = 0;
									if (typeof(window.innerHeight) == 'number') {
										windowHeight = window.innerHeight;
									}
									else {
										if (document.documentElement && document.documentElement.clientHeight) {
											windowHeight = document.documentElement.clientHeight;
										}
										else {
											if (document.body && document.body.clientHeight) {
												windowHeight = document.body.clientHeight;
											}
										}
									}
									return windowHeight;
								}
								
								function getScrollY() {
									scrOfY = 0;
									if( typeof( window.pageYOffset ) == 'number' ) {
										//Netscape compliant
										scrOfY = window.pageYOffset;
									} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
										//DOM compliant
										scrOfY = document.body.scrollTop;
									} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
										//IE6 standards compliant mode
										scrOfY = document.documentElement.scrollTop;
									}
									return scrOfY;
								}
							
							    Lib.Dom.Elm.Style.add(this.contentviewer, {
									'visibility'		: 'visible',
									'width'			: width+'px',
									'height'		: height+'px',
									'left' 			: (this.dim.xfull/2)-(width/2) + 'px',
									'top' 			: (getWindowHeight() / 2) - (height / 2) + getScrollY() + '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/images/lightbox/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'
							});
						}
	}
});

MadeByPi.AtlasTracking = Base.extend({
	constructor : function ()
	{
		this.trackHome = false;
		this.trackTag = 'http://switch.atdmt.com/action/';
		
		callWhenDOMLoaded(Lib.delegate(this, this.initiate));
	},
	home : function ()
	{
		this.trackHome = true;
	},
	initiate : function (trackHome)
	{
		if (this.trackHome)
		{
			this.track('mdgfid_FirstDirectLiveLanding_10');
		}
		
		var switchbankinglink = document.getElementById('switchbankinglink');
		if (switchbankinglink != null)
		{
			switchbankinglink.onclick = Lib.delegate(this, this.track, 'mdgfid_FirstDirectLiveSwitchyourbankingatfirst_10');
		}
		
		var telluswhatyourethinking = document.getElementById('telluswhatyourethinking');
		if (telluswhatyourethinking != null)
		{
			telluswhatyourethinking.onclick = Lib.delegate(this, this.track, 'mdgfid_FirstDirectLiveTelluswhatyourethinking_10');
		}
	},
	track : function (mouseEvent, url)
	{
		if (url == null)
		{
			url = mouseEvent;
		}
	
		var tag = this.trackTag + url;
		var action_tag = document.getElementById('action_tag');
		if (action_tag != null)
		{
			action_tag.src = tag;
		}
	}
});

var atlas_tracking = new MadeByPi.AtlasTracking();
function GetActionTag(URL) { atlas_tracking.track(URL); }

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();
        }
    }
}))();

function doLightbox(type) {
	function getMovie(movieName) { return parent.document.getElementById(movieName); }
	var flash;
	
	try{
		flash = getMovie('widget_content_W4a97a5f757d19750');
		flash.onLightboxOpen();
	}catch(err){ }
	
	try{
		flash = getMovie('widget_content_W4a97a7ecf9c073f4');
		flash.onLightboxOpen();
	}catch(err){ }
	
	try{
		flash = getMovie('widget_content_W4a979bcfbe2720c7');
		flash.onLightboxOpen();
	}catch(err){ }
	
	try{
		flash = getMovie('widget_content_W4b290df9d7d49f91');
		flash.onLightboxOpen();
	}catch(err){ }
	
	try{
		flash = getMovie('banner');
		flash.onLightboxOpen();
	}catch(err){ }
	
	if(type == "positivenegative") {
		lightbox.open('/lightbox/feel.html', 791, 591);
	} else if(type == "wordle") {
		lightbox.open('/lightbox/wordle.html', 791, 591);
	} else if(type == "impression"){
		lightbox.open('/lightbox/impression.html', 791, 591);
	}
}

function closeLightBox(widgetId) {
	parent.lightbox.close();
	
	function getMovie(movieName) { return parent.document.getElementById(movieName); }
	
	try{
		flash = getMovie('widget_content_W4a97a5f757d19750');
		flash.onLightboxClosed();
	}catch(err){ }
	
	try{
		flash = getMovie('widget_content_W4a97a7ecf9c073f4');
		flash.onLightboxClosed();
	}catch(err){ }
	
	try{
		flash = getMovie('widget_content_W4a979bcfbe2720c7');
		flash.onLightboxClosed();
	}catch(err){ }
	
	try{
		flash = getMovie('widget_content_W4b290df9d7d49f91');
		flash.onLightboxClosed();
	}catch(err){ }
	
	try{
		flash = getMovie('banner');
		flash.onLightboxClosed();
	}catch(err){ }
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
		aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}

function isfd(){ return true; }



/// Browser Detection code used in the FF/PC - Scroll / Click to activate bug. FDL-7
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


//scroll flicker for PC firefox - FDL-7
function flicker(){
	document.getElementById("widget-row-1").style.backgroundColor =
"transparent";

}

var d = new Date();
var scrollStart = 0;
var waitForScroll = false;

function isFirefoxOnPC() {
	// this bug only occurs in firefox in the PC
	return (BrowserDetect.browser == "Firefox" && BrowserDetect.OS == "Windows");
}
window.onscroll = function(){
	if (isFirefoxOnPC()){
		d = new Date();
		scrollStart = d.getTime();
		waitForScroll = true;
	}
}

function scrollLoop(){
	d = new Date();
	if(waitForScroll && scrollStart < (d.getTime() - 250)){
		waitForScroll = false;
		document.getElementById("widget-row-1").style.backgroundColor = "#E6E6E6";
		setTimeout(flicker, 10);
	}else{

	}
	setTimeout(scrollLoop, 50);

}

if (isFirefoxOnPC())
{
	scrollLoop();
}