window.addEvent('domready', function (event) {
	
	//Cufon
	Cufon.replace('.main-menu-li', {fontFamily: 'Gotham Medium', hover: true});
	Cufon.replace('.sub-menu-li', {fontFamily: 'Gotham Medium', hover: true});
	Cufon.replace('.gotham-medium', {fontFamily: 'Gotham Medium', hover: true});
	Cufon.replace('.gotham-bold', {fontFamily: 'Gotham Bold', hover: true});
	
	//Menus
    var activeMenu = null;

    $$('.main-menu-li-parent').each(function(el) {
				
		if (!activeMenu && el.hasClass('subactive')) {
			activeMenu = el;
		}
		
        el.addEvent('click', function (e) {
            if (e) {
                e.stop();
				
				if (activeMenu) {
					activeMenu.fireEvent('click', null);
				}
            }

            activeMenu = el;

            var subMenu = $('subMenu'+ this.rel)
            var menuSlide = new Fx.Slide(subMenu);
            var currentDisplay = subMenu.getStyle('display');

            if (Browser.Engine.trident) {
                if (currentDisplay == 'none') {
                    subMenu.setStyle('display', 'block');
                }
                else {
                    subMenu.setStyle('display', 'none');
                }
            }
            else {
                if (currentDisplay == 'none') {
                    subMenu.setStyle('display', 'block');

                    menuSlide.hide();
                }

                menuSlide.toggle();
            }
        });
    });
	
	/** Director template **/
	
	var filmStrip = $('filmsStrip');
	var thumbnails = $$('.director-film');
	var i = 0;
	var thumbnailsPos = 0;
	var maxPos = (thumbnails.length - 3) * 202;
	
	if (Cookie.read('rareFilmClicks')) {
		thumbnailsPos = parseInt(Cookie.read('rareFilmClicks'));
	}
	
	if ($('linkNavRight')) {
		$('linkNavRight').addEvent('click', function(e){
			e.stop();
			
			thumbnailsPos += 202;
			
			if (thumbnailsPos > maxPos) {
				thumbnailsPos = maxPos;
				
				return null;
			}
			
			Cookie.write('rareFilmClicks', thumbnailsPos, {duration: 7});
			
			thumbnails.each(function(el){
				el.leftPos -= 202;
				
				el.set('tween', {
					duration: 1000
				}).tween('left', el.leftPos + 'px');
			});
		});
	}
	
	if ($('linkNavLeft')) {
		$('linkNavLeft').addEvent('click', function(e){
			e.stop();
			
			thumbnailsPos -= 202;
			
			if (thumbnailsPos < 0) {
				thumbnailsPos = 0;
				
				return null;
			}

			Cookie.write('rareFilmClicks', thumbnailsPos, {duration: 7});
			
			thumbnails.each(function(el){
				el.leftPos += 202;
								
				el.set('tween', {
					duration: 1000
				}).tween('left', el.leftPos + 'px');
			});
		});
	}
	
	thumbnails.each(function(el){
		var image = el.getElement('img');
		
		el.setStyles({
		    left: i * 202 +'px',
			margin: 0,
		    position: 'absolute',
		    top: 0
		});
		
		//el.leftPos = el.getCoordinates(filmStrip).left;
		el.leftPos = i * 202;
		
		//Place thumbnails as previous time
		if (Cookie.read('rareFilmClicks')) {
			el.leftPos -= Cookie.read('rareFilmClicks');

			el.set('tween', {
				duration: 1
			}).tween('left', el.leftPos + 'px');
		}
		
		i++;
				
		el.addEvents({
			/*'click': function (e) {
				e.stop();
				
				var linkInfo = el.rel;
				
				linkInfo = linkInfo.split(';');	
				
				swfobject.removeSWF('flashContent');
				
				$('flashContentWrapper').adopt(new Element('div', {id: 'flashContent'}));
				
				var flashVars = {videoPath: linkInfo[1], autoPlay: true};
                var params = {allowFullScreen: true, allowScriptAccess: 'always'};
                var attributes = {id: 'flashContent'};
				
                //swfobject.embedSWF(window.path +'flash/flvPlayer/rarePlayer.swf', 'flashContent', '604', '340', '9', 'images/expressinstall.swf', flashVars, params, attributes);
                var fn = function () {
					swfobject.createSWF(
						{data: window.path +'flash/flvPlayer/rarePlayer.swf', width: '604', height: '340'},
						{flashvars: 'videoPath='+ linkInfo[1] +'&autoPlay=true'},
						'flashContent'
					);
				}

				swfobject.addDomLoadEvent(fn);
				
				var req = new Request({url: '../../resources/getContent.php', method: 'post',
					onSuccess: function(text) {
						$('filmInfo').set('html', text);
						Cufon.refresh();
					}
				});		
				
				req.send('path=./&template=director&pageID=1&langID=1&method=getFilmInfo&params='+ linkInfo[0]);
			},*/
		    'mouseenter': function(){
				if (image) {
					//image.morph({'opacity': 0});
					image.fade(0);
				}
		    },
			'mouseleave': function(e){
				if (image) {
					//image.morph({'opacity': 1});
					image.fade(1);
				}
		    }
		});
	});
	
	//FLash slideshow/flvplayer
	/*if ($('flashContentWrapper') && $('flashContent')) {
        $('flashContentWrapper').addEvent('mouseleave', function() {
			if ($('flashContent').hideControls) {
            	$('flashContent').hideControls();
			}
        });

        $('flashContentWrapper').addEvent('mouseover', function() {
			if ($('flashContent').showControls) {
            	$('flashContent').showControls();
			}
        });
    }*/
});
