var HashRouter=function(b,c,d,a) { 
    this.availablePages = b || [];
    this.onHashChange = c || function(){};
    this.duration = d || 50;
    this.hashPrefix = a || "#!/";
    this.intervalID = false;
    this.currentHash = false;
    this.lastHash = false
};

HashRouter.prototype.start = function(){
    this.intervalID=setInterval(this.checkHashChanges.bind(this),this.duration);
    return this
};

HashRouter.prototype.stop = function(){
    clearInterval(this.intervalID);
    return this
};

HashRouter.prototype.checkHashChanges = function(){
    var a = document.location.hash.replace(this.hashPrefix,"");

    if(a === this.currentHash){
        return
    }
    
    if(!a || a == this.hashPrefix){
        document.location.hash = this.hashPrefix + this.availablePages[0];
        return
    }
    
    /*if(this.availablePages.indexOf(a)==-1){
        document.location.hash = this.hashPrefix + this.availablePages[this.availablePages.length-1];
        return
    }*/
    
    this.stop();
    this.lastHash = this.currentHash;
    this.currentHash = a;
    this.onHashChange() && this.start()
};

var loaderEl;
var baseUri = 'http://' + window.location.hostname + '/';
var hashRouter;

if(!document.location.hash){
    document.location.href = document.location.href.replace(new RegExp("^("+baseUri+")"),"$1#!/")
}

var pageToHide;
var pageToShow;
var pageToShowHeight;
var menuButtonSelected;
var languageRelatedItems;
var selectedLanguage;
var delayBasedOnInitOrTransition;
var floatUp;
var floatYearUp;
var elementToScrollSpy;
var scrollSpyElements;
var offsetForScrollSpy=200;
var delayBetweenScrollSpyed=100;
var elementToParallax;
var styleSwap1;
var styleSwap2;
var style;
var changeCss=true;

window.addEvent("domready",function(){
    new Fx.Scroll(window).set(0,0);
    
    if(!pageToHide){
        setWebsiteLoader()
    }
    
    loaderEl=new Element("div",{style:"display: none;"}).inject(document.body);
    
    $("homepage") && $("homepage").dispose().destroy();
    
    styleSwap1=new Element("style",{type:"text/css"}).inject($(document.head),"bottom");
    styleSwap2=new Element("style",{type:"text/css"}).inject($(document.head),"bottom");
    
});

window.addEvent("load",function(){
    
    new Fx.Scroll(window).set(0,0);
    hashRouter=new HashRouter(["titulni-stranka","biography","newspress","tv","cinematheatre","media","notFound404"],routingSection).start()
});

function fakeDomReady(){
    
    new Fx.Scroll(window).set(0,0);
    menuRelatedItems=$$("#menu a");
    menuRelatedItems&&menuButtons();
    
    if(!pageToHide){
        delayBasedOnInitOrTransition=6000;
        (function(){
            slideWebsiteIn()
        }).delay(5000)
    }else{
        delayBasedOnInitOrTransition=2000
    }
    
    startAnimation();
    unLogoRolloverFx();
    mainNavItemRollover();
    Cufon.replace('.cufon, .websiteLoaderText', {
        hover: true
    });
}

function routingSection(){
    pageToHide=hashRouter.lastHash;
    pageToShow=hashRouter.currentHash;
    menuButtonSelected=pageToShow;
    if(pageToHide){
        hideTheMenu();
        preventSillyUsers()
    } else{
        cssAndAssetsLoader()
    }
}

function hashRouterEnabling(){
    hashRouter.start()
}

function cssAndAssetsLoader(){
    new Request({
        url:"/templates/dreamsolutions_cz/css/"+pageToShow.replace(/\//g, '-')+".css",
        method:"get",
        onSuccess:function(c){
            changeCss ? style = styleSwap1:
            style = styleSwap2;
            changeCss=!changeCss;
            Browser.ie?(style.styleSheet.cssText=c):
            style.set("html",c);
            var d=[];
            var a=[];
            c.replace(/url\((.+)\)/g,function(){
                d.push(arguments[1].replace(/^('|")(.+)('|")$/,"$2"))
            });
            for(var b=0;b<d.length;b++){
                a.push(new Element("img",{
                    "data-loadsrc":d[b],
                    style:"position: absolute; top: 0; left: 0;"
                }).addEvent("load",e).inject(loaderEl))
            }
            
            for(var b=0;b<d.length;b++){
                a[b].store("next",a[b+1]||false)
            }
            a[0].set("src",a[0].get("data-loadsrc"));
            
            function e(f){
                (function(){
                    f.target.retrieve("next")&&f.target.retrieve("next").set("src",f.target.retrieve("next").get("data-loadsrc"));
                    if(!f.target.retrieve("next")){
                        injectTheNewSection()
                    }
                }).delay(50)
            }
        }
    }).send()
}

function menuButtons(){
    menuRelatedItems.each(function(c){
        var b=new Element("span",{
            text:c.get("text")
        });
        
        c.set("morph",{
            duration:1000,
            transition:Fx.Transitions.Elastic.easeOut
        });
        
        c.set("text","").grab(b,"bottom").grab(b.clone().set("class","over"),"bottom");
        c.getFirst().set("tween",{
            duration:300,
            transition:Fx.Transitions.Expo.easeInOut
        });
        
        c.addEvents({
            mouseenter:function(){
                if(this!=$(menuButtonSelected+"Butt")){
                    this.getElement("span").tween("margin-top",-15)
                }
            },
            mouseleave:function(){
                if(this!=$(menuButtonSelected+"Butt")){
                    this.getElement("span").tween("margin-top",0)
                }
            },
            click:a.bind(c)
        })
    });
    
    function a(b){
        if(menuButtonSelected==this.get("id").substr(0,this.get("id").length-4)){
            return
        }
        menuRelatedItems.getElement("span").tween("margin-top",0);
        this.getElement("span").tween("margin-top",-15)
    }
    
    if(menuButtonSelected!="homepage"){
        $$("#"+pageToShow.replace(/\//g, '-')+" #"+menuButtonSelected+"Butt").getElement("span").setStyle("margin-top",-15)
    }
    
}

function preventSillyUsers(){
    window.addEvent("mousewheel",preventSillyWheel)
}

function preventSillyWheel(a){
    a.stop()
}

function reenableSillyUsers(){
    window.removeEvent("mousewheel",preventSillyWheel)
}

function eyeCandyKilling(){
    if(Browser.ie8){
        return
    }
    
    destroyVerticalParallax();
    window.removeEvent("scroll",verticalParallax);
    floatUp=null;
    floatYearUp=null;
    floatCinemaUp=null;
    
    if($("growl")){
        $("growl").tween("opacity",0)
    }
}

function setVerticalParallax(a){
    if(Browser.Platform.name=="ios"||Browser.ie8){
        return
    }a.each(function(b){
        b.store("top",b.getStyle("top").toInt());
        b.store("y",b.getPosition().y);
        b.store("friction",parseFloat(b.get("data-friction")));
        b.set({"class":"active",style:"position: fixed;"})
    });
    
    window.addEvent("scroll",verticalParallax)
}

function verticalParallax(a){
    elementToParallax.each(function(b){
        b.setStyle("top",parseInt(b.retrieve("top")-window.getScroll().y*b.retrieve("friction")))
    })
}

function destroyVerticalParallax(){
    if(elementToParallax==null){
        return
    }
    elementToParallax.each(function(a){
        a.set({
            style:"position: absolute;"
        })
    })
}

function injectTheNewSection(){
    new Request.HTML({
        url:pageToShow,
        onComplete:function(c,a,d,b){
            if(!pageToHide){
                new Element("div",{
                    id:pageToShow.replace(/\//g, '-'),"class":"section"
                }).setStyles({
                    position:"absolute",
                    width:"100%","margin-left":"0"
                }).inject($(document.body)).set("html",d);
                
                fakeDomReady()
            } else {
                if(Browser.Platform.name=="ios"){
                    new Element("div",{
                        id:pageToShow.replace(/\//g, '-'),"class":"section"
                    }).inject($(pageToHide.replace(/\//g, '-')),"after").set("html",d)
                } else { 
                    new Element("div",{
                        id:pageToShow.replace(/\//g, '-'),"class":"section"
                    }).setStyles({
                        position:"absolute",
                        width:"100%","margin-left":$(pageToHide.replace(/\//g, '-')).getSize().x,overflow:"hidden"
                    }).inject($(pageToHide.replace(/\//g, '-')),"after").set("html",d)
                }
                sectionVisualSwap()
            }
        }
    }).get({'ajax': true});
    hashRouterEnabling()
}

function sectionVisualSwap(){
    var a=$$("#"+pageToShow.replace(/\//g, '-')+" #header-top");
    if(Browser.Platform.name!="ios"){
        $(pageToShow.replace(/\//g, '-')).set("tween",{
            duration:1200,transition:Fx.Transitions.Quint.easeInOut
        }).tween.delay(0,$(pageToShow.replace(/\//g, '-')),["margin-left","0"]);
        
        a.setStyles({
            top:-112
        }).set("tween",{
            duration:400,
            transition:Fx.Transitions.Quint.easeInOut
        }).tween.delay(1200,a,["top","-20"])
    } else {
        a.setStyles({top:-20})
    }
    
    if(Browser.Platform.name=="ios"){
        (function(){
            $$("#"+pageToHide.replace(/\//g, '-')+" > *").each(function(c,b){
                if(c.get("id")==undefined||c.get("id")=="loaderSpinner"){
                    return
                } else {
                    c.destroy()
                }
            });
            
            $$("#"+pageToHide.replace(/\//g, '-')+" > *").setStyles({
                webkitTransition:"opacity 0s linear",opacity:0.01
            });
            
            (function(){
                $(pageToHide.replace(/\//g, '-')).destroy()
            }).delay(700)
        }).delay(2400)
    } else {
        $(pageToHide.replace(/\//g, '-')).setStyle("overflow","hidden").set("tween",{
            duration:1200,
            transition:Fx.Transitions.Quint.easeInOut,
            onComplete:function(b){
                b.destroy()
            }
        }).tween.delay(0,$(pageToHide.replace(/\//g, '-')),["margin-left",-$(pageToHide.replace(/\//g, '-')).getSize().x])
    }
    eyeCandyKilling();
    fakeDomReady()
}

function setWebsiteLoader(){
    websiteLoaderEl=new Element("div",{
        id:"websiteLoader"
    }).setStyles({
        height:"100%",
        width:"100%","background-color":"#313131",
        position:"absolute","z-index":"1000",
        top:0,
        left:0
    }).inject(document.body);
    
    websiteLoaderSlider=new Element("div",{
        id:"websiteLoaderSlider"
    }).setStyles({
        height:"100%",width:"100%","background-color":"#000",position:"absolute","z-index":"1","margin-top":"-100%",left:0
    }).inject(websiteLoaderEl);
    
    websiteLoaderLogo=new Element("img",{
        id:"websiteLoaderLogo",
        src:"templates/dreamsolutions_cz/images/logo.png"
    }).setStyles({
        height:124,
        width:79,
        position:"absolute","z-index":"2","margin-left":-119,"margin-top":-102,
        top:"50%",
        left:"50%",
        opacity:0
    }).inject(websiteLoaderSlider);
    
    $("websiteLoaderSlider").set("tween",{
        duration:1400,transition:Fx.Transitions.Quint.easeInOut,unit:"%",
        property:"margin-top",
        onComplete:showRealLoader
    });
    
    if(Browser.Platform.name=="ios"){
        $("websiteLoaderSlider").setStyles({
            webkitTransitionDuration:"0",
            "-webkit-backface-visibility":"hidden",
            "-webkit-perspective":"1000",
            webkitTransform:"translate3d(0, -"+(document.body.getHeight())+"px, 0)","margin-top":0
        });
        (function(){
            $("websiteLoaderSlider").setStyles({
                webkitTransitionDuration:"700ms",
                webkitTransitionTimingFunction:"cubic-bezier(0.33,0.0,0.33,1)",
                webkitTransform:"translate3d(0, 0, 0)"
            })
        }).delay(1000);
        
        (function(){
            showRealLoader()
        }).delay(2400)
    } else {
        $("websiteLoaderSlider").tween.delay(1000,$("websiteLoaderSlider"),0)
    }
    
    $("websiteLoaderLogo").set("morph",{
        duration:500,
        transition:Fx.Transitions.Quint.easeOut,
    })
}

function showRealLoader(){
    $("websiteLoaderLogo").morph({
        "margin-top":-62,
        opacity:1
    });
    
    createWebsiteGraphicalLoader()
}

function createWebsiteGraphicalLoader(){
    preventSillyUsers();
    websiteLoaderBox=new Element("div",{
        id:"websiteLoaderBox",
        style:"position: absolute; z-index: 3; top: 50%; left: 50%; margin: -31px 0 0 -25px; width: 50px; height: 50px; border-radius: 10px; opacity: 0;"
    }).setStyles({
        transform:["scale(1)"]
    }).inject(websiteLoaderSlider).set("morph",{
        duration:700,
        transition:Fx.Transitions.Quint.easeOut
    });
    
    websiteLoaderSpinner=new Element("div",{
        id:"websiteLoaderSpinner",
        style:"width: 15px; height: 15px; opacity: 0; margin: 17px 0 0 18px;"
    }).inject(websiteLoaderBox).set("tween",{
        duration:700,transition:Fx.Transitions.Quint.easeOut
    });
    
    var b={
        lines: 16, // The number of lines to draw
          length: 0, // The length of each line
          width: 2, // The line thickness
          radius: 11, // The radius of the inner circle
          color: '#525252', // #rgb or #rrggbb
          speed: 1.6, // Rounds per second
          trail: 100, // Afterglow percentage
          shadow: true // Whether to render a shadow
    };
    
    var a=new Spinner(b).spin(websiteLoaderSpinner);
    
    (function(){
        if(Browser.Platform.name=="ios"){
            (function(){
                $("websiteLoaderBox").setStyles({
                    webkitTransition:"opacity .4s linear",
                    opacity:1
                })
            }).delay(300);
            
            (function(){
                $("websiteLoaderSpinner").setStyles({
                    webkitTransition:"opacity .4s linear",opacity:1
                })
            }).delay(600)
        } else {
            $("websiteLoaderBox").morph.delay(300,$("websiteLoaderBox"),[{
                opacity:"1"
            }]);
            
            $("websiteLoaderSpinner").tween.delay(600,$("websiteLoaderSpinner"),["opacity","1"])
        }
    }).delay(200)
    
    websiteLoaderText=new Element("div",{
        id:"websiteLoaderText",
        html: 'Čekejte prosím ...'
    }).set("class","cufon").setStyles({
        "color":"#7e7e7e",position:"absolute","z-index":"1",left:"50%", width: 150, "margin-left": "30px", "margin-top": "-5px",top:"50%"
    }).inject(websiteLoaderSpinner);
    Cufon.replace('.cufon, .websiteLoaderText', {
        hover: true
    });
}

function createandFadeLoader(d){
    var c=new Color($(pageToHide.replace(/\//g, '-')).getStyle("background-color"));
    var b=c.setBrightness(Math.max(0,c.hsb[2]-20)).setSaturation(Math.min(100,c.hsb[1]+20));
    var a=c.setBrightness(Math.max(0,c.hsb[2]-100)).setSaturation(10).invert();
    
    loaderOverlay=new Element("div",{
        style:"position: absolute; z-index: 1000; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; background-color: "+c.hex+";"
    }).inject(pageToHide.replace(/\//g, '-'));
    
    if(Browser.Platform.name=="ios"){
        (function(){
            $(loaderOverlay).setStyles({"-webkit-transition":"opacity .4s linear",opacity:1})
        }).delay(200)
    } else {
        loaderOverlay.set("tween",{
            duration:500,
            transition:Fx.Transitions.Quint.easeOut
        }).fade(0.8)
    }
    
    loaderBox=new Element("div",{
        style:"position: absolute; z-index: 1001; top: "+window.getHeight()/2+"px; left: 50%; margin: -25px 0 0 -25px; width: 50px; opacity: 0; height: 50px; border-radius: 10px; background-color:"+b.hex+";"
    }).inject(pageToHide.replace(/\//g, '-')).set("tween",{
        duration:500,
        transition:Fx.Transitions.Quint.easeOut
    });
    
    loaderSpinner=new Element("div",{
        id:"loaderSpinner",
        style:"position: absolute; z-index: 1002; top: "+(window.getHeight()/2)+"px; left: 50%; margin: -7px 0 0 -7px; width: 15px; height: 15px; opacity: 0;"
    }).inject(pageToHide.replace(/\//g, '-')).set("tween",{
        duration:500,
        transition:Fx.Transitions.Quint.easeOut
    });
    
    createSpinner("loaderSpinner",a.hex);
    (function(){
        if(Browser.Platform.name=="ios"){
            (function(){
                loaderBox.setStyles({
                    webkitTransition:"opacity .4s linear",
                    opacity:0.5
                })
            }).delay(400);
            
            (function(){
                loaderSpinner.setStyles({
                    webkitTransition:"opacity .4s linear",
                    opacity:1
                })
            }).delay(700)
        } else {
            loaderBox.tween.delay(300,loaderBox,["opacity",".5"]);
            loaderSpinner.tween.delay(600,loaderSpinner,["opacity","1"])
        }d.delay(1400)
    }).delay(400)
}

function createSpinner(d,a){
    var c={
        lines:16,
        length:0,
        width:3,
        radius:15,
        color:a,
        speed:1,
        trail:60,
        shadow:false
    };
    
    var b=new Spinner(c).spin($(d))
}

function startAnimation(){
    switch(pageToShow.replace(/\//g, '-')){
        case"titulni-stranka":
            startAnimationHomepage();            
        break;
    }
}

function startAnimationHomepage() {
    setMoosizer();
    resizeListener();
    doFirstLoadBG();
}

function slideWebsiteIn(){
    if(Browser.Platform.name=="ios"){
        $("websiteLoaderLogo").setStyles({
            webkitTransition:"opacity .3s linear",
            opacity:0
        });
        
        $("websiteLoaderSpinner").setStyles({
            webkitTransition:"opacity .3s linear",opacity:0
        });
        
        $("websiteLoaderBox").set("morph",{
            duration:500
        }).morph({
            transform:["scale(0)"]
        }).setStyles({
            webkitTransition:"opacity .5s linear",
            opacity:0
        });
        (function(){
            $("websiteLoader").setStyles({
                webkitTransition:"opacity .5s linear",
                opacity:0
            })
        }).delay(200)
    } else { 
        $("websiteLoaderLogo").set("morph",{
            duration:300
        }).morph({
            opacity:0
        });
        
        $("websiteLoaderSpinner").set("tween",{
            duration:300
        }).tween("opacity",0);
        
        $("websiteLoaderBox").set("morph",{
            duration:1500
        }).morph({
            opacity:0,
            transform:["scale(0)"]
        });
        
        $("websiteLoader").set("morph",{duration:500}).morph.delay(1000,$("websiteLoader"),[{opacity:0}])
    }
    
    (function(){
        Browser.ie8?$("websiteLoader").empty().dispose():$("websiteLoader").destroy();
        reenableSillyUsers()
    }).delay(1500)
}

function hideTheMenu(){
    $$("#header-top").set("tween",{
        duration:400,
        transition:Fx.Transitions.Back.easeInOut,
        onComplete:function(){
            slideThePageToTop()
        }
    }).tween.delay(200,$$("#"+pageToHide.replace(/\//g, '-')+" #header-top"),["top","-112"])
}

function slideThePageToTop(){
    scrollDocument=new Fx.Scroll(window,{
        duration:document.body.getScroll().y*1.5,
        transition:Fx.Transitions.Quint.easeInOut,
        wheelStops:false,
        onComplete:createandFadeLoader.bind(window,cssAndAssetsLoader)
    }).toTop()
}

function setMoosizer() {
    var setMoosizerCurrent = new mooSizer({bgElement:'slider-current'});
    var setMoosizerPrev = new mooSizer({bgElement:'slider-prev'});
    var setMoosizerNext = new mooSizer({bgElement:'slider-next'});
}

function resizeListener() {
    window.g_prevSize = getViewportSizeforSlider();
    regResizeListener = setInterval(doResize, 100);
}

function getViewportSizeforSlider() {
	var size = [0, 0];
	if (typeof window.innerWidth != 'undefined') {
			size = [ window.innerWidth, window.innerHeight ];
	} else if (typeof	document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)	{
			size = [ document.documentElement.clientWidth, document.documentElement.clientHeight ];
	} else	{
			size = [ document.getElementsByTagName('body')[0].clientWidth, document.getElementsByTagName('body')[0].clientHeight ];
	}
	return size;
}

function positionNavigationforSlider() {
    var regProportion = 0.25;
    var getMarginT = parseInt($("slider-current").getStyle('margin-top'));
    var getMarginL = parseInt($("slider-current").getStyle('margin-left'));
    var setTop = Math.floor(($('titulni-stranka').retrieve('win_y') - 142)/2)-getMarginT;
    $$('#navslide li').setStyles({'width':Math.round($('titulni-stranka').retrieve('win_x')*regProportion),'height':$('titulni-stranka').retrieve('win_y')+Math.abs(getMarginT)-190}); 
    $$('#navslide li .btn').setStyle('top',setTop);
    $$('#navslide .prev').setStyle('left',0);
    $$('#navslide .next').setStyle('right',0);
    $$('#navslide li').addEvent('click',function(e) {
        e.stop();
        window.location.href = this.getElement('a').get('href');
    })
}

function doResize() {
	var currentSize = getViewportSizeforSlider();
	if (currentSize[0] != g_prevSize[0] || currentSize[1] != g_prevSize[1])
	{
		g_prevSize = currentSize;
		resizeWrapper();
		positionNavigationforSlider.delay(300);
	}
}

function resizeWrapper() {
   $('titulni-stranka').store('win_x',window.getSize().x);
   $('titulni-stranka').store('win_y',window.getSize().y);
}

function doFirstLoadBG() {
    var sliderCurrent = 'slider-current';
    var sliderPrev = 'slider-prev';
    var sliderNext = 'slider-next';
    var actualSlide = 0;
    var registerGrowRatio = 60;
    var nbSlide = 7;
    var scrollWrapper;
    var slideCursor = 0;
    var regFeatures = [
        {'color_code':'dark', 'font':'none', 'titre':'<a href="http://www.ultranoir.com/en/#!/projects/societe_generale/collection_societe_generale_v2/" title="Collection société générale v2">Collection société générale v2</a>', 'soustitre':'<li>Official website</li><li class=\"last\">Société Générale</li>', 'categorie':'<li>Conception</li><li>Art direction</li><li>HTML Integration</li><li>Development</li><li class=\"last\">Back office</li>'},
        {'color_code':'dark', 'font':'none', 'titre':'<a href="http://www.ultranoir.com/en/#!/projects/ultranoir/nouvelle_vague/" title="Nouvelle Vague">Nouvelle Vague</a>', 'soustitre':'<li>Application</li><li class=\"last\">ultranoir</li>', 'categorie':'<li>Conception</li><li>Art direction</li><li>HTML Integration</li><li class=\"last\">Development</li>'},
        {'color_code':'dark', 'font':'none', 'titre':'<a href="http://www.ultranoir.com/en/#!/projects/orange_cinema_series/breaking_bad_saison_4/" title="Breaking Bad Saison 4">Breaking Bad Saison 4</a>', 'soustitre':'<li>microsite</li><li class=\"last\">orange cinéma séries</li>', 'categorie':'<li>Conception</li><li>Art direction</li><li>Flash Animation</li><li class=\"last\">Development</li>'},
        {'color_code':'dark', 'font':'none', 'titre':'<a href="http://www.ultranoir.com/en/#!/projects/ubik_starck_network/starck.com/" title="starck.com">starck.com</a>', 'soustitre':'<li>Official website</li><li class=\"last\">Ubik / Starck Network</li>', 'categorie':'<li>Conception</li><li>Art direction</li><li>HTML Integration</li><li>Development</li><li class=\"last\">Back office</li>'},
        {'color_code':'dark', 'font':'none', 'titre':'<a href="http://www.ultranoir.com/en/#!/projects/bva/mobile.bva.fr/" title="MOBILE.BVA.FR">MOBILE.BVA.FR</a>', 'soustitre':'<li>Mobile website</li><li class=\"last\">BVA</li>', 'categorie':'<li>Conception</li><li>Art direction</li><li>HTML Integration</li><li>Development</li><li class=\"last\">Back office</li>'},
        {'color_code':'dark', 'font':'none', 'titre':'<a href="http://www.ultranoir.com/en/#!/projects/orange_cinema_series/boardwalk_empire/" title="Boardwalk Empire">Boardwalk Empire</a>', 'soustitre':'<li>microsite</li><li class=\"last\">orange cinéma séries</li>', 'categorie':'<li>Conception</li><li>Art direction</li><li>Flash Animation</li><li>HTML Integration</li><li class=\"last\">Development</li>'},
        {'color_code':'dark', 'font':'none', 'titre':'<a href="http://www.ultranoir.com/en/#!/projects/lip/lip.fr/" title="lip.fr">lip.fr</a>', 'soustitre':'<li>ecommerce website</li><li class=\"last\">lip</li>', 'categorie':'<li>Conception</li><li>Art direction</li><li>HTML Integration</li><li>Development</li><li class=\"last\">Back office</li>'}];
    var regNewBottom;
    var listenerSMC = 0;
    var movingSMC = 0;
    var regMedia = [
        {'type':'img', 'source_html':'', 'source_file':'', 'source_img':'http://www.ultranoir.com/data/portfolio/fiche/358/xlarge_sg_48f7a.jpg'},
        {'type':'img', 'source_html':'', 'source_file':'', 'source_img':'http://www.ultranoir.com/data/portfolio/fiche/359/xlarge_visuel_home_nouvelle_vague_32761.jpg'},
        {'type':'img', 'source_html':'', 'source_file':'', 'source_img':'http://www.ultranoir.com/data/portfolio/fiche/361/xlarge_bb_ba0a3.jpg'},
        {'type':'img', 'source_html':'', 'source_file':'', 'source_img':'http://www.ultranoir.com/data/portfolio/fiche/81/xlarge_big_visuel_78552.jpg'},
        {'type':'img', 'source_html':'', 'source_file':'', 'source_img':'http://www.ultranoir.com/data/portfolio/fiche/240/xlarge_bva_d08c4.jpg'},
        {'type':'video', 'source_html':'<source src="http://www.ultranoir.com/data/portfolio/fiche/265/trailer_facebook_h264_48ea6.mp4" type="video/mp4" />', 'source_file':'http://www.ultranoir.com/data/portfolio/fiche/265/trailer_facebook_h264_48ea6.mp4', 'source_img':'http://www.ultranoir.com/data/portfolio/fiche/265/xlarge_bwe_55f00.jpg'},
        {'type':'img', 'source_html':'', 'source_file':'', 'source_img':'http://www.ultranoir.com/data/portfolio/fiche/219/xlarge_lip_home_1920_1020_source_cz_16592.jpg'}];
    
    $('titulni-stranka').store('win_x',window.getSize().x);
    $('titulni-stranka').store('win_y',window.getSize().y);
    $('titulni-stranka').store('goslide','0');
    $('titulni-stranka').store('memo_slide','0');
    $('titulni-stranka').store('video_actif','0');
    $('titulni-stranka').store('check_fading','0');
    $('titulni-stranka').store('firstBGtoLoad','/storage/images/wallpaper_products.jpg');
    Asset.image($('titulni-stranka').retrieve('firstBGtoLoad'), {
        'title': '',
        'class': 'firstloadimg',
        onLoad: function(img) {
            img.inject($(sliderCurrent));
            img.tween('opacity',[0,1]);
            
        }
    });
    var regFXFeaturesBottom = new Fx.Morph( $('features-wrapper'),{duration:300,transition:'pow:out',wait:'false'});
    (function() {
        if($('features-wrapper').hasClass('adjustement')) {
            regNewBottom = 2;
        } else {
            regNewBottom = 65;
        }
        regFXFeaturesBottom.start({'bottom':regNewBottom});
    }).delay(1500);
}

function unLogoRolloverFx(){
    if(Modernizr.cssanimations && Modernizr.csstransforms3d) {
    	var target = document.getElementById('logo_un');
    	var hoverStatus = false;
    	var animationPlay = false;
    	target.addEventListener(
    		"webkitAnimationEnd",function(){
    			animationPlay = false;
    			target.getElementsByTagName('a')[0].style.webkitAnimationName="";	
    		},false
    	);
    	target.addEvents({			   
    		'mouseenter':function(){
    			hoverStatus = true;
    			animationPlay = true;
    			target.getElementsByTagName('a')[0].setStyle('webkitAnimationName','rotateLogo');
    		},
    		'mouseleave':function(){
    			hoverStatus = false;
    		}
    	});
    	function restartAnim(){
    		if( (hoverStatus == true) && (animationPlay == false) ){
    			target.getElementsByTagName('a')[0].style.webkitAnimationName="rotateLogo";
    		}
    	};
    	setInterval(restartAnim,100);
    }
}

function mainNavItemRollover() {
    mainNavItemRolloverSoundFx()
	var mainnavItems = $$('#main-menu li a');
    var tweenBG = [];
    mainnavItems.each(function(el,i){
        if(!el.hasClass('active')){
            tweenBG[i] = new Fx.Morph(el,{duration: 300, transition: 'pow:out', wait:false, 'link':'cancel'});
            el.setStyle('background-position','0px 50px');
        }
    });
    mainnavItems.each(function(el,i){
        el.addEvents({
            'click':function(e) { /*$$('#nav .item:not(.active)').getElement('a').setStyle('color','#fff'); $$('#nav .item:not(.active)').setStyle('background-position','0px 0px'); this.getElement('a').setStyle('color','#000'); this.setStyle('color','#000');*/ },
            'mouseenter':function(e){el.setStyle('color','#fff');tweenBG[i].start({'background-position':'0px 0'});},
            'mouseleave':function(e){if(!el.hasClass('active')) {el.setStyle('color','#c7c7c7');tweenBG[i].start({'background-position':'0px 50px'});}}
        });
    });


}

function mainNavItemRolloverSoundFx(){
	if(Modernizr.audio){
		navItems = $$('#main-menu li');
		navItems.each(function(el,i){
			var soundFx = el.getElement('.sound_player');
			if( !(el.hasClass('separator'))){
				el.addEvent( 'mouseenter', function(){soundFx.play();});
			}
		});
	}
}
