jQuery.noConflict(); 

/////////////////////////////////////////////////////
// Javascript  - flash Interaction controller
////////////////////////////////////////////////////

var JSFL = {
  initialized: false,
  callFlash: true,
  callback: function () {},
  setFlash: function () {
    if (!JSFL.initialized) {
      try {
        JSFL.swfobj.write("mosaicwrapper");
        JSFL.initialized = true;
      } catch(e) { // alert("exception caught : "+e);
        return false;
      }
    }
    if (!JSFL.swfobj || !JSFL.swfobj.tagName) {
      try {
        var name = "mosaic";
        var isIE = jQuery.browser.msie;
        window[name] = document.forms[0].mosaic;
        if (JSFL.swfobj = (isIE) ? window[name] : document[name]) {
          return true;
        } else return false;
      } catch(e) {
        return false;
      }
    } else return true;
  },
  stopCurrentAction: function () {
    try {
      if (!JSFL.setFlash() || typeof(JSFL.swfobj.cqStop) == "undefined") {
        setTimeout("JSFL.stop();", 1000);
      } else JSFL.swfobj.cqStop();
    } catch(e) { // alert("exception caught : "+e);
    }
  },
  theme: function (id, callback) {
    JSFL.callback = callback ? callback : function () {};
    try {
      if (JSFL.callFlash) {
        if (!JSFL.setFlash() || typeof(JSFL.swfobj.cqGetTheme) == "undefined") {
          setTimeout("JSFL.theme(" + id + ", JSFL.callback);", 1000);
        } else {
          setTimeout("JSFL.swfobj.cqGetTheme(" + id + ")", 500);
          JSFL.callback();
        }
      }
    } catch(e) { // alert("exception caught : "+e);
    }
  },
  search: function (id) {
    try {
      if (JSFL.callFlash) {
        if (!JSFL.setFlash() || typeof(JSFL.swfobj.cqSearch) == "undefined") {
          setTimeout("JSFL.search('" + id + "');", 1000);
        } else JSFL.swfobj.cqSearch(id);
      }
    } catch(e) { // alert("exception caught : "+e);
    }
  },
  load: function (suffix, id, clip) {
    if (JSFL.callFlash) {
      try {
        if (!JSFL.setFlash() || typeof(JSFL.swfobj.cqLoad) == "undefined") {
          setTimeout("JSFL.load('" + suffix + "', '" + id + "', '" + clip + "');", 1000);
        } else {
          if (typeof(clip) != "undefined") {
            JSFL.swfobj.cqLoad(suffix, id, clip);
          } else if (typeof(id) != "undefined") {
            JSFL.swfobj.cqLoad(suffix, id);
          } else {
            JSFL.swfobj.cqLoad(suffix);
          }
        }
      } catch(e) { // alert("exception caught : "+e);
      }
    }
  },
  clear: function () {
    try {
      if (!JSFL.setFlash() || typeof(JSFL.swfobj.cqClearAll) == "undefined") {
        setTimeout("JSFL.clear();", 1000);
      } else JSFL.swfobj.cqClearAll();
    } catch(e) { // alert("exception caught : "+e);
    }
  },
  clearMosaic: function () {
    try {
      if (!JSFL.setFlash() || typeof(JSFL.swfobj.cqClearAll) == "undefined") {
        setTimeout("JSFL.clearMosaic();", 1000);
      } else JSFL.swfobj.cqClearMosaic();
    } catch(e) { // alert("exception caught : "+e);
    }
  },
  pending: function () {
    try {
      if (!JSFL.setFlash() || typeof(JSFL.swfobj.cqShowPendingWheel) == "undefined") {
        setTimeout("JSFL.pending();", 1000);
      } else JSFL.swfobj.cqShowPendingWheel();
    } catch(e) { // alert("exception caught : "+e);
    }
  },
  stop: function () {
    try {
      if (!JSFL.setFlash() || typeof(JSFL.swfobj.cqShowPendingWheel) == "undefined") {
        setTimeout("JSFL.stop();", 1000);
      } else JSFL.swfobj.cqShowPendingWheel();
    } catch(e) { // alert("exception caught : "+e);
    }
  },
  playVideo: function (url, clipname, question) {
    /* 	Parameters are:
					url : the URL of the clip, of the form "/Document/Clips/...flv"
					clipname : the user-friendly identifier of the clip
					question : the associated quiz question of this clip
				*/
    if (JSFL.callFlash) {
      var name_format = clipname.split(':', 2)[1];
      if (!name_format) name_format = clipname;
      if (name_format.charAt(0) == ' ') name_format = name_format.substr(1, clipname.length - 1);
      try {
        if (!JSFL.setFlash() || typeof(JSFL.swfobj.cqPlayVideo) == "undefined") {
          var question_format = question.replace("'", "\'");
          setTimeout("JSFL.playVideo('" + url + "','" + clipname + "','" + question_format + "', '');", 1000);
        } else JSFL.swfobj.cqPlayVideo(url, name_format, question, '');
      } catch(e) { // alert("exception caught : "+e);
      }
    }
  },
  filter: function (type) {
    try {
      if (!JSFL.setFlash() || typeof(JSFL.swfobj.cqFilterBy) == "undefined") {
        setTimeout("JSFL.filter('" + type + "');", 1000);
      } else JSFL.swfobj.cqFilterBy(type);
    } catch(e) { // alert("exception caught : "+e);
    }
  },
  showDefaultImage: function (module) {
    try {
      if (!JSFL.setFlash() || typeof(JSFL.swfobj.cqShowDefaultImage) == "undefined") {
        setTimeout("JSFL.showDefaultImage('" + module + "');", 1000);
      } else JSFL.swfobj.cqShowDefaultImage(module);
    } catch(e) { // alert("exception caught : "+e);
    }
  }
} 

//////////////////////////////////////////////////////////////
// Popup Controller 
//////////////////////////////////////////////////////////////

var Popup = {
  oneliner: function (text, duration, callback) {
    /* jQuery("body").append("<div class='popup_oneliner'><span>"+text+"<span></div>");
        						jQuery(".popup_oneliner")
        												.ifixpng()
        												.width(686)
        												.height(162)
        												.css('text-align', "center")
        												.css("position", "absolute")
        												.css("font", "50px Georgia")
        												.css("color", "#ffffff")
        												.css("top", jQuery(document).scrollTop()+((jQuery(window).height()-162)/2))
        												.css("left", (jQuery(window).width()-686)/2)
        												.animate({opacity:1}, {duration:300, easing:"easeOutSine", complete:function(){
        								
        								
        								jQuery(window).scroll(function(){
        									jQuery(".popup_oneliner").css("top", jQuery(document).scrollTop()+((jQuery(window).height()-162)/2))
        								});
        								
        								var cb = function(){
        									jQuery(".popup_oneliner").animate({opacity:0}, {duration:300, easing:"easeOutSine", complete:
        										function(){
        											jQuery(".popup_oneliner").remove();
        											callback();
        											jQuery(window).unbind("scroll");
        										}
        									});
        								};
        								
        								setTimeout("cb();", duration);
        						}});
        						*/
    callback();
  },
  //This is a DHTML version of the javascript "alert" function
  alert: function (text, callback) {
    Popup.callback = callback ? callback : function () {};
    var controls = "<a onclick='Popup.callback(true);Popup.close();return false;'>OK</a>";
    Popup.printBubble(text, controls);
  },
  //This is a DHTML version of the javascript "prompt" function
  prompt: function (text, callback) { //var result = confirm(text); //Use javascript confirm for now, skin something later.
    //callback(result);
    Popup.callback = callback ? callback : function () {};
    var controls = "<a onclick='Popup.callback(true);Popup.close();return false;'>Oui</a>";
    controls += "<a onclick='Popup.callback(false);Popup.close();return false;'>Non</a>";
    Popup.printBubble(text, controls);
  },
  //This function should not be used directly outside of the Popup namespace
  printBubble: function (text, controls) {
    jQuery("#body").append("<div class='popup-wrapper'><div class='popup'><div>" + text + "</div><div>" + controls + "</div></div></div>");
    jQuery(".popup").css("top", jQuery(window).scrollTop() + Math.floor(jQuery(window).height() / 5));
  },
  close: function () {
    jQuery("#body div.popup-wrapper").remove();
  }
} 

//////////////////////////////////////////////////////////////
// Loading bar Controller 
//////////////////////////////////////////////////////////////

var LoadingBar = {
  current: 0,
  width: 0,
  isShown: false,
  callback: function () {},
  show: function (id, callback) {
    LoadingBar.callback = callback ? callback : function () {};
    if (!LoadingBar.isShown) {
      LoadingBar.isShown = true;
      var elem = jQuery(id);
      var w = elem.width() + parseInt(elem.css("padding-left")) + parseInt(elem.css("padding-right"));
      var h = elem.height() + parseInt(elem.css("padding-top")) + parseInt(elem.css("padding-bottom"));
      elem.append("<div class='loadingCanevasBackground'></div>");
      elem.append("<div class='loadingCanevas'></div>");
      jQuery(".loadingCanevas, .loadingCanevasBackground", elem).height(h);
      jQuery(".loadingCanevas", elem).append("<div class='loadingBar'></div>");
      var lbw = jQuery(".loadingBar", elem).width();
      var lbh = jQuery(".loadingBar", elem).height();
      var l = (w - lbw) / 2;
      var t = (h - lbh) / 2;
      jQuery(".loadingBar", elem).append("<div class='loadingProgress'></div>").css("top", t).css("left", l);
      LoadingBar.width = lbw - (2 * parseInt(jQuery(".loadingProgress", elem).css("left")));
      jQuery(".loadingCanevasBackground", elem).animate({
        opacity: 0.4
      },
      {
        duration: 200,
        easing: "easeOutExpo",
        complete: function () {
          jQuery(".loadingCanevas", elem).animate({
            opacity: 1
          },
          {
            duration: 100,
            easing: "easeOutExpo"
          });
        }
      });
    }
  },
  hide: function () {
    jQuery(".loadingCanevas").animate({
      opacity: 0
    },
    {
      duration: 100,
      easing: "easeOutExpo",
      complete: function () {
        jQuery(".loadingCanevasBackground").animate({
          opacity: 0
        },
        {
          duration: 100,
          easing: "easeOutExpo",
          complete: function () {
            jQuery(".loadingCanevas, .loadingCanevasBackground").remove();
            LoadingBar.current = 0;
            LoadingBar.isShown = false;
            LoadingBar.callback();
          }
        });
      }
    });
  },
  set: function (pct) {
    if (LoadingBar.isShown) {
      LoadingBar.current = Math.min(pct, 1);
      var lbw = LoadingBar.width * LoadingBar.current; // Stop and dequeue are necessary to remove other currently running ticks 
      // and animate from where we are to our current final progress width
      jQuery(".loadingProgress").stop().dequeue().animate({
        width: lbw
      },
      {
        duration: 300,
        easing: "easeOutExpo",
        complete: function () {
          if (LoadingBar.current >= 1) LoadingBar.hide();
        }
      });
    }
  },
  increment: function (c) {
    LoadingBar.set(LoadingBar.current + c);
  }
} 

////////////////////////////////////////////////////
// Bottom Elements Content Views
////////////////////////////////////////////////////

var Bottom = {
  elements: jQuery("#bottom"),
  show: function () {
    jQuery("#bottom, #partners").show();
  },
  hide: function () {
    jQuery("#bottom, #partners").hide();
  }
} 

////////////////////////////////////////////////////
// Ajax Bulk Content Loader
////////////////////////////////////////////////////

var AjaxLoader = {
  LastCalled: "",
  BulkLoad: function (suffix, id, callback) {
    callback = callback ? callback : function () {};
    if (id != "" && id != "Default.aspx" && id != false) {
      var url = "/" + suffix + "/" + id + "/Default.aspx";
      var aurl = "/" + suffix + "/" + id + "/Ajax.aspx"
    } else {
      var url = "/" + suffix + "/Default.aspx";
      var aurl = "/" + suffix + "/Ajax.aspx"
    }
    if (AjaxLoader.LastCalled != url) {
      AjaxLoader.LastCalled = url;
      jQuery.get(aurl, function (data) { // let the browser handle the DOM manip
        //DescriptionPane.setInfo(data);
        var dummycontainer = document.createElement('div');
        dummycontainer.innerHTML = data;
        var domcontent = jQuery('.descriptionPane', dummycontainer).children().get();
        var texte = jQuery('.descriptionPane .desc-title h2', dummycontainer).html(); //jQuery('.descriptionPane').empty().append(content);
        if (texte == null || texte == "") texte = jQuery('head title', dummycontainer).text();
        DescriptionPane.setDOMInfo(domcontent);
        Page.addArrowLabels(); //var texte = jQuery(".desc-title h2", data).text();
        if (texte != "" && texte != null) {
          NavBar.addElement(texte, url);
        }
        Browser.setTitle(texte);
        callback();
      });
    } else callback();
  },
  BulkListLoad: function (suffix, callback) {
    callback = callback ? callback : function () {};
    AjaxLoader.LastCalled = "/" + suffix + "/Default.aspx";
    if (AjaxLoader.LastCalled != "/" + suffix + "Default.aspx") {
      jQuery.get("/Gateway/XML/service.asmx/" + suffix, function (data) {
        if (jQuery(".descriptionPane", data).html() != "") {
          eval("var content = DescriptionPane.create" + suffix + "List(data);");
          DescriptionPane.setInfo(content);
          DescriptionPane.setListEventHandlers();
        }
        callback();
      });
    }
  },
  SuggestionLoader: function (callback) {
    callback = callback ? callback : function () {};
    var url = "/Gateway/XML/service.asmx/Suggestions";
    var list = jQuery(".search-datalist").eq(0);
    list.html(""); // if(AjaxLoader.LastCalled != url){
    //  AjaxLoader.LastCalled = url;
    jQuery.get(url, function (data) {
      var lines = jQuery("Suggestion", data);
      var word;
      lines.each(function (i) {
        word = jQuery("Name", this).text();
        list.append("<a href='#' style='opacity:0; filter:alpha(opacity=0);' onclick='Suggest.hide(); pageTracker._trackEvent(\"Suggestion\", \"Event\", \"Search=" + word + "\"); jQuery(\"#search-field\").val(\"" + word + "\"); Main.Search(\"" + word + "\", true); return false'>" + word + "</a>");
      });
      Suggest.show();
      callback();
    }); // }
  },
  SearchLoad: function (word, callback) {
    callback = callback ? callback : function () {};
    var url = "/Recherche/" + word + "/Default.aspx";
    if (AjaxLoader.LastCalled != url) {
      AjaxLoader.LastCalled = url;
      NavBar.addElement("Recherche : " + word, url);
      Browser.setTitle("Recherche : " + word);
      jQuery.post("/Gateway/XML/service.asmx/Search", {
        word: word
      },
      function (data) {
        if (jQuery("Result", data).length > 0) {
          var content = DescriptionPane.createSearchList(word, data);
          DescriptionPane.setInfo(content);
          DescriptionPane.setListEventHandlers();
        }
        callback();
      });
    }
  },
  ThemeLoad: function (id, callback) {
    callback = callback ? callback : function () {};
    var url = "/Episodes/" + id + "/Default.aspx";
    if (AjaxLoader.LastCalled != url) {
      AjaxLoader.LastCalled = url;
      jQuery.post("/Gateway/XML/service.asmx/GetThemeElements", {
        id: id
      },
      function (data) {
        if (jQuery("Film, Artist", data).length > 0) {
          var content = DescriptionPane.createThemeList(id, data);
          DescriptionPane.setInfo(content);
          DescriptionPane.setListEventHandlers();
        }
        callback();
      });
    }
  },
  QueteLoad: function (id, callback) {
    var aurl = "/Quete/" + id + "/Ajax.aspx"
    jQuery.get(aurl, function (data) {
      var content = jQuery(".descriptionPane", data).html();
      callback(content);
    });
  },
  LexiconEntryLoad: function (id, callback) {
    var aurl = "/Gateway/XML/service.asmx/LexiconEntry"
    jQuery.get(aurl, {
      id: id
    },
    callback);
  },
  setAjaxLinks: function (element) {
    jQuery("a", element).click(function () {
      var el = jQuery(this).attr("href").split("/");
      var suffix, fiche, clip;
      if (el[1] == "" && el.length > 2)
      {
        el.shift();
        el.shift();
      }
      suffix = el[1];
      fiche = el[2];
      if (el[3] == "Clips" && el[4] > 0)
      {
        clip = el[4];
        Main.Load(suffix, fiche, clip);
      }
      else
      {
        Main.Load(suffix, fiche);
      }
      //if (el[1] == "") Main.Load(el[3], el[4]);
      //else Main.Load(el[1], el[2]);
      return false;
    });
  }
} 

////////////////////////////////////////////////////
// Filter
////////////////////////////////////////////////////

var Filter = {
  current: false,
  isActive: true,
  setIsActive: function (val) {
    if (val) {
      /*
					jQuery("#filter_film, #filter_artisan").mouseover(function(){ jQuery(this).addClass("over"); })
										.mouseout(function(){
											if((jQuery(this).is("#filter_film") && Filter.current != "films") || (jQuery(this).is("#filter_artisan") && Filter.current != "artists"))
												jQuery(this).removeClass("over"); 
										});
										*/
      jQuery(".search-filter").css("opacity", 1); //.css("background", "transparent url(/Portals/_default/Skins/CinemaQuebecois/images/bg_filter_top.jpg) repeat scroll 0 0");
    } else {
      jQuery("#filter_film, #filter_artisan").unbind("mouseover").unbind("mouseout");
      jQuery(".search-filter").css("opacity", 0.3).css("background", "#eeeeee");
    }
  },
  init: function () {
    Filter.setIsActive(true);
    jQuery("#filter_film, #filter_artisan").click(function () {
      jQuery(".descriptionPane").height("auto");
      if (Filter.isActive) {
        if (jQuery(this).is("#filter_film")) Filter.films();
        else Filter.artists();
      }
      return false;
    });
  },
  artists: function () {
    jQuery(".descriptionPane").height("auto");
    if (Filter.current == "artists") {
      Filter.remove();
      pageTracker._trackEvent("Filter", "Button", "None");
    } else {
      jQuery(".descriptionPane tr.Films").hide();
      jQuery(".descriptionPane tr.Artists").show();
      jQuery("#filter_artisan, .filter_artisan").addClass("selected");
      jQuery("#filter_film, .filter_film").removeClass("selected");
      JSFL.filter("artists");
      Filter.current = "artists";
      pageTracker._trackEvent("Filter", "Button", "Artists");
    }
  },
  films: function () {
    jQuery(".descriptionPane").height("auto");
    if (Filter.current == "films") {
      Filter.remove();
      pageTracker._trackEvent("Filter", "Button", "None");
    } else {
      jQuery(".descriptionPane tr.Artists").hide();
      jQuery(".descriptionPane tr.Films").show();
      jQuery("#filter_film, .filter_film").addClass("selected");
      jQuery("#filter_artisan, .filter_artisan").removeClass("selected");
      JSFL.filter("films");
      Filter.current = "films";
      pageTracker._trackEvent("Filter", "Button", "Films");
    }
  },
  remove: function () {
    JSFL.filter("");
    Filter.clear();
    jQuery(".descriptionPane tr").show();
  },
  clear: function () {
    Filter.current = false;
    jQuery(".filter_film, .filter_artisan, #filter_film, #filter_artisan").removeClass("selected");
  }
} 

////////////////////////////////////////////////////
// QuestController
////////////////////////////////////////////////////

var Quete = {
  current: 0,
  isOpen: false,
  isShowAll: true,
  getProperCoords: function () {
    var q_window = jQuery(".quete-window");
    var body = jQuery("#body");
    var left = Math.floor((body.width() - q_window.width()) / 2);
    var top = 0;
    return [left, top];
  },
  init: function () {
    jQuery("#quete-window-wrapper").append("<div class='quete-window'></div>");
    var controls = "<div class='head'>";
    controls += "<h3>La Qu&ecirc;te</h3><span class='quete-number'></span><span class='quete-name'></span>";
    controls += "<a class='close' href='#' onclick='Quete.quit(); return false;'>Fermer</a>";
    controls += "<a class='minimize' href='#' onclick='Quete.minimize(); return false;'>R&eacute;duire</a>";
    controls += "</div>";
    controls += "<div class='intro'></div>";
    controls += "<div class='content'></div>";
    controls += "<div class='information-form'></div>";
    controls += "<div class='content-selector'></div>";
    controls += "<div class='quete-controls'></div>";
    jQuery(".quete-window").css("position", "absolute").css("height", "100%").css("width", "100%").append(controls);
    var form = "<div class='form'>";
    form += "<form>";
    form += "<fieldset><label>Nom : </label><input type='text' name='FirstName' /></fieldset>";
    form += "<fieldset><label>Pr&eacute;nom : </label><input type='text' name='LastName' /></fieldset>";
    form += "<fieldset><label>Adresse : </label><input type='text' name='Address' /></fieldset>";
    form += "<fieldset><label>Ville : </label><input type='text' name='City' /></fieldset>";
    form += "<fieldset><label>T&eacute;l&eacute;phone : </label><input type='text' name='Telephone' /></fieldset>";
    form += "<fieldset><label>Courriel : </label><input type='text' name='Email' /></fieldset>";
    form += "</form>";
    form += "<div class='clear'></div>";
    form += "</div>";
    form += "<div class='form-explain'>";
    form += "<p>Envoyez vos r&eacute;ponses avec vos coordonn&eacute;es et courrez la chance de gagner une paire de billet pour les Cin&eacute;ma Famous Players!</p>"
    form += "</div>";
    jQuery(".quete-window .information-form").css("display", "none").append(form);
    jQuery(".quete-window .information-form input").onfill(Quete.setSubmitFormButton).onunfill(Quete.setSubmitFormButton);
  },
  start: function () {
    var hidEpisode = jQuery(".quete-window .content input.queteEpisodeId");
    if (hidEpisode.length == 0) {
      Quete.overwrite();
    } else if (hidEpisode.val() == Main.currentEpisode) {
      Quete.open();
    } else {
      Popup.prompt("Vous avez d&eacute;j&agrave; une qu&ecirc;te en cours. En d&eacute;butant cette qu&ecirc;te vous allez effacer vos r&eacute;ponses. Voulez-vous d&eacute;buter cette nouvelle qu&ecirc;te ?", function (result) {
        if (result) Quete.overwrite();
      });
    }
  },
  overwrite: function () {
    LoadingBar.show("html", function () {});
    AjaxLoader.QueteLoad(Main.currentEpisode, function (content) {
      LoadingBar.increment(0.8);
      var pos = jQuery("#theme" + Main.currentEpisode + " .theme-number").text();
      var name = jQuery("#theme" + Main.currentEpisode + " .theme-name").text();
      jQuery(".quete-window .quete-name").html(name);
      jQuery(".quete-window .quete-number").html(pos);
      jQuery(".quete-window .content").html(content);
      var hidIsClosed = jQuery(".quete-window .content input.queteIsClosed");
      Quete.showIntro(hidIsClosed.val() == 'True');
      jQuery("#quete-window-wrapper").css("display", "block");
      jQuery(".quete-window").height("auto").width(686);
      var coords = Quete.getProperCoords();
      jQuery(".quete-window").css({
        'left': coords[0],
        'top': coords[1]
      });
      LoadingBar.increment(0.2);
      jQuery(".content-selector").html('');
      Quete.open(function () {
        Quete.setButton(Main.currentEpisode, pos, name);
        jQuery(".quete-window tr input").focus(function () {
          Quete.current = parseInt(jQuery(".quete-window tr input").index(this));
        }).onfill(Quete.setSubmitButton).onunfill(Quete.setSubmitButton).each(function (i) {
          var num = (i > 8) ? i + 1 : "0" + (i + 1);
          jQuery(".content-selector").append("<span id='quete-question" + i + "'>" + num + "</span>&nbsp;");
          jQuery("#quete-question" + i).click(function () {
            Quete.show(i);
            jQuery(".content-selector span").each(function (index, elt) {
              jQuery(elt).removeClass('selected');
            });
            jQuery(this).addClass('selected');
          });
          jQuery("#quete-question" + i).mouseover(function () {
            jQuery(this).addClass('hover');
          });
          jQuery("#quete-question" + i).mouseout(function () {
            jQuery(this).removeClass('hover');
          });
        });
      });
    });
  },
  stop: function () {},
  open: function (callback) {
    jQuery("#quete-window-bg, #quete-window-wrapper").css("height", jQuery(document).height());
    jQuery("#quete-window-bg").show();
    jQuery("#quete-window-wrapper").show().animate({
      opacity: 1
    },
    {
      duration: 300,
      easing: "easeOutSine",
      complete: callback
    });
  },
  close: function (callback) {
    jQuery("#quete-window-bg").hide();
    jQuery("#quete-window-wrapper").animate({
      opacity: 0
    },
    {
      duration: 300,
      easing: "easeOutSine",
      complete: function () {
        jQuery(this).hide();
        callback();
      }
    });
  },
  minimize: function () {
    jQuery("#quete-box-mask").mouseover(function () {
      var elt = jQuery('#quete-info-btn')[0];
      jQuery(elt).addClass('rollhover');
    });
    jQuery("#quete-box-mask").mouseout(function () {
      jQuery('#quete-info-btn').removeClass('rollhover');
    });
    Quete.close(Quete.showButton);
    pageTracker._trackEvent("Quete", "Button", "Minimize");
  },
  maximize: function () {
    Quete.open(Quete.hideButton);
    pageTracker._trackEvent("Quete", "Button", "Maximize");
  },
  showAll: function () {
    jQuery(".quete-single-nav").remove();
    jQuery(".content-selector").hide(); //ne pas voir la liste des numeros de question					
    jQuery(".quete-window tr").show();
    jQuery(".quete-window tr input").eq(Quete.current).focus();
    pageTracker._trackEvent("Quete", "Display", "ShowAll");
    Quete.isShowAll = true;
  },
  showOne: function () {
    Quete.show(Quete.current);
    jQuery(".quete-window .content").append("<div class='quete-single-nav'>" + Quete.singleViewControls() + "</div>");
    jQuery(".content-selector").show();
    Quete.setSelectedNum(Quete.current);
    pageTracker._trackEvent("Quete", "Display", "ShowOne");
    Quete.isShowAll = false;
  },
  setSelectedNum: function (index) {
    var numQuestions = jQuery('.content-selector span');
    for (var i = 0; i < numQuestions.length; i++) {
      var currentQuestion = numQuestions[i];
      jQuery(currentQuestion).removeClass('selected');
      if (i == index) {
        jQuery(currentQuestion).addClass('selected');
      }
    }
    if (jQuery.browser.msie) {
      jQuery(".quete-single-nav").css('border-top', '1px dotted #fff');
    }
    if (!jQuery.browser.msie) {
      if (index == 9) jQuery(".quete-single-nav").css('border-top', '1px dotted #fff');
      else jQuery(".quete-single-nav").css('border', 'none');
    }
  },
  toggleView: function () {
    if (Quete.isShowAll) {
      Quete.showOne();
      jQuery(".quete-controls a.viewone").html("Voir la liste compl&egrave;te");
      jQuery(".quete-controls a.viewone").removeClass('topFleche');
      jQuery(".quete-controls a.viewone").addClass('bottomFleche');
    } else {
      Quete.showAll();
      jQuery(".quete-controls a.viewone").html("Voir une question &agrave; la fois");
      jQuery(".quete-controls a.viewone").removeClass('bottomFleche');
      jQuery(".quete-controls a.viewone").addClass('topFleche');
    }
  },
  show: function (pos) {
    if (pos >= jQuery(".quete-window tr").length) pos = 0;
    else if (pos < 0) pos = jQuery(".quete-window tr").length - 1;
    jQuery(".quete-window tr").hide().eq(pos).show();
    jQuery(".quete-window tr input").eq(pos).focus();
    Quete.current = pos;
    Quete.setSelectedNum(Quete.current);
  },
  setButton: function (id, pos, name) {
    var inside = "<span class='quete-number'>" + pos + "</span>";
    jQuery(".quete-box .quete-info").html(inside);
  },
  showButton: function () {
    jQuery(".quete-box").bind("click", Quete.maximize).animate({
      opacity: 1
    },
    {
      duration: 200
    });
  },
  hideButton: function () {
    jQuery(".quete-box").unbind("click").animate({
      opacity: 0
    },
    {
      duration: 200
    });
    jQuery("#quete-info-btn").removeClass('rollhover');
  },
  showIntro: function (isClosed) {
    var text = "";
    if (isClosed) {
      text += "<h3>Bienvenue dans la Qu&ecirc;te!</h3>";
      text += "<p>Pour prendre part &agrave; cette Qu&ecirc;te, rien de plus simple. R&eacute;pondez ";
      text += "aux 10 questions relatives au th&egrave;me en vedette dans cette Qu&ecirc;te, puis ";
      text += "comparez ensuite vos &eacute;l&eacute;ments de r&eacute;ponses &agrave; la grille de correction afin ";
      text += "de juger de votre performance.</p>";
    } else {
      text += "<h3>Bienvenue au c&oelig;ur de la Qu&ecirc;te de la semaine!</h3>";
      text += "<p>Pour prendre part &agrave; la Qu&ecirc;te, rien de plus simple. R&eacute;pondez aux ";
      text += "10 questions qui font l'objet de la Qu&ecirc;te de cette semaine, puis ";
      text += "soumettez votre formulaire de participation au tirage. Le prix : une ";
      text += "paire de billets pour deux personnes pour le visionnement du film TRUFFE de Kim Nguyen.</p>";
    }
    text += "<p>Vous ignorez la r&eacute;ponse &agrave; une question? R&eacute;duisez la fen&ecirc;tre de votre formulaire ";
    text += "de r&eacute;ponse le temps de partir en qu&ecirc;te des informations n&eacute;cessaires sur le site. ";
    text += "Retournez ensuite &agrave; votre formulaire et inscrivez votre d&eacute;couverte. Notez que lorsque ";
    text += "r&eacute;duite, la fen&ecirc;tre glisse dans la zone situ&eacute;e dans le coin sup&eacute;rieur gauche de votre &eacute;cran.</p>";
    text += "<h4>Bonne chance!</h4>";
    jQuery(".content-selector").hide();
    jQuery(".quete-window .intro").html(text).show();
    jQuery(".quete-window .content").hide();
    jQuery(".quete-window .information-form").hide();
    jQuery(".quete-window .quete-controls").html(Quete.introControls());
  },
  showContent: function (startQuete) {
    jQuery(".quete-window .intro").hide();
    jQuery(".quete-window .content").show();
    jQuery(".quete-window .information-form").hide();
    jQuery(".quete-window .quete-controls").html(Quete.questControls());
    if (!Quete.isShowAll) jQuery(".content-selector").show();
    if ((Quete.isCompleted() || Quete.formIsCompleted()) && !startQuete) {
      jQuery('.quete-window .viewone').css('display', 'none');
    } else {
      jQuery('.quete-window .viewone').css('display', 'block');
      jQuery(".content-selector").hide();
    }
  },
  showSubmitForm: function () {
    pageTracker._trackEvent("Quete", "Action", "ShowSubmitForm");
    jQuery(".content-selector").hide();
    jQuery(".quete-window .intro").hide();
    jQuery(".quete-window .content").hide();
    jQuery(".quete-window .information-form").show();
    jQuery(".quete-window .quete-controls").html(Quete.formControls());
  },
  toogleAnswers: function () {
    if (Quete.answersVisibility) Quete.hideAnswers();
    else Quete.showAnswers();
  },
  showAnswers: function () {
    jQuery('.quete-window tr .answer').css('visibility', 'visible');
    Quete.answersVisibility = true;
    jQuery('.quete-controls a.submit').html('Masquer les r&eacute;ponses');
  },
  hideAnswers: function () {
    jQuery('.quete-window tr .answer').css('visibility', 'hidden');
    Quete.answersVisibility = false;
    jQuery('.quete-controls a.submit').html('Voir les r&eacute;ponses');
  },
  setSubmitButton: function () {
    if (Quete.isCompleted()) {
      jQuery('.quete-window .submit').removeClass('hidden');
      jQuery('.quete-window .viewone').css('display', 'none');
    } else {
      jQuery('.quete-window .submit').addClass('hidden');
      jQuery('.quete-window .viewone').css('display', 'block');
    }
  },
  setSubmitFormButton: function () {
    if (Quete.formIsCompleted()) {
      jQuery('.quete-window .submitForm').removeClass('hidden');
      jQuery('.quete-window .viewone').css('display', 'none');
    } else {
      jQuery('.quete-window .submitForm').addClass('hidden');
      jQuery('.quete-window .viewone').css('display', 'block');
    }
  },
  submit: function () {
    var data = new Object();
    var url = "/Gateway/XML/service.asmx/QueteSubmit";
    data["ModuleID"] = jQuery(".queteModuleId").val();
    data["SubmitData"] = "";
    var results = '';
    jQuery(".quete-window tr input").each(function (i) {
      results += jQuery(this).val() + ";";
    });
    data["SubmitData"] = results.substr(0, results.length - 1);
    jQuery(".quete-window .information-form input").each(function () {
      data[jQuery(this).attr("name")] = jQuery(this).val();
    });
    jQuery.post(url, data, function (data) {
      var result = jQuery("boolean", data).text();
      var message = (result == 'true') ? 'Merci de votre participation !' : 'Message erreur';
      Popup.alert(message, function () {
        Quete.quit(true);
        pageTracker._trackEvent("Quete", "Action", "Submit");
      });
    });
  },
  quit: function (force) {
    var doclose = function () {
      Quete.close(function () {
        jQuery(".quete-window .content").html("");
        Quete.hideButton();
        pageTracker._trackEvent("Quete", "Action", "Quit");
      });
    };
    if (force) doclose();
    else {
      Popup.prompt("Voulez-vous vraiment fermer la Qu&ecirc;te et PERDRE vos r&eacute;ponses?", function (response) {
        if (!response) return;
        doclose();
      });
    }
  },
  isCompleted: function () {
    var canSubmit = true;
    pageTracker._trackEvent("Quete", "Event", "QuestIsCompleted");
    jQuery(".quete-window .content tr input").each(function () {
      if (jQuery(this).val() == "") canSubmit = false;
    });
    return canSubmit;
  },
  formIsCompleted: function () {
    var canSubmit = true;
    pageTracker._trackEvent("Quete", "Event", "UserInfoIsCompleted");
    jQuery(".quete-window .information-form input").each(function () {
      if (jQuery(this).val() == "") canSubmit = false;
    });
    return canSubmit;
  },
  introControls: function () {
    var ret = "<a href='#' class='quit' onclick='Quete.quit(); return false;'>Quitter la qu&ecirc;te</a>";
    ret += "<a href='#' class='startQuete' onclick='pageTracker._trackEvent(\"Quete\", \"Event\", \"Start\");Quete.showContent(true); return false;'><span>&nbsp;</span></a>";
    ret += "<a href='#' class='rules'>R&egrave;glement</a>";
    return ret;
  },
  questControls: function () {
    var canSubmit = Quete.isCompleted() ? '' : ' hidden';
    var isClosed = jQuery(".quete-window .content input.queteIsClosed").val() == "True";
    var submitText = isClosed ? "Voir les r&eacute;ponses" : "Soumettre vos r&eacute;ponses";
    var submitAction = isClosed ? "Quete.toogleAnswers();" : "Quete.showSubmitForm();";
    ret = "<a href='#' class='quit' onclick='Quete.quit(); return false;'>Quitter la qu&ecirc;te</a>";
    ret += "<a href='#' class='goToQuest' onclick='Quete.minimize(); return false;'>Partir en qu&ecirc;te</a>";
    ret += "<a href='#' class='viewone topFleche' onclick='Quete.toggleView(); return false;'>Voir une question &agrave; la fois</a>";
    ret += "<a href='#' class='submit" + canSubmit + "' onclick='" + submitAction + " return false;'>" + submitText + "</a>";
    return ret;
  },
  singleViewControls: function () {
    var ret = "<a href='#' onclick='Quete.show(Quete.current-1); return false;' class='prev'>Pr&eacute;c&eacute;dente</a>";
    ret += "<a href='#' onclick='Quete.show(Quete.current+1); return false;' class='next'>Suivante</a>";
    return ret;
  },
  formControls: function () {
    var canSubmit = Quete.formIsCompleted() ? '' : ' hidden';
    var ret = "<a href='#' class='back' onclick='Quete.showContent(); return false;'>Retour &agrave; la qu&ecirc;te</a>";
    ret += "<a href='#' class='submitForm" + canSubmit + "' onclick='Quete.submit(); return false;'><span>&nbsp;</span></a>";
    return ret;
  }
}; 

////////////////////////////////////////////////////
// Description pane action controller
////////////////////////////////////////////////////

var DescriptionPane = {
  hide: function (callback) {
    Bottom.hide();
    callback = callback ? callback : function () {
      return true;
    };
    jQuery(".descriptionPane").animate({
      opacity: 0,
      marginBottom: 0
    },
    {
      duration: 100,
      easing: "easeOutExpo",
      complete: callback
    }).html("");
  },
  show: function (callback) {
    callback = callback ? callback : function () {
      return true;
    };
    if (jQuery(".descriptionPane").html() != "") {
      jQuery(".descriptionPane").css("height", "auto").css("display", "block");
      jQuery(".descriptionPane").animate({
        opacity: 1,
        marginBottom: 20
      },
      {
        duration: 150,
        easing: "easeOutExpo",
        complete: function () {
          Bottom.show();
          callback();
        }
      });
    } else callback();
  },
  setInfo: function (content) {
    jQuery(".descriptionPane").html(content);
  },
  setDOMInfo: function (dom) {
    jQuery(".descriptionPane").empty().append(dom);
  },
  createSearchList: function (word, data) {
    var imagepath = "/Portals/_default/Skins/CinemaQuebecois/images/";
    var content = "<div id='cqsearch-header' class='cqsearch-headerfooter'>"; // content += "<a class='cqsearch-quit' href='javascript:DescriptionPane.hide()'>Quittez la recherche <img src='" + imagepath + "search-close.png' alt='Quitter' /></a>";
    content += "<span id='cqsearch-title'>La recherche</span>";
    content += "<span id='cqsearch-number'>00</span>";
    content += "<span id='cqsearch-text'>R&eacute;sultats pour: <span id='cqsearch-word'>" + word + "</span></span>";
    content += "</div>";
    content += "<table id='cqsearch-content'>";
    content += "<thead>";
    content += "<tr class='cqsearch-row-header'>";
    content += "<th class='cqsearch-column-icon'>";
    content += "<a href='#' class='filter_film' onclick='Filter.films(); return false;'></a>";
    content += "<a href='#' class='filter_artisan' onclick='Filter.artists(); return false;'></a>";
    content += "</th>";
    content += "<th class='cqsearch-column-film'>Titre</th>";
    content += "</thead>";
    content += "<tbody>";
    jQuery("Result", data).each(function (i) {
      var title = jQuery("Title", this).text();
      var suffix = jQuery("ElementType", this).text();
      var id = jQuery("ID", this).text();
      var iconcell;
      var rowclass = "cqsearch-row-" + ((i % 2 == 0) ? 'main' : 'alternate');
      title = "<a href=\"/" + Browser.translateSuffix(suffix) + "/" + id + "/Default.aspx\" onclick=\"Main.Load('" + suffix + "','" + id + "'); return false;\">" + title + "</a>"
      var subtexts = new Array();
      if (suffix == 'Films') {
        iconcell = "<img src='" + imagepath + "film_icone.gif' alt='SuffixIcone' />";
        subtexts[0] = jQuery("Year", this).text();
        subtexts[1] = jQuery("SubTitle", this).text();
        subtexts[2] = jQuery("Text", this).text();
      } else if (suffix == 'Artists') {
        iconcell = "<img src='" + imagepath + "entrevue_icone.gif' alt='SuffixIcone' />";
        subtexts[0] = jQuery("Year", this).text();
        subtexts[1] = jQuery("SubTitle", this).text();
      }
      content += "<tr class='" + rowclass + " " + suffix + "'>";
      content += "<td class='cqsearch-column-icon'>" + iconcell + "</td>";
      content += "<td class='cqsearch-column-film'><h4>" + title + "</h4><span>" + subtexts.join("</span><span>") + "</span></td>";
      content += "</tr>";
    });
    content += "</tbody>";
    content += "<tfoot>";
    content += "</tfoot>";
    content += "</table>";
    content += "<div id='cqsearch-footer' class='cqsearch-headerfooter'>&nbsp;";
    content += "</div>";
    return content;
  },
  createThemeList: function (id, data) {
    var imagepath = "/Portals/_default/Skins/CinemaQuebecois/images/";
    var themeName = jQuery("#theme" + id + " .theme-name").text();
    var themeNum = jQuery("#theme" + id + " .theme-number").text();
    var content;
    ThemeMenu.select(id);
    content = "<div id='cqsearch-header' class='cqsearch-headerfooter'>"; // content += "<a class='cqsearch-quit' href='javascript:DescriptionPane.hide()'>Quittez la recherche <img src='" + imagepath + "search-close.png' alt='Quitter' /></a>";
    content += "<span id='cqsearch-title'>" + themeName + "</span>";
    content += "<span id='cqsearch-number'>" + themeNum + "</span>"; // content += "<span id='cqsearch-text'>R&eacute;sultats pour: <span id='cqsearch-word'>" + word + "</span></span>";
    content += "</div>";
    content += "<table id='cqsearch-content'>";
    content += "<thead>";
    content += "<tr class='cqsearch-row-header'>";
    content += "<th class='cqsearch-column-icon'>";
    content += "<a href='#' class='filter_film' onclick='Filter.films(); return false;'></a>";
    content += "<a href='#' class='filter_artisan' onclick='Filter.artists(); return false;'></a>";
    content += "</th>";
    content += "<th class='cqsearch-column-film'>Titre</th>";
    content += "</thead>";
    content += "<tbody>";
    jQuery("Film, Artist", data).each(function (i) {
      var id = jQuery("ID", this).text();
      var title = jQuery("Name", this).text();
      var rowclass = "cqsearch-row-" + ((i % 2 == 0) ? 'main' : 'alternate');
      var subtexts = new Array();
      var suffix, iconcell;
      if (jQuery(this).is("Film")) {
        suffix = "Films";
        iconcell = "<img src='" + imagepath + "film_icone.gif' alt='SuffixIcone' />";
        subtexts[0] = jQuery("DateSortie", this).text();
        subtexts[1] = jQuery("Realisateur", this).text();
        subtexts[2] = jQuery("Genre", this).text();;
      } else if (jQuery(this).is("Artist")) {
        suffix = "Artisans";
        iconcell = "<img src='" + imagepath + "entrevue_icone.gif' alt='SuffixIcone' />";
        subtexts[0] = jQuery("Annee", this).text();;
        subtexts[1] = jQuery("Metiers", this).text();;
      }
      title = "<a href=\"/" + Browser.translateSuffix(suffix) + "/" + id + "/Default.aspx\" onclick=\"Main.Load('" + suffix + "','" + id + "'); return false;\">" + title + "</a>";
      content += "<tr class='" + rowclass + " " + suffix + "'>";
      content += "<td class='cqsearch-column-icon'>" + iconcell + "</td>";
      content += "<td class='cqsearch-column-film'><h4>" + title + "</h4><span>" + subtexts.join("</span><span>") + "</span></td>";
      content += "</tr>";
    });
    content += "</tbody>";
    content += "<tfoot>";
    content += "</tfoot>";
    content += "</table>";
    content += "<div id='cqsearch-footer' class='cqsearch-headerfooter'>&nbsp;";
    content += "</div>";
    return content;
  },
  createWorksList: function (data) {
    var imagepath = "/Portals/_default/Skins/CinemaQuebecois/images/";
    var iconcell = "<img src='" + imagepath + "entrevue_icone.gif' alt='SuffixIcone' />";
    var content = "<div id='cqsearch-header-metiers' class='cqsearch-headerfooter'>";
    content += '<img src="/Portals/_default/Skins/CinemaQuebecois/images/metiers_banner.jpg" width="961" height="57" border="0">'; //content += "<span id='cqsearch-title' class='cqsearch-title-metier'>Les M&eacute;tiers</span>";
    //content += "<span id='cqsearch-text'>R&eacute;sultats pour: <span id='cqsearch-word'>Tous les m&eacute;tiers</span></span>";
    content += "</div>";
    content += "<table id='cqsearch-content'>";
    content += "<thead>";
    content += "<tr class='cqsearch-row-header'>";
    content += "<th class='cqsearch-column-icon'>";
    content += "</th>";
    content += "<th class='cqsearch-column-metier-titre'>Titre</th>";
    content += "<th class='cqsearch-column-metier-collaborateurs'>Collaborateur(s) direct(s)</th>";
    content += "</thead>";
    content += "<tbody>";
    jQuery("Work", data).each(function (i) {
      var title = jQuery("Name", this).text();
      var subtext = jQuery("Collaborateurs", this).text().replace(/(<([^>]+)>)/ig, "  ").trim().replace(/([\s]{2,})/g, ", ");
      var id = jQuery("ID", this).text();
      var rowclass = "cqsearch-row-" + ((i % 2 == 0) ? 'main' : 'alternate');
      title = "<a href=\"/Metiers/" + id + "/Default.aspx\" onclick=\"Main.Load('Metiers','" + id + "'); return false;\">" + title + "</a>"
      var subtexts = new Array();
      content += "<tr class='" + rowclass + "'>";
      content += "<td class='cqsearch-column-icon'>" + iconcell + "</td>";
      content += "<td class='cqsearch-column-metier-titre'><h4>" + title + "</h4></td>";
      content += "<td class='cqsearch-column-metier-collaborateurs'><span>" + subtext + "</span></td>";
      content += "</tr>";
    });
    content += "</tbody>";
    content += "<tfoot>";
    content += "</tfoot>";
    content += "</table>";
    content += "<div id='cqsearch-footer' class='cqsearch-headerfooter'>&nbsp;";
    content += "</div>";
    return content;
  },
  createLexiconList: function (data) {
    var imagepath = "/Portals/_default/Skins/CinemaQuebecois/images/";
    var iconcell = "<img src='" + imagepath + "entrevue_icone.gif' alt='SuffixIcone' />";
    var content = "<div id='cqsearch-header' class='cqsearch-headerfooter'>";
    content += "<span id='cqsearch-title' class='cqsearch-title-glossaire'>Glossaire</span>"; //content += "<span id='cqsearch-text'>R&eacute;sultats pour: <span id='cqsearch-word'>Tous les mots du glossaire</span></span>";
    content += "</div>";
    content += "<table id='cqsearch-content'>";
    content += "<thead>";
    content += "<tr class='cqsearch-row-header'>";
    content += "<th class='cqsearch-column-icon'>";
    content += "</th>";
    content += "<th class='cqsearch-column-glossaire-titre'>Titre</th>";
    content += "</thead>";
    content += "<tbody>";
    jQuery("LexiconEntry", data).each(function (i) {
      var title = jQuery("Word", this).text();
      var subtext = "";
      var id = jQuery("ID", this).text();
      var rowclass = "cqsearch-row-" + ((i % 2 == 0) ? 'main' : 'alternate');
      title = "<a href=\"/Glossaire/" + id + "/Default.aspx\" onclick=\"Main.Load('Glossaire','" + id + "'); return false;\">" + title + "</a>"
      var subtexts = new Array();
      content += "<tr class='" + rowclass + "'>";
      content += "<td class='cqsearch-column-icon'>" + iconcell + "</td>";
      content += "<td class='cqsearch-column-glossaire-titre'><h4>" + title + "</h4></td>";
      content += "</tr>";
    });
    content += "</tbody>";
    content += "<tfoot>";
    content += "</tfoot>";
    content += "</table>";
    content += "<div id='cqsearch-footer' class='cqsearch-headerfooter'>&nbsp;";
    content += "</div>";
    return content;
  },
  setListEventHandlers: function () {
    jQuery(".descriptionPane table tr").not(":first").hover(function () {
      this.prevColor = jQuery(this).css("background-color"); // jQuery(this).animate({backgroundColor:"#88CAD8"}, { duration:150,easing:"easeOutSine"});
      jQuery(this).css("background-color", "#81b1c1");
    },
    function () { // jQuery(this).animate({backgroundColor:this.prevColor}, { duration:50, easing:"easeOutExpo"});
      jQuery(this).css("background-color", this.prevColor);
    }).click(function () {
      var url = jQuery("td h4 a", this).eq(0).attr('href');
      Browser.URL(url);
      return false;
    });
  }
} 

//////////////////////////////////////////////////////
// Theme Menu Controllr
//////////////////////////////////////////////////////

var ThemeMenu = {
  themeSelected: false,
  currentSection: 'Webzine', 
  carouselID: null, 
  carouselObject: null, 
  init: function () {
    jQuery('.carousel_item').click(function () {
      ThemePane.showFull = true;
      Main.Episode(jQuery(this).attr("id").substr(5), true);
      jQuery("#search-field").val("Votre recherche");
      return false;
    });
    
		this.carouselID = jQuery('#menuCarousel');
		this.carouselID.carousel({position:0});
		this.carouselObject = this.carouselID.data('carousel');
    this.select(Main.currentEpisode);
  },
  changeSection: function(section) {
    if (section != "Webzine" && section != "Serie") return;
    
    this.currentSection = section;
    jQuery('.theme-menu-tabs').find('.bt-theme-menu').removeClass('active');
    
    if ( section == "Webzine" )
    {
      jQuery('.theme-menu-slider').animate({top: '0'});
      jQuery('.theme-menu-tabs .bt-webzine').addClass('active');
    }
    else if ( section == "Serie" )
    {
      jQuery('.theme-menu-slider').animate({top: '-73px'});
      jQuery('.theme-menu-tabs .bt-serie-tele').addClass('active');
    }
  }, 
  select: function(id) {
    var element = jQuery('#theme'+id);
    if (!element.length) return this.deselect();
    
    //Figure out which section it's in
    var is_serie = element.parents('.theme-list-serie').length;
    var is_webzine = element.parents('.theme-list-webzine').length;
    if (!is_serie && !is_webzine) return;
    
    this.deselect();
    element.addClass('slider_selected');
    
    if (is_serie)
    {
      this.changeSection("Serie");
    }
    else if (is_webzine)
    {
      this.changeSection("Webzine");
      this.carouselObject.setPage(element.data('carouselData').itemPage - 1);
    }
  }, 
  deselect: function() {
    jQuery('.carousel_item').removeClass('slider_selected');
  }, 
  addDatePointer: function (elid) {
    var id = parseInt(elid.substr(5));
    var element = jQuery("#" + elid);
    var arrow = function () {
      var dateid = "date-" + elid;
      if (jQuery("#" + dateid).length == 0) {
        jQuery("body").append("<div class='date-tooltip' id='" + dateid + "'>Disponible le <br /><span class='date'>" + element.date + "</span></div>");
        var t = element.offset().top + 30 - (jQuery("#" + dateid).height() / 2);
        var l = element.offset().left + 73;
        jQuery("#" + dateid).stop().dequeue().css("opacity", 0).css("position", "absolute").css("display", "block").css("top", t).css("left", l).css("z-index", 400).animate({
          opacity: 1
        },
        {
          duration: 500,
          easing: "easeOutExpo"
        });
      }
    }
    element.mouseover(function () {
      element.isOver = true;
      if (typeof(element.date) == "undefined") jQuery.get("/Gateway/XML/service.asmx/Episode", {
        id: id
      },
      function (data) {
        element.date = jQuery("AvailableDate", data).text();
        element.date = element.date.substr(0, element.date.indexOf("-"));
        if (element.isOver) arrow();
      });
      else arrow();
    }).mouseout(function () {
      element.isOver = false;
      jQuery('.date-tooltip').stop().dequeue().remove();
    });
  }
} 

////////////////////////////////////////////////////////
// Mosaic html controller
////////////////////////////////////////////////////////

var Mosaic = {
  hide: function () {
    jQuery("#mosaicwrapper").hide(); // stop().dequeue().animate({height:0, marginBottom:0}, {duration:200, complete:function(){ jQuery("#mosaicwrapper").css("border", "0px none"); }});
  },
  show: function () {
    jQuery("#mosaicwrapper").show(); //.animate({height:310, marginBottom:20}, {duration:200});
    if (jQuery.browser.msie) jQuery("#mosaicwrapper").css("border", "2px dotted #A5B0B5");
    else jQuery("#mosaicwrapper").css("border", "1px dotted #A5B0B5");
  }
} 

////////////////////////////////////////////////////////
// Theme Pane Controller
////////////////////////////////////////////////////////

var ThemePane = {
  showFull: false,
  isOpen: true,
  citations: Array(),
  citationsInterval: false,
  currentCitation: 0,
  citationDuration: 8000,
  init: function () {
    jQuery('.current-theme-left, .current-theme-right').css("opacity", 0);
    ThemePane.hideElements(function () {
      if (location.href.indexOf("#") == -1) {
        var currentep = jQuery(".current-id").val();
        
        ThemePane.showElements(false);
      } else {
        LoadingBar.show('.current-theme');
      }
    });
  },
  close: function (callback) {
    clearInterval(ThemePane.citationsInterval);
    if (ThemePane.isOpen) {
      jQuery('.current-theme').animate({
        opacity: 0
      },
      {
        duration: 100
      });
      jQuery('.current-theme').animate({
        height: 0,
        marginBottom: 0
      },
      {
        duration: 300,
        easing: "easeOutExpo",
        complete: function () {
          jQuery('.current-theme').css("display", "none");
          ThemePane.isOpen = false;
          callback();
        }
      });
    } else callback();
  },
  open: function (callback) {
    callback = callback ? callback : function () {
      return true;
    };
    jQuery('.current-theme').animate({
      opacity: 1
    },
    {
      duration: 100
    });
    jQuery('.current-theme').animate({
      height: 185,
      marginBottom: 20
    },
    {
      duration: 300,
      easing: "easeOutExpo",
      complete: callback
    });
    ThemePane.isOpen = true;
  },
  hide: function (callback) {
    jQuery('.current-theme').css("height", "0px").css("opacity", 0).css("margin-bottom", "0px");
    ThemePane.isOpen = false;
    callback();
  },
  hideElements: function (callback) {
    clearInterval(ThemePane.citationsInterval);
    if (ThemePane.isOpen) {
      jQuery('.current-theme-title').animate({
        opacity: 0
      },
      {
        duration: 100,
        easing: "easeOutExpo"
      });
      
      jQuery(".current-theme-right").animate({
        opacity: 0
      },
      {
        duration: 100,
        complete: callback
      });
      jQuery(".current-theme-left").css("opacity", 0);
    } else callback();
  },
  showElements: function (callback) {
  
    if (ThemePane.isOpen) {
      jQuery('.current-theme-left, .current-theme-right').css("opacity", 1); 
      
      jQuery('.current-theme-title').animate({
        opacity: 1
      },
      {
        duration: 100,
        easing: "easeOutSine"
      });
      
      jQuery(".current-theme-right").animate({
        opacity: 1
      },
      {
        duration: 200,
        complete: callback
      });
    } else {
      ThemePane.open(function () {
        ThemePane.showElements(callback);
      });
    }
  },
  setInfo: function (id, pos, callback) {
    AjaxLoader.LastCalled = "";
    if (ThemePane.isOpen) LoadingBar.show(".current-theme", callback);
    pos = (pos <= 9) ? "0" + pos : pos;
    ThemePane.citations = new Array();
    jQuery.post('/Gateway/XML/service.asmx/Episode', {
      id: id
    },
    function (data) {
      LoadingBar.increment(0.5);
      var title = jQuery('Name', data).text();
      var isWebzine = (jQuery('Section', data).text() == "Webzine"); 
      jQuery('.current-theme-title').text(title);
      jQuery('.current-theme-excerpt').html(jQuery('Extrait', data).text());
      jQuery('.current-theme-trailer-img').attr("src", "/Documents/Thumbs/Episodes/379-" + jQuery('ID', data).text() + "-hub.jpg");
      Browser.setTitle(title);
      if (isWebzine) {
        jQuery('.current-theme-webzine-block').show();
        jQuery('.current-theme-episode-block').hide();
        var action_split = jQuery('Action', data).text().split(':');
        var href = "#";
        if (action_split.length == 2 && action_split[0] == "page")
        {
          href = action_split[1];
        }
        jQuery('.current-theme-trailer a').html("D&eacute;couvrir").attr("href", href);
        LoadingBar.increment(0.5);
      } else {
        jQuery('.current-theme-webzine-block').hide();
        jQuery('.current-theme-episode-block').show();
        jQuery('.current-theme-quete .theme-title').text(jQuery('Name', data).text());
        jQuery('.current-theme-quete .theme-title').prepend("<span class='quete-number'>" + pos + "</span>&nbsp;");
        jQuery('.current-theme-trailer a').html("&Agrave; propos de l'&eacute;mission").attr("href", "/a-propos-emission/" + jQuery('ID', data).text() + "/Default.aspx");
        jQuery.post('/Gateway/XML/service.asmx/TribuneInfo', {
          id: id
        },
        function (data2) {
          LoadingBar.increment(0.5);
          ThemePane.setTribune(id, data2);
          ThemePane.setQuete(id);
        });
      }
      if (!ThemePane.isOpen) callback();
    });
  },
  setCitation: function (callback) {
    var pos = ThemePane.currentCitation >= ThemePane.citations.length ? 0 : ThemePane.currentCitation++;
    ThemePane.currentCitation = ThemePane.currentCitation >= ThemePane.citations.length ? 0 : ThemePane.currentCitation;
  },
  setCitationArray: function (citations) {
    if (citations.indexOf(";") >= 0) {
      var tmp1 = citations.split(";");
      jQuery.each(tmp1, function (i, val) {
        if (val.indexOf(":") >= 0) {
          var tmp2 = this.split(":");
          ThemePane.citations[i] = {
            CitationHTML: tmp2[0],
            AuteurHTML: "&nbsp;" + tmp2[1]
          };
        }
      });
    }
  },
  setTribune: function (id, data) {
    var trib = jQuery('Tribune', data);
    var ClipRefs = jQuery('SampleAnswer ClipRef', trib);
    var Artists = jQuery('SampleAnswer Artist', trib);
    var Quotes = jQuery('SampleAnswer Quotes', trib);
    jQuery('#cq-tribune-title span').text(jQuery('Title', trib).text());
    jQuery(".repondez").attr("href", "/Sondage/" + id + "/Default.aspx");
    jQuery('.cq-tribune-thumb img').each(function (i) {
      var ClipRefDetails = ClipRefs.eq(i).text().split(";");
      var clipid = ClipRefDetails[0];
      this.src = '/Documents/Thumbs/Clips/379-' + clipid + '-trib.jpg';
      this.alt = Artists.eq(i).text();
    });
  },
  setQuete: function (id, data) {
    jQuery(".startquete").attr("href", "/Quete/" + id + "/Default.aspx");
  },
  setId: function (id, pos) {
    pos = (pos <= 9) ? "0" + pos : pos; //jQuery('.current-theme-number').text(pos);
  }
} 

////////////////////////////////////////////////////////
// Bottom Elements Controller
////////////////////////////////////////////////////////

var BottomElements = {
  hide: function (callback) {
    jQuery("#bottom, #dnnmenu_bottom, .loginbuttons, .skingradient").animate({
      opacity: 0
    },
    {
      duration: 100,
      complete: callback
    });
  },
  show: function (callback) {
    jQuery("#bottom, #dnnmenu_bottom, .loginbuttons, .skingradient").animate({
      opacity: 1
    },
    {
      duration: 100,
      complete: callback
    });
  }
} 

////////////////////////////////////////////////////////
// SearchList Controller (for suggestion and ideas)
////////////////////////////////////////////////////////

var Suggest = {
  datalist: false,
  timeout: false,
  isOn: false,
  init: function () {
    Suggest.datalist = jQuery('.search-datalist').eq(0);
    jQuery('.search-datalist').height(0);
    Suggest.datalist.mouseout(function (e) {
      Suggest.timeout = setTimeout("Suggest.hide();", 1000);
    }).mouseover(function (e) {
      clearTimeout(Suggest.timeout);
    });
    jQuery("#une-idee").mouseout(function (e) {
      Suggest.timeout = setTimeout("Suggest.hide();", 1000);
    }).mouseover(function (e) {
      clearTimeout(Suggest.timeout);
    });
  },
  ask: function () {
    Main.Suggestion();
    pageTracker._trackEvent("Suggestion", "Button", "Click");
    clearTimeout(Suggest.timeout);
  },
  show: function () {
    Suggest.hideLabel();
    this.isOn = true;
    this.datalist.css("border-left", "#002a42 solid 1px").css("border-right", "#002a42 solid 1px").css("border-top", "#002a42 solid 1px");
    jQuery("a", this.datalist).each(function (i, val) {
      jQuery(this).css("display", "block");
      jQuery(this).animate({
        opacity: 1
      },
      {
        duration: (200 * (i + 1)),
        easing: "easeOutSine"
      });
    });
    this.datalist.animate({
      height: (20 * jQuery("a", this.datalist).length)
    },
    {
      duration: 500,
      easing: "easeOutElastic"
    });
  },
  hide: function () {
    clearTimeout(Suggest.timeout);
    this.isOn = false;
    this.datalist.animate({
      height: 0
    },
    {
      duration: 500,
      easing: "easeOutSine"
    });
    var adl = jQuery("a", this.datalist);
    jQuery("a", this.datalist).each(function (i, val) {
      var cnt = (200 * (adl.length - (i + 1)));
      jQuery(this).animate({
        opacity: 0
      },
      {
        duration: cnt,
        easing: "easeOutSine",
        complete: function () {
          jQuery(this).css("display", "none");
        }
      });
    });
  },
  showLabel: function () {
    if (!Suggest.isOn) {
      jQuery("#idee-label").remove();
      if (jQuery("#idee-label").length == 0) jQuery(".search-box").prepend("<div id='idee-label'><span>Une id&eacute;e de recherche?</span></div>");
      jQuery("#idee-label span").css("display", "block").css("font-size", 11).css("color", "#071F29").css("margin", "2px 2px 2px 5px").width(122);
      jQuery("#idee-label").css("background", "#ffffff").css("position", "absolute").css("overflow", "hidden").css("top", 5).css("left", 0).width(122).animate({
        left: -125
      },
      {
        duration: 300,
        easing: "easeOutExpo"
      });
    }
  },
  hideLabel: function () {
    jQuery("#idee-label").stop().dequeue().animate({
      left: 0
    },
    {
      duration: 300,
      easing: "easeInExpo"
    });
  }
} 

////////////////////////////////////////////////////////
// Navbar Controller
////////////////////////////////////////////////////////

var NavBar = {
  isOpen: false,
  addElement: function (text, link) {
    var add = true;
    jQuery("#navbar .visited a:contains(" + text + ")").each(function () {
      if (jQuery(this).text() == text) add = false;
    });
    if (add) {
      var id = "visited-" + jQuery("#navbar .visited a").length; // make sure everything is in french
      var el = link.split("/");
      jQuery.each(el, function (i, e) {
        el[i] = Browser.reverseTranslateSuffix(e);
      });
      link = el.join("/");
      var gt = ""
      if (jQuery("#navbar .visited a").length != 0) jQuery("#navbar .visited a:first").prepend(" &gt; ");
      jQuery("#navbar .visited").prepend("<a href='#" + link + "' id='" + id + "'><span>" + text + "</span></a>");
      if (!NavBar.isOpen) NavBar.open();
    }
  },
  open: function (callback) {
    NavBar.isOpen = true;
    if (!ThemeMenu.themeSelected) {
      jQuery(".theme-menu-wrapper").animate({
        height: 64
      },
      {
        duration: 100
      });
    }
    jQuery("#navbar").css("opacity", 1).stop().dequeue().animate({
      height: 20,
      paddingTop: 10
    },
    {
      duration: 200,
      easing: "easeInSine",
      complete: callback
    });
  },
  close: function (callback) {
    NavBar.isOpen = false;
    jQuery("#navbar").stop().dequeue().animate({
      opacity: 0,
      height: 7,
      paddingTop: 0
    },
    {
      duration: 200,
      easing: "easeInSine",
      complete: callback
    });
  }
} 

////////////////////////////////////////////////////////
// Browser Controller
////////////////////////////////////////////////////////

var Browser = {
  startURL: "",
  isLoading: false,
  currentURL: "/",
  translateSuffix: function (suffix) {
    switch (suffix) {
    case "Metiers":
      return "Works";
      break;
    case "Glossaire":
      return "Lexicon";
      break;
    case "Artisans":
      return "Artists";
      break;
    default:
      return suffix;
    }
  },
  reverseTranslateSuffix: function (suffix) {
    switch (suffix) {
    case "Works":
      return "Metiers";
      break;
    case "Lexicon":
      return "Glossaire";
      break;
    case "Artists":
      return "Artisans";
      break;
    default:
      return suffix;
    }
  },
  URL: function (url, fl) {
    fl = typeof(fl) == "undefined" ? true : fl;
    JSFL.callFlash = fl;
    if (typeof(url) == "undefined") url == "";
    else if (url.indexOf("http://") != -1) url = url.substr(url.indexOf("/", 8));
    if (jQuery(".mosaic").length > 0) jQuery("#navigator").attr("src", "Navigator.aspx?URL=" + url);
    else location.href = "/#" + url
  },
  setTitle: function (titre) {
    var ea = String.fromCharCode(233);
    document.title = "T" + ea + "l" + ea + "-Qu" + ea + "bec / Cin" + ea + "ma Qu" + ea + "b" + ea + "cois / " + titre;
  },
  updateContent: function () {
    var el1 = Browser.currentURL.split("/");
    var el2 = location.href.split("/");
    if ((el1[4] != el2[4] || el1[5] != el2[5]) && !Browser.isLoading) {
      Browser.currentURL = location.href;
      Filter.clear();
      Main.Wait();
      Browser.loadFromURL();
    }
  },
  callAnalytics: function () {
    pageTracker._trackPageview(Browser.currentURL.substr(Browser.currentURL.indexOf("#") + 1));
  },
  loadFromURL: function () {
    if (!Browser.isLoading && Main.initiated) {
      Browser.isLoading = true;
      clearTimeout(Page.arrowTimeout);
      jQuery("#arrow").stop().dequeue().remove();
      if (Browser.currentURL.indexOf("#") != -1 && Browser.currentURL.substring(Browser.currentURL.indexOf("#")).length > 1) {
        var url = Browser.currentURL.substr(Browser.currentURL.indexOf("#") + 1);
        var el = url.split("/");
      } else {
        var el = new Array();
        el[0] = "";
        el[1] = "Episodes";
        el[2] = Main.thisWeekEpisode;
        ThemePane.showFull = true;
        jQuery("#search-field").val("Votre recherche");
      }
      el[1] = Browser.translateSuffix(el[1]);
      switch (el[1]) {
      case "Recherche":
        historyFunction = function () {
          Main.currentEpisode = -1;
          ThemePane.close(function () {
            ThemeMenu.deselect();
            DescriptionPane.hide(function () {
              Mosaic.show();
              var word = decodeURIComponent(el[2]).trim();
              AjaxLoader.SearchLoad(word, function () {
                jQuery("#search-field").val(word);
                JSFL.search(word);
                JSFL.callFlash = true;
                DescriptionPane.show();
                Filter.setIsActive(true);
                Browser.isLoading = false;
                Main.firstLoad = false;
                ThemePane.showFull = true;
                Browser.callAnalytics();
              });
            });
          });
          return false;
        }
        break;
      case "Episodes":
        historyFunction = function () {
          Mosaic.show();
          DescriptionPane.hide(function () {
            if (ThemePane.showFull) {
              NavBar.close();
              var pos = parseInt(jQuery("#theme" + el[2] + " .theme-number").text(), 10);
              if (isNaN(pos)) pos = -1;
              ThemeMenu.select(el[2]);
              ThemePane.hideElements(function () {
                ThemePane.setId(el[2], pos);
                ThemePane.setInfo(el[2], pos, function () {
                  JSFL.theme(el[2]);
                  Filter.setIsActive(true);
                  Browser.callAnalytics();
                  ThemePane.showElements(function () {});
                  Main.currentEpisode = el[2];
                  Browser.isLoading = false;
                  ThemePane.showFull = false;
                  Main.firstLoad = false;
                  Bottom.show();
                });
              });
            } else { // if(!Main.firstLoad)
              AjaxLoader.ThemeLoad(el[2], function () {
                DescriptionPane.show(function () {
                  Browser.callAnalytics();
                  JSFL.theme(el[2]);
                  Browser.isLoading = false;
                  Main.firstLoad = false;
                  Filter.setIsActive(true);
                  ThemePane.showFull = false;
                });
              });
            }
          });
          return false;
        }
        break;
      case "Quiz":
        historyFunction = function () {
          NavBar.close();
          Filter.setIsActive(false);
          ThemePane.close(function () {
            ThemeMenu.deselect();
            DescriptionPane.hide(function () {
              AjaxLoader.BulkLoad(el[1], "", function () {
                Mosaic.show();
                CQQuiz.initializePage(380, function () { // ID FOR OUR QUIZ, set static
                  DescriptionPane.show(function () {
                    Browser.callAnalytics();
                    Browser.isLoading = false;
                    Filter.setIsActive(false);
                    Main.firstLoad = false;
                    ThemePane.showFull = true;
                  });
                });
              });
            });
          });
          return false;
        }
        break;
      case "Sondage":
        historyFunction = function () {
          NavBar.close();
          Filter.setIsActive(false);
          ThemePane.close(function () {
            DescriptionPane.hide(function () {
              AjaxLoader.BulkLoad(el[1], el[2], function () {
                Sondage.init();
                Mosaic.show();
                DescriptionPane.show(function () {
                  JSFL.load("Tribune", el[2]);
                  Browser.callAnalytics();
                  Browser.isLoading = false;
                  Main.firstLoad = false;
                  ThemePane.showFull = true;
                  Filter.setIsActive(false);
                });
              });
            });
          });
          return false;
        }
        break;
      case "credits":
      case "contactez-nous":
        //Fall through to a-propos, same procedure
      case "a-propos":
        historyFunction = function () {
          ThemePane.close(function () {
            NavBar.close();
            Mosaic.hide();
            DescriptionPane.hide(function () {
              ThemeMenu.deselect();
              AjaxLoader.BulkLoad(el[1], "", function () {
                DescriptionPane.show(function () {
                  Browser.callAnalytics();
                  Browser.isLoading = false;
                  Main.firstLoad = false;
                  Filter.setIsActive(false);
                  ThemePane.showFull = false;
                });
              });
            });
          });
          return false;
        }
        break;
      case "jutra":
        historyFunction = function () {
          ThemePane.close(function () {
            NavBar.close();
            DescriptionPane.hide(function () {
              ThemeMenu.deselect();
              AjaxLoader.BulkLoad(el[1], "", function () {
                Mosaic.show();
                DescriptionPane.show(function () {
                  JSFL.playVideo('/Documents/Clips/Episodes/379-16.flv', "", "");
                  Browser.callAnalytics();
                  Browser.isLoading = false;
                  Main.firstLoad = false;
                  Filter.setIsActive(false);
                  ThemePane.showFull = false;
                });
              });
            });
          });
          return false;
        }
        break;
      case "a-propos-emission":
        historyFunction = function () {
          ThemePane.close(function () {
            ThemeMenu.deselect();
            DescriptionPane.hide(function () {
              AjaxLoader.BulkLoad(el[1], el[2], function () {
                Mosaic.show();
                DescriptionPane.show(function () {
                  JSFL.load("episode", el[2]);
                  Browser.callAnalytics();
                  Browser.isLoading = false;
                  Main.firstLoad = false;
                  Filter.setIsActive(false);
                  ThemePane.showFull = true;
                });
              });
            });
          });
          return false;
        }
        break;
      case "page":
        historyFunction = function () {
          Filter.setIsActive(false); // JSFL.clearMosaic();
          ThemePane.close(function () {
            ThemeMenu.deselect();
            NavBar.open();
            DescriptionPane.hide(function () {
              AjaxLoader.BulkLoad(el[1], el[2], function () {
                AjaxLoader.setAjaxLinks(".descriptionPane");
                var hidden = jQuery('.descriptionPane input.mosaic_theme');
                if (hidden.length > 0)
                {
                  JSFL.theme(hidden.val());
                  Mosaic.show();
                }
                DescriptionPane.show(function () {
                  Browser.isLoading = false;
                  Main.firstLoad = false;
                  Filter.setIsActive(false);
                  ThemePane.showFull = false;
                });
                Browser.callAnalytics();
              });
            });
          });
          return false;
        }
        break;
      default:
        historyFunction = function () {
          Filter.setIsActive(false); // JSFL.clearMosaic();
          ThemePane.close(function () {
            ThemeMenu.deselect();
            NavBar.open();
            DescriptionPane.hide(function () {
              if (el[2] != "Default.aspx" || el[1] == "Lexicon") AjaxLoader.BulkLoad(el[1], el[2], function () {
                AjaxLoader.setAjaxLinks(".descriptionPane");
                Mosaic.show();
                if (el[3] == "Default.aspx") {
                  JSFL.load(el[1], el[2]);
                } else {
                  JSFL.load(el[1], el[2], el[4]);
                }
                DescriptionPane.show(function () {
                  Browser.isLoading = false;
                  Main.firstLoad = false;
                  Filter.setIsActive(false);
                  ThemePane.showFull = false;
                });
                Browser.callAnalytics();
              });
              else AjaxLoader.BulkListLoad(el[1], function () {
                JSFL.callFlash = true;
                Mosaic.show();
                DescriptionPane.show(function () {
                  Browser.isLoading = false;
                  Main.firstLoad = false;
                  switch (el[1]) {
                  case "Films":
                  case "Artists":
                    Filter.setIsActive(true);
                    JSFL.load(el[1]);
                    break;
                  case "Works":
                    Filter.setIsActive(false);
                    JSFL.load(el[1]);
                    break;
                  default:
                    Filter.setIsActive(false);
                  }
                  ThemePane.showFull = false;
                  Browser.callAnalytics();
                });
              });
            });
          });
          return false;
        }
      }
      Page.goTo(0, historyFunction);
    }
  },
  loadLexiconEntry: function (id) {
    AjaxLoader.LexiconEntryLoad(id, function (data) {
      NavBar.open();
      Filter.setIsActive(false);
      var content = jQuery("Description", data).text().replace(/<br \/><br \/>/, "</p><p>");
      var title = jQuery("Word", data).text();
      jQuery(".desc-center div").html(content);
      jQuery(".desc-title h2").html(title);
      jQuery(".desc-center div p:last").addClass("last");
      jQuery(".desc-right-no-center a").removeClass("selected");
      jQuery(".desc-right-no-center a:contains('" + title + "')").each(function (i) {
        if (jQuery(this).text() == title) jQuery(this).addClass("selected");
      });
    });
  }
} 

////////////////////////////////////////////////////////
// Page Controller
////////////////////////////////////////////////////////

var Page = {
  arrowTimeout: false,
  currentlyPointed: false,
  isScrolling: false,
  scrollTo: function (top, callback) {
    top = top ? top : jQuery(".tq-header").eq(0).offset().top;
    jQuery("html").animate({
      scrollTop: top
    },
    {
      duration: 300,
      easing: "easeOutExpo"
    });
    jQuery("body").animate({
      scrollTop: top
    },
    {
      queue: false,
      duration: 300,
      easing: "easeOutExpo",
      complete: callback
    });
  },
  goTo: function (top, callback) {
    jQuery(document).scrollTop(Math.max(top, 0));
    callback();
  },
  addArrowLabels: function () {
    jQuery(".filtered").mouseover(function () {
      Page.currentlyPointed = jQuery(this);
      Page.arrowTimeout = setTimeout("Page.createArrow(Page.currentlyPointed);", 300);
    }).mouseout(function () {
      clearTimeout(Page.arrowTimeout);
      jQuery("#arrow").stop().dequeue().remove();
    }).click(function () {
      clearTimeout(Page.arrowTimeout);
      jQuery("#arrow").stop().dequeue().remove();
    });
  },
  createArrow: function () {
    var imagepath = "/Portals/_default/Skins/CinemaQuebecois/images/";
    var link = jQuery(Page.currentlyPointed);
    var top = link.offset().top - 2;
    var left = link.offset().left + link.width() + 5;
    var start = link.offset().left + link.width() + 200
    var details = link.attr("href").split("/");
    var img;
    if (details[1] == "") var suffix = details[3];
    else var suffix = details[1];
    switch (suffix) {
    case "Artists":
      img = "arrow_voir_portrait.png";
      break;
    case "Films":
      img = "arrow_voir_film.png";
      break;
    }
    if (suffix != "Works") {
      var html = "<img id='arrow' src='" + imagepath + img + "' style='position:absolute; top:" + top + "px; left:" + left + "px;' />";
      jQuery("body").append(html);
      jQuery("#arrow").ifixpng();
      jQuery("#arrow").css("opacity", "0");
      jQuery("#arrow").animate({
        opacity: 1
      },
      {
        duration: 300,
        easing: "easeOutExpo",
        complete: function () {
          jQuery("#arrow").ifixpng();
        }
      }); // jQuery("#arrow").animate({left:left}, {queue:false, duration:300, easing:"easeOutExpo"});
    }
  }
} 

////////////////////////////////////////////////////////
// Central Control
////////////////////////////////////////////////////////

var Main = {
  initiated: false,
  firstLoad: true,
  thisWeekEpisode: "",
  currentEpisode: -1,
  Init: function () { // Remove H1 - we dont need it, only for indexing
    //jQuery("h1").remove();
    // Capture this week's episode from previously ran code
    Main.thisWeekEpisode = jQuery(".current-id").val();
    Main.currentEpisode = jQuery(".current-id").val(); // Link Action setup
    jQuery(".main-menu a").click(function () {
      Main.LoadURL(jQuery(this).attr("href"), true);
      return false;
    });
    jQuery(".main-menu a.first").click(function () {
      ThemePane.showFull = true;
      Main.LoadURL(jQuery(this).attr("href"), true);
      return false;
    });
    jQuery("#bottom a").click(function () {
      Main.LoadURL(jQuery(this).attr("href"), true);
      return false;
    });
    jQuery(".main-menu a.first").attr("href", "/Episodes/" + Main.thisWeekEpisode + "/Default.aspx"); // Flash Element
    // Shortcut manager and link references setup
    if (location.href.indexOf("#") == -1) {
      Browser.startURL = location.href;
      Browser.currentURL = location.href;
      if (Main.thisWeekEpisode) JSFL.theme(Main.thisWeekEpisode, function () {}); //jQuery("#mosaic").focus();
    } else { // Browser.currentURL 	=  location.href.substr(location.href.indexOf("#"));
      Browser.startURL = location.href.substr(0, location.href.indexOf("#"));
      ThemePane.showFull = true;
      jQuery(".theme-menu-wrapper").animate({
        height: 62
      },
      {
        duration: 100
      });
    } // Navigation Environnement Setup
    setInterval(Browser.updateContent, 100);
    jQuery("body").append("<iframe id='navigator' style='display:none;'></iframe>"); // Search Event Capture setup

    /*jQuery("#cqdb-search").submit(function () {
      Main.Search(jQuery("#search-field").val(), true);
      return false;
    });*/

    jQuery("#search-field").focus(function () {
      if (jQuery(this).val() == "Votre recherche") jQuery(this).val("");
    }).blur(function () {
      if (jQuery(this).val() == "") jQuery(this).val("Votre recherche");
    });
    jQuery("#search-submit").click(function () {
      if (jQuery("#search-field").val() != "Votre recherche") Main.Search(jQuery("#search-field").val(), true);
      return false;
    }); // Search Button rollovers
		
		jQuery("#search-field").keypress(function (e) {
			if (e.which == 13) {
				if (jQuery("#search-field").val() != "Votre recherche") Main.Search(jQuery("#search-field").val(), true);
				return false;
			}
		}); // Search Button rollovers
		

    jQuery("#une-idee").mouseover(function () {
      jQuery(this).addClass("selected");
      Suggest.showLabel();
    }).mouseout(function () {
      jQuery(this).removeClass("selected");
      Suggest.hideLabel();
    });
    jQuery("#search-submit").mouseover(function () {
      jQuery(this).addClass("selected");
    }).mouseout(function () {
      jQuery(this).removeClass("selected");
    }); // Sub init
    Suggest.init();
    Quete.init();
    ThemeMenu.init();
    Filter.init();
    jQuery("#une-idee").click(function () {
      Suggest.ask();
      return false;
    });
    Main.initiated = true;
  },
  Wait: function () {
    JSFL.clear();
    JSFL.pending();
  },
  Search: function (word, fl) {
    Browser.URL("/Recherche/" + word.trim() + "/Default.aspx", fl);
  },
  Load: function (suffix, id, clip) {
    if (typeof(clip) != "undefined") Browser.URL("/" + Browser.reverseTranslateSuffix(suffix) + "/" + id + "/Clips/" + clip + "/Default.aspx");
    else if (typeof(id) != "undefined") Browser.URL("/" + Browser.reverseTranslateSuffix(suffix) + "/" + id + "/Default.aspx");
  },
  LoadLexiconEntry: function (id) {
    var el = Browser.currentURL.split("/");
    if (id.toString() != el[4]) {
      location.replace(Browser.currentURL = "http://" + el[2] + "/#/Glossaire/" + id + "/Default.aspx");
      JSFL.load('Lexicon', id);
      Browser.loadLexiconEntry(id);
      return false;
    }
  },
  LoadList: function (suffix, fl) {
    Browser.URL("/" + Browser.reverseTranslateSuffix(suffix) + "/Default.aspx", fl);
  },
  LoadClip: function (id) {
    var el = Browser.currentURL.split("/");
    location.replace(Browser.currentURL = "http://" + el[2] + "/#/" + el[4] + "/" + el[5] + "/Clips/" + id + "/Default.aspx");
  },
  Episode: function (id, fl) {
    Browser.URL("/Episodes/" + id + "/Default.aspx", fl);
  },
  Suggestion: function () {
    AjaxLoader.SuggestionLoader();
  },
  LoadURL: function (url, fl) {
    Browser.URL(url, fl);
  },
  Home: function () {
    jQuery("#search-field").val("Votre recherche");
    ThemePane.showFull = true;
    Browser.URL(Browser.startURL);
  },
  CurrentEpisode: function () {
    if (Main.currentEpisode == -1) Main.Home();
    else Main.Episode(Main.currentEpisode, true);
  }
} 

/////////////////////////////////////////////////////
// Bootstrap
/////////////////////////////////////////////////////

jQuery(document).ready(Main.Init);
