google.load("jquery", "1.4");
google.load("jqueryui", "1.8");
google.setOnLoadCallback(function(){$(function() {livedome.init();});});
var livedome = {
   cliplist:null,
   slideshow_ident: 0,
   slideshow_play: true,
   slideshow_timeout: 3000,
   init: function() {livedome.setDefaultBehaviors();},
   setDefaultBehaviors: function() {
      // Search
      var $sf = $("form#search"), $sq = $("input#q"), $sq_val = $sq.val(), $ss = $("input#s");
      $sf.click(function() { $sq.focus(); });
      $sq.focus(function() { if ($sq.val() == $sq_val) $sq.val(""); });
      $sq.blur(function() { if ($sq.val() == "") $sq.val($sq_val); });
      $ss.mousedown(function() { $(this).addClass("active"); });
      $ss.mouseup(function() { $(this).removeClass("active"); });
      // Newsletter
      var $nf = $("div#aside_newsletter div.input"), $ne = $("input#newsletter_email"), $ne_val = $ne.val(), $ns = $("input#newsletter_submit");
      $nf.click(function() { $ne.focus(); });
      $ne.focus(function() { if ($ne.val() == $ne_val) $ne.val(""); });
      $ne.blur(function() { if ($ne.val() == "") $ne.val($ne_val); });
      $ns.mousedown(function() { $(this).addClass("active"); });
      $ns.mouseup(function() { $(this).removeClass("active"); });
   },
   setCarousel: function(container, width) {
      var $c = $("div#"+container+" div.carousel");
      var ident = 0, max = $c.find("li").length-1;
      $c.find("ul").css("width", max*width+width);
      $c.find("a.control.arrow_left, a.control.arrow_right").mousedown(function() { $(this).addClass("active"); });
      $c.find("a.control.arrow_left, a.control.arrow_right").mouseup(function() { $(this).removeClass("active"); });
      $c.find("a.control.arrow_left").click(function() {
         if (ident>0) {
            $c.find("ul").animate({left: "+="+width});
            ident--;
         } else {
            $c.find("ul").animate({left: "-="+max*width});
            ident = max;
         }
         return false;
      });
      $c.find("a.control.arrow_right").click(function() {
         if(ident<max) {
            $c.find("ul").animate({left: "-="+width});
            ident++;
         } else {
            $c.find("ul").animate({left: "+="+max*width});
            ident = 0;
         }
         return false;
      });
   },
   setStageSlideshow: function(container) {
      var $c = $("div."+container);
      $c.find("div.carousel div.container li").hover(
         function() {
            var $this = $(this);
			/*alert($this);*/
            if ($this.find("div.highlight").length == 0) {
               $c.find("div.carousel div.container li div.highlight").remove();
               $this.append("<div class=\"highlight\">&nbsp;</div>");
            }
         },
         function() {
            $c.find("div.carousel div.container li div.highlight").remove();
            $c.find("div.carousel div.container li.active").append("<div class=\"highlight\">&nbsp;</div>");
         }
      );
      $c.find("div.carousel div.container li").click(function() {
         $c.find("div.carousel div.container li").removeClass("active");
         $(this).addClass("active");
         var ident = $(this).index();
         livedome.slideshow_play = false;
         livedome.slideshow_ident = ident;
         $c.find("div.images div.section, div.info div.section").hide();
         $c.find("div.images div.section:eq("+ident+"), div.info div.section:eq("+ident+")").show();
         $("div#stage div.progress").removeClass("z0 z1 z2 z3");
         $("div#stage div.progress").addClass("z"+ident);
         return false;
      });
      $c.find("a.control.arrow_left").click(function() {
         livedome.slideshow_play = false;
         livedome._changeStageSlideshow((livedome.slideshow_ident == 0 ? 3 : livedome.slideshow_ident-1));
         return false;
      });
      $c.find("a.control.arrow_right").click(function() {
         livedome.slideshow_play = false;
         livedome._changeStageSlideshow((livedome.slideshow_ident == 3 ? 0 : livedome.slideshow_ident+1));
         return false;
      });
      window.setTimeout("livedome._playStageSlideshow()", livedome.slideshow_timeout);
   },
   _playStageSlideshow: function() {
      if (livedome.slideshow_play) {
         livedome._changeStageSlideshow((livedome.slideshow_ident == 3 ? 0 : livedome.slideshow_ident+1));
         window.setTimeout("livedome._playStageSlideshow()", livedome.slideshow_timeout);
      }
   },
   _changeStageSlideshow: function(slide) {
      $("div#stage div.images div.section:eq("+livedome.slideshow_ident+"), div.info div.section:eq("+livedome.slideshow_ident+")").fadeOut(1000);
      $("div#stage div.carousel div.container li").removeClass("active");
      $("div#stage div.carousel div.container li div.highlight").remove();
      $("div#stage div.progress").removeClass("z0 z1 z2 z3");
      livedome.slideshow_ident = slide;
      $("div#stage div.images div.section:eq("+livedome.slideshow_ident+"), div.info div.section:eq("+livedome.slideshow_ident+")").fadeIn(1000);
      $("div#stage div.carousel div.container li:eq("+livedome.slideshow_ident+")").addClass("active");
      $("div#stage div.carousel div.container li:eq("+livedome.slideshow_ident+")").append("<div class=\"highlight\">&nbsp;</div>");
      $("div#stage div.progress").addClass("z"+livedome.slideshow_ident);
   },
   setStageNav: function(container, height) {
      var $c = $("div."+container);
      var reset = false;
      var ident = 0;
      var max = Math.ceil(($c.find("div.section ul").height()-406)/406);
      var handle = Math.ceil(100/max);
      $c.find("ul#stagenav li").click(function() {
         var active = $(this).attr("class").split(" ")[0];
         $c.find("ul#stagenav li").removeClass("active");
         $c.find("ul#stagenav li."+active).addClass("active");
         $c.find("div.section").hide();
         $c.find("div.section."+active).show();
      });
      $("div.scroll_arrow.down").mousedown(function() {
         if (reset) {
            $slide.css("top", "0");
            $("a.ui-slider-handle").css("bottom", "100%");
            ident = 0;
            reset = false;
         }
         if (ident<max) {
            $slide.animate({top: "-=406"});
            var pos = parseInt($("a.ui-slider-handle").css("bottom"));
            if (ident == (max-1)) {
               $("a.ui-slider-handle").animate({bottom: "0%"});
            } else {
               $("a.ui-slider-handle").animate({bottom: pos-handle+"%"});
            }
            ident++;
         }
      });
      $("div.scroll_arrow.up").mousedown(function() {
         if (reset) {
            $slide.css("top", "0");
            $("a.ui-slider-handle").css("bottom", "100%");
            ident = 0;
            reset = false;
         }
         if (ident>0) {
            $slide.animate({top: "+=406"});
            var pos = parseInt($("a.ui-slider-handle").css("bottom"));
            if (ident == 1) {
               $("a.ui-slider-handle").animate({bottom: "100%"});
            } else {
               $("a.ui-slider-handle").animate({bottom: pos+handle+"%"});
            }
            ident--;
         }
      });
      var $slide = $c.find("div.section ul");
      var slide_height = $c.find("div.section ul").height()-height;
      $("div#slider").slider({
         orientation: "vertical",
         value: slide_height,
         max: slide_height,
         slide: function(event, ui) {
            $slide.css("top", ui.value-slide_height);
            reset = true;
         }
      });
      $("div.scroll_arrow.up").mousedown(function() { $(this).addClass("active"); });
      $("div.scroll_arrow.up").mouseup(function() { $(this).removeClass("active"); });
      $("div.scroll_arrow.down").mousedown(function() { $(this).addClass("active"); });
      $("div.scroll_arrow.down").mouseup(function() { $(this).removeClass("active"); });
      $("a.ui-slider-handle").mousedown(function() { $(this).addClass("active"); });
      $("a.ui-slider-handle").mouseup(function() { $(this).removeClass("active"); });
      $("a.ui-slider-handle").blur(function() { $(this).removeClass("active"); });
   },
   
   setAccordion: function(container) {
      var $s = $("div#"+container).find("div.section");
      $s.find("div.control").mousedown(function() { $(this).addClass("active"); });
      $s.find("div.control").mouseup(function() { $(this).removeClass("active"); });
      $s.each(function() {$(this).css("height", "50px");});
      var $active = false;
      $s.find("div.control").click(function() {
         var $this = $(this);
         if ($this.parent().height() == 50) {
            if ($active) $active.animate({height: "50px"});
            $this.parent().animate({height: $this.parent().find("div.content").height()+60+"px"});
            $active = $(this).parent();
            $s.find("div.control").removeClass("active");
            $(this).addClass("active");
         } else {
            $this.parent().animate({height: "50px"});
            $active = false;
         }
      });
   },
   setGallery: function(container, width) {
      var $c = $("div#"+container);
      var ident = 0, max = Math.ceil(($c.find("li").length)/4)-1;
      $c.find("ul").css("width", max*width+width);
      $c.find("a.control.arrow_left, a.control.arrow_right").mousedown(function() { $(this).addClass("active"); });
      $c.find("a.control.arrow_left, a.control.arrow_right").mouseup(function() { $(this).removeClass("active"); });
      $c.find("a.control.arrow_left").click(function() {
         if (ident>0) {
            $c.find("ul").animate({left: "+="+width});
            ident--;
         } else {
            $c.find("ul").animate({left: "-="+max*width});
            ident = max;
         }
         return false;
      });
      $c.find("a.control.arrow_right").click(function() {
         if(ident<max) {
            $c.find("ul").animate({left: "-="+width});
            ident++;
         } else {
            $c.find("ul").animate({left: "+="+max*width});
            ident = 0;
         }
         return false;
      });
      $c.find("li").click(function() {
         var img = $(this).index();
         $c.find("div.image img").hide();
         $c.find("div.image img:eq("+img+")").show();
         $c.find("li div.highlight").remove();
         $c.find("li:eq("+img+")").append("<div class=\"highlight\">&nbsp;</div>");
      });
   },
   switchCategories: function(container) {
      var $c = $("div#"+container);
      $c.find("a.cat").click(function() {
         var cat = $(this).attr("class").split(" ")[1];
         $c.find("div.cat").hide();
         $c.find("a.cat").removeClass("active");
         $c.find("div.cat."+cat).show();
         $c.find("a.cat."+cat).addClass("active");
         return false;
      });
   },
    openPlayer: function() {
        
        var event_id = $('#player_iframe').attr("title");
        switch(event_id){
            case "interview":$('#player_iframe').attr('src', 'http://www.livedome.com/flowplayer-3.2.3/interviews-ld.html?id='+$('#interview_id').attr("title")); 
            break;
            case "sport":$('#player_iframe').attr('src', 'http://kunden.wundermedia.de/livedome/player/'+$('#sport_id').attr("title")+'/livedome.com/'); 
            break;
            case "live": break;
            default:$('#player_iframe').attr('src', 'http://www.livedome.com/flowplayer-3.2.3/archivplayer-ld.html?id='+event_id+'&clip=0'); 
            break;
        }	  
        $("div#player").show();
    },
   closePlayer: function() {
      $("div#player").hide();
   },
   
   setPlayer: function(container) {
      var $c = $("div#"+container);
      $c.find("a.close").click(function() {
         livedome.closePlayer();
         return false;
      });
      $c.find("li").click(function() {
         var active = $(this).attr("class").split(" ")[0];
         if ($c.find("li."+active).children("a").length == 0) {
            $c.find("li").removeClass("active");
            $c.find("div.meta div.section").hide();
            $c.find("li."+active).addClass("active");
            $c.find("div.meta div.section."+active).show();
            $c.find("a.toggle").removeClass("show");
            $c.find("a.toggle").addClass("hide");
         }
         return false;
      });
      $c.find("a.toggle").click(function() {
         var state = $(this).attr("class").split(" ")[1];
         if (state == "hide") {
            $c.find("li").removeClass("active");
            $c.find("div.meta div.section").hide();
            $(this).removeClass("hide");
            $(this).addClass("show");
         } else if (state == "show") {
            $c.find("li.info").addClass("active");
            $c.find("div.meta div.info").show();
            $(this).removeClass("show");
            $(this).addClass("hide");
         }
         return false;
      });      
   },
   setNextClip:function(_id){
        var fileurl= "";
        if(typeof livedome.cliplist != "undefined"){
            if(typeof livedome.cliplist[_id] != "undefined"){
                //set videotype
        		var vt = (typeof livedome.cliplist[_id].video_type == "undefined") ? livedome.cliplist["video_type"] : livedome.cliplist[_id].video_type ;
                switch(vt){
        			case ".mp4": fileurl="mp4:"+livedome.cliplist["folder"]+livedome.cliplist[_id].url;break;
        			case ".f4v": fileurl="mp4:"+livedome.cliplist["folder"]+livedome.cliplist[_id].url+".f4v";break;
        			case ".flv": fileurl=livedome.cliplist["folder"]+livedome.cliplist[_id].url+".flv";break;
        		}
                if(fileurl.length > 0){$f("playerbox").play(fileurl)}  
            }    
        }
   },
   setCliplist:function(list){
        if(!list){list = null}
        if(typeof(list) == "object"){
            var li = "";
            var w = list["size"]*100;
            var thumb = "";
            for(var i = 0; i < list["size"];i++ ){
                li = $("<li></li>").css("float","left");
                $("<img />").attr("src",list[i].thumb).css("cursor","pointer").appendTo(li)
                li.append("<br/>");
                li.append('<a href="#">'+list[i].title+'</a>');
                if(i==0){ li.append('<div class="highlight">&nbsp;</div>');  }
                $("ul#cliplist").append(li);    
            }
            if(typeof document.getElementById('cliplist') != "undefined"){
                livedome.setPlayerCarousel("clip_auswahl", 500);  
            }
            livedome.cliplist = list;
        }  
    },
   setFlowPlayer: function(container,player,fileurl){
      
      var random = Math.floor(Math.random() * 4900) + 1;
      random=random*random;
      
      if(arguments.length < 4){
        
        var plugin_uif = {
                
                videoCompleteCallback:"",
                url: "http://www.livedome.com/flowplayer/plugins/uif.swf"+'?'+Math.round(random),
                preroll:  escape("http://ad-emea.doubleclick.net/ad/livedome.smartclip/;sz=400x320;dcmt=text/xml;ord="+Math.round(random)+"?")
                
        };
        
        /*
        // ABFRAGE FUER CLIPS OHNE PREROLLS
        if(fileurl.match(/^mp4:Turk-Kaz|mp4:Turk-Asa/)){
           
            plugin_uif = {}
            
        }
        */
        
        
        flowplayer(player, {src:"http://www.livedome.com/flowplayer/lib/flowplayer.commercial-3.2.7.swf",wmode:'transparent'}, {
            key:"#$b6a516aabb2124f3ba6",
            clip:{	
            
            provider: "rtmp",				
            autoPlay: true,
            url:fileurl 
            
            },
            plugins:{
                rtmp:{
                    
                    url: "http://www.livedome.com/flowplayer/lib/flowplayer.rtmp-3.2.3.swf",
                    netConnectionUrl: "rtmp://livedomefs.fplive.net/livedome/"
                    					
                },
                uif:plugin_uif
            }
        });
          
      }
      
      var $c = $("div#"+container);
      $c.find("a.close").click(function() {livedome.closePlayer();return false;});
      $c.find("li").click(function() {
         var active = $(this).attr("class").split(" ")[0];
         if ($c.find("li."+active).children("a").length == 0) {
            $c.find("li").removeClass("active");
            $c.find("div.meta div.section").hide();
            $c.find("li."+active).addClass("active");
            $c.find("div.meta div.section."+active).show();
            $c.find("a.toggle").removeClass("show");
            $c.find("a.toggle").addClass("hide");
         }
         return false;
      });
      $c.find("a.toggle").click(function() {
         var state = $(this).attr("class").split(" ")[1];
         if (state == "hide") {
            $c.find("li").removeClass("active");
            $c.find("div.meta div.section").hide();
            $(this).removeClass("hide");
            $(this).addClass("show");
         } else if (state == "show") {
            $c.find("li.info").addClass("active");
            $c.find("div.meta div.info").show();
            $(this).removeClass("show");
            $(this).addClass("hide");
         }
         return false;
      });      
   },
   
   setPlayerCarousel : function(container, width) {
      var $c = $("div."+container);
      var ident = 0, max = Math.ceil(($c.find("li").length)/5)-1;
      $c.find("ul").css("width", max*width+width);
      $c.find("a.control.arrow_left, a.control.arrow_right").mousedown(function() { $(this).addClass("active"); });
      $c.find("a.control.arrow_left, a.control.arrow_right").mouseup(function() { $(this).removeClass("active"); });
      /*added by Marion start */
	  $c.find("div.carousel div.container li").hover(
         function() {
            var $this = $(this);
            if ($this.find("div.highlight").length == 0) {           
			   $c.find("div.carousel div.container li div.highlight").remove();
               $this.append("<div class=\"highlight\">&nbsp;</div>");			   
            }
         },
         function() {
            $c.find("div.carousel div.container li div.highlight").remove();
            $c.find("div.carousel div.container li.active").append("<div class=\"highlight\">&nbsp;</div>");
         }
      );  
	  $c.find("div.carousel div.container li").click(function() {
         $c.find("div.carousel div.container li").removeClass("active");
         $(this).addClass("active");         
		 var ident = $("div.carousel div.container li").index(this);         
		 livedome.slideshow_play = false;
         livedome.slideshow_ident = ident;
         $c.find("div.images div.section, div.info div.section").hide();
         $c.find("div.images div.section:eq("+ident+"), div.info div.section:eq("+ident+")").show();
         $("div#stage div.progress").removeClass("z0 z1 z2 z3");
         $("div#stage div.progress").addClass("z"+ident);
         livedome.setNextClip(ident);
         return false;
      });
	  /* added by Marion end */
      $c.find("a.control.arrow_left").click(function() {
         if (ident>0) {
            $c.find("ul").animate({left: "+="+width});
            ident--;
         } else {
            $c.find("ul").animate({left: "-="+max*width});
            ident = max;
         }
         return false;
      });
      $c.find("a.control.arrow_right").click(function() {
         if(ident<max) {
            $c.find("ul").animate({left: "-="+width});
            ident++;
         } else {
            $c.find("ul").animate({left: "+="+max*width});
            ident = 0;
         }
         return false;
      });
   }
}

