

function openTiny(bigurl,sharerUrl)
{

    $.getJSON(
      "http://json-tinyurl.appspot.com/?&callback=?",
      {url: bigurl},
      function(data){

      window.open(sharerUrl+data.tinyurl,'share','menubar=no, status=no, scrollbars=no, menubar=no, width=600, height=400');
      }
    );
}


function getHostname(str) {    var re = new RegExp('^(?:f|ht)tp(?:s)?\://([^/]+)', 'im');    return str.match(re)[1].toString();}

jQuery(document).ready(function(){



$('a.facebook_button').click(function()
{

//alert($(this).parents('div').find('a').attr('onclick'));



var sharerUrl = 'http://www.facebook.com/sharer.php?u=';

var contentUrl = $(this).attr('href');

contentUrl = contentUrl.replace("http://tv.bizet.arte-tv.com", "http://www.arte.tv");

contentUrl = contentUrl.replace("http://videos.bizet.arte-tv.com", "http://videos.arte.tv");

contentUrl = contentUrl.substr(0,contentUrl.indexOf('&t='));

var contentUrl = contentUrl.replace(sharerUrl, '');

openTiny(contentUrl,sharerUrl)

return false;
});



$('a.twitter_button').click(function()
{

var sharerUrl = 'http://twitter.com/home?status=';

var contentUrl = $(this).attr('href');

contentUrl = contentUrl.replace("http://tv.bizet.arte-tv.com", "http://www.arte.tv");

contentUrl = contentUrl.replace("http://videos.bizet.arte-tv.com", "http://videos.arte.tv");

contentUrl = contentUrl.substr(0,contentUrl.indexOf('&t='));

var contentUrl = contentUrl.replace(sharerUrl, '');

openTiny(contentUrl,sharerUrl)

return false;
});



//bind hiding video when rollover on main nav

if (!badBrowser)
{
jQuery('#main_nav ul li').bind("mouseover","",hide_video);
jQuery('#main_nav ul li').bind("mouseout","",show_video);

}



//ie7 : unbind all child DOM elements to avoid flickering
jQuery('#main_nav ul li *').unbind();





jQuery("#right_column").html('');

		

//load right column content
jQuery("#right_column").load(rightColumnUri,'',function() {

//set the right font-size
jQuery(".iframe").css({ fontSize:"1em"});

//we load the day date, the today trailer is the first one
manage_trailer_nav(0,"");



//then launch the video
//loadFile('artetv_trailer',{file:'http://download.www.arte.tv/permanent/c0/teaser/'+video_date[id_date]+'_fr.FLV',javascriptid:'artetv_trailer_player',click_link:'http://vdm.bz',autostart:'true',width:'240',height:'180',volume:'0'});



//then launch the video
//loadFile('artetv_trailer',{file:getTrailerLink(),javascriptid:'artetv_trailer_player',click_link:getTrailerLink(),autostart:'true',width:'240',height:'180',volume:'0'});



//be sure not to load the javascript each time the website is called

$.ajaxSetup({ cache: true });

jQuery.getScript("/fr/2150258,templateId=renderJs,property=data,v=23,CmPart=com.arte-tv.www.js", function(){});

$.ajaxSetup({cache: false});

openElements();

});



//bottom horizontal accordion
jQuery.fn.extend({
  haccordion: function(params){
    var jQ = jQuery;
    var params = jQ.extend({
      speed: 200,
      headerclass: "header",
      contentclass: "content",
      event: "click",
      contentwidth: 162
    },params);

//then set all elements to the maximum height



var elem1 = getElementsByClass('content_1');
elem1[0].style.height=(biggest_div_height())+"px";
var elem1 = getElementsByClass('link_1');
elem1[0].style.height=(biggest_div_height()-20)+"px";



var elem2 = getElementsByClass('content_2');
elem2[0].style.height=(biggest_div_height())+"px";
var elem2 = getElementsByClass('link_2');
elem2[0].style.height=(biggest_div_height()-20)+"px";



var elem3 = getElementsByClass('content_3');
elem3[0].style.height=(biggest_div_height())+"px";
var elem3 = getElementsByClass('link_3');
elem3[0].style.height=(biggest_div_height()-20)+"px";



jQuery(".haccordion").css({ maxHeight:biggest_div_height()});

    
//return the biggest content div in order to resize the smaller one
function biggest_div_height(){
//if the third one is clicked, we have to set a special grey background
elem1 = getElementsByClass('content_1');
elem2 = getElementsByClass('content_2');
elem3 = getElementsByClass('content_3');



var safari = 0;
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("safari") != -1) safari=1;;



if(elem1[0].offsetHeight>=elem2[0].offsetHeight && elem1[0].offsetHeight>=elem3[0].offsetHeight)

{
 return elem1[0].offsetHeight;

}

 if(elem2[0].offsetHeight>=elem3[0].offsetHeight && elem2[0].offsetHeight>=elem1[0].offsetHeight)

{
 return elem2[0].offsetHeight;

}

 if(elem3[0].offsetHeight>=elem2[0].offsetHeight && elem3[0].offsetHeight>=elem1[0].offsetHeight)

{
 return elem3[0].offsetHeight;

}



}

    return this.each(function(){

//apply visible class to the opened element (the first)
this.opened = jQ("."+params.contentclass,this).filter(".visible").prev();

  jQ("."+params.headerclass+" a",this).bind(params.event,function(){
	
	var p = jQ(this).parent().parent()[0];
        if (p.opened != "undefined"){
          jQ(p.opened).next("div."+params.contentclass).animate({
            width: "0px"
          },params.speed);
        }
        p.opened = jQ(this).parent();
        jQ(p.opened).next("div."+params.contentclass).animate({
          width: params.contentwidth + "px"
        }, params.speed);
	
	//if the third one is clicked, we have to set a special grey background
	if(this.className=="link_3")
	document.getElementById(this.parentNode.parentNode.id).style.backgroundImage ='url(/i18n/2150278,property=data,v=3.gif)';
	else
	document.getElementById(this.parentNode.parentNode.id).style.backgroundImage ='none';

                  return false;
	 
      });
    });
  }
});

jQuery('#left_content').find(".haccordion").each(function(i) {
jQuery('#'+this.id).haccordion();
});





//add background url src

var host = getHostname(window.location.href.toString());



jQuery.get('http://'+host+'/rightcolumnV3/?page_id=2&lang='+locale, function(data) {

//console.log(window.location.href.toString().indexOf('/fr')+"--"+(parseInt(window.location.href.toString().length)-3))

    if(window.location.href.toString().indexOf('/fr') == (parseInt(window.location.href.toString().length)-3) || window.location.href.toString().indexOf('/de') == (parseInt(window.location.href.toString().length)-3))

    {

         if(data!="NOBG")  

         jQuery("body").attr("style",data);

     }

});








});
