var Site = {
	
	start: function(){

                if ($('leftnav')) {
                
                addReflections();
                //moopop.captureByRel('popup');
                        
                        var defaultWidth = 158;
                        var defaultMargin = 37;
                        var leftnav = $('leftnav');
                        var rightnav = $('rightnav');
                        var slider = $('slider');
                        var sliderinner = $('sliderinner');
                        var images = $$('.imgWrapper');
                        var oimagew = (defaultWidth+defaultMargin); // width of 1 image + margin
                        var timagesw = oimagew*3; //width of 3 images
                        var imagepopup = $$('.imgWrapper a');
                        sliderinner.setStyle('width', images.length*oimagew + '0px');
                        //alert(sliderinner.getStyle('width'));
                        var maxscroll = slider.getScrollSize();
                        var scrollleft = 0;
                        var currimage = 0;
                        
                        var imageWidth = new Array();
                        var imageHeight = new Array();
                        images.each(function(item,index) {
                                imageWidth.extend([images[index].getWidth()]);
                                imageHeight.extend([images[index].getHeight()]);
                        });
                        //alert(imageWidth[0]);
                        //images[0].setStyle('margin-left',defaultMargin/2); // used to center the images
                        images.setStyle('width',defaultWidth+'px');
                        images.setStyle('margin-right',defaultMargin+'px');
                        
                        //alert (oimagew*8);
                        //alert (sliderinner.getStyle('width'));
                        //alert (slider.getStyle('width'));
                        
                        var slideeffect = new Fx.Scroll(slider, {duration: 'long', transition: Fx.Transitions.Sine.easeOut});
                        //var imagewidtheffect = new Fx.Tween(images, {duration: 300, transition: Fx.Transitions.Sine.easeOut});

                        rightnav.addEvent('click', function(e) {
                                sliderf.scrolls(true); //forward
                        });
                        leftnav.addEvent('click', function(e) {
                                sliderf.scrolls(false); //backward
                        });
                        var sliderf = {
                                scrolls: function(fb){
                                        if ((currimage<(images.length-2)) || (currimage>1)) {
                                                scrollleft = slider.getScroll();
                                                //newleft = scrollleft.x + fb*timagesw;
                                                if (fb) {
                                                
                                                        if (currimage<(images.length-2)) currimage = currimage+3;
                                                } else {
                                                        if (currimage>1) currimage = currimage-3;
                                                }
                                                
                                                newleft = images[currimage].getLeft()-slider.getLeft(); //centering the images -(defaultWidth/2)
                                                //alert (newleft);
                                                //alert (oimagew*currimage);
                                                slideeffect.start(newleft, 0);
                                        }
                                }
                        }
                        
                        images.each(function(item,index) {
                                item.addEvent('mouseenter', function(e) {
                                        item.tween('width',imageWidth[index]);
                                        if ((index+1)/3==1) {
                                                images[0].tween('width',30);
                                        }
                                });
                        });
                        images.addEvent('mouseout', function(e,thisimage) {
                                this.tween('width',defaultWidth);
                                //alert(images[0].getStyle('width'));
                                if (images[0].getStyle('width').toInt()<defaultWidth) {
                                        images[0].tween('width',defaultWidth);
                                }
                        });
                        imagepopup.addEvent('click', function(e,index){
                                new Event(e).stop();
                                window.open(this.href, '', 'width=' + 600 + ', height=' + 400);
                        });
                        var toplis = $$('#mainlevel li a');
                        toplis[3].setProperty('id', 'active_menu');
                }	
	
		if ($('sidebar')) Site.parseSidebars();
		if ($('player')) Site.parsePlayer();
		if ($('contactbutton')) {
			$('contactbutton').addEvent('mouseenter', function(e){
			     //this.setStyle('height','38px');
			     this.setStyle('background-image','url(/templates/djchen/images/input_bg_hover.jpg)');
			     this.setStyle('background-position','0% 0px');
			     this.setStyle('background-repeat','repeat-x');
			     
			});
			$('contactbutton').addEvent('mouseleave', function(e){
			     this.setStyle('background-image','url(/templates/djchen/images/input_bg.jpg)');
			});
		}
	


                window.fireEvent('resize');

                //if (Browser.Engine.trident4) {
                var toplis = $$('#mainlevel li');
                 //{background:url(../images/topmenu_hoverbg.jpg) repeat-x top left; }
                //var lifx = new Fx.Elements(toplis, {wait: false, duration: 100, transition: Fx.Transitions.quadOut});
                toplis.each(function(topli, i){
			topli.addEvent('mouseenter', function(e){
			     //this.setStyle('height','38px');
			     this.setStyle('background-image','url(/templates/djchen/images/topmenu_hoverbg.jpg)');
			     this.setStyle('background-position','0% 0px');
			     this.setStyle('background-repeat','repeat-x');
			     
			});
			topli.addEvent('mouseleave', function(e){
			     this.setStyle('background-image','none');
			});
		});
                
                
                //}
	},
	parsePlayer: function() {	
        	var clicker = $$('a');
        	clicker.addEvent('click',function(e) {
                e = new Event(e);
                //e.stop();

                	if(window.mp3player) window.document["mp3player"].SetVariable("movePagevar", "true")
                	if(document.mp3player) document.mp3player.SetVariable("movePagevar", "true")
                
        	});
	},
	parseSidebars: function(){
		//var glow = $('glow');
		//var sidebar1 = $('sidebar');
		//bottomgrey.setStyle('top',footer+'px');
		//glow.setStyle ('top',sidebar1.getTop()-40);
		//glow.setStyle ('left',sidebar1.getLeft()-80);
		var sidebars = $$('#sidebar .sidebar');
		var sidebars2 = $$('#sidebar2 .sidebar');
		var fx = new Fx.Elements(sidebars, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		var fx2 = new Fx.Elements(sidebars2, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		sidebars.each(function(sidebar, i){
			sidebar.addEvent('mouseenter', function(e){
				var obj = {};
				var obj2 = {};
				obj[i] = {
					'width': [sidebar.getStyle('width').toInt(), 149]
				};
				obj2[i] = {
					'width': [sidebars2[i].getStyle('width').toInt(), 149]
				};
				sidebars.each(function(other, j){
					if (other != sidebar){
						var w = other.getStyle('width').toInt();
						if (w != 36) obj[j] = {'width': [w, 36]};
						var w2 = sidebars2[j].getStyle('width').toInt();
						if (w2 != 36) obj2[j] = {'width': [w2, 36]};
					}
				});
				fx.start(obj);
				fx2.start(obj2);
			});
		});
		
		$('sidebar').addEvent('mouseleave', function(e){
			var obj = {};
			var obj2 = {};
			sidebars.each(function(other, j){
				obj[j] = {'width': [other.getStyle('width').toInt(), 73]};
				obj2[j] = {'width': [sidebars2[j].getStyle('width').toInt(), 73]};
			});
			fx.start(obj);
			fx2.start(obj2);
		});
	}
	}
	window.addEvent('resize', function(){
	var bottomgrey = $('ubottomgrey');
		var outer = $('outer');
	
	
		if (Browser.Engine.trident5 || Browser.Engine.trident4) {bottomgrey.setStyle ('height',30);}
		//alert(window.getHeight().toInt()-outer.getStyle('height').toInt());
		if (window.getHeight().toInt()>outer.getStyle('height').toInt()) {
		      var greyheight = window.getHeight().toInt()-outer.getStyle('height').toInt();
		      
		      bottomgrey.setStyle ('height',greyheight+34);
                      //alert(greyheight);
                }
                /*
        	var bottomgrey = $('ubottomgrey');
		var outer = $('outer');
		if (window.getHeight().toInt()>outer.getStyle('height').toInt()) {
		      var greyheight = window.getHeight().toInt()-outer.getStyle('height').toInt();
                      bottomgrey.setStyle ('height',greyheight+'px');
                }*/
        });
