﻿var fr = true
var en = false
var domain = en ? 'http://indigenousartsnetwork.ca/' : 'http://reseaudartsautochtones.ca/'
$(function(){

  // populate the attributes from the artists array
  if(window.artists){
    $.each(window.artists,function(uri,artist){
      $('#'+uri).attr('ian:artist_uri',uri)
      $.each(artist,function(attr,val){
        if(val!=null) $('#'+uri).attr('ian:'+attr,val)
      })
    })
  }
  
  if ($(document).pngFix) { 
    //$('body').css({background:'white url(/stylesheets/bg.urbane.jpg) top center repeat-y'});
    $('img.logo').css({margin:'30px 0 10px 0;'})
    $(document).pngFix();
  }

  // preload
  $.get('/swf/stylish.swf')
  $.get('/swf/player.swf')
  $.get('/swf/captions.swf')

  if(fr) $("<div><h2>Explorer la carte</h2><a class='maplink iframe' title='Carte interactive des artistes' href='/carte/'><img src='/stylesheets/map/map_thumbnail.png' alt='Carte du Canada' style='border:0; width:160px; height:120px; margin-left: 20px; margin-top:7px;' /></a></div>").insertAfter('#sidebar ul.tags')
  if(en) $("<div><h2>Explore the Map</h2><a class='maplink iframe' title='Interactive map of artists' href='/map/'><img src='/stylesheets/map/map_thumbnail.png' alt='Map of Canada' style='border:0; width:160px; height:120px; margin-left: 20px; margin-top:7px;' /></a></div>").insertAfter('#sidebar ul.tags')

  if(fr) $("<div class='feature' style='background: url(/images/feature.map.jpg);'><div class='info'><h2><a href='/carte/' class='maplink iframe'>Carte interactive des artistes</a></h2><div class='description'><p>Naviguez dans l'univers des arts autochtones au Canada au moyen de la carte interactive.</p></div></div></div>").prependTo('#features')
  if(en) $("<div class='feature' style='background: url(/images/feature.map.jpg);'><div class='info'><h2><a href='/map/' class='maplink iframe'>Interactive Artist Map</a></h2><div class='description'><p>Explore Indigenous art across Canada with the interactive artist map.</p></div></div></div>").prependTo('#features')

  // re-apply css3 styles
  $('body').css('overflow-x','hidden')
  $('#content .description').css({'-moz-border-radius':'8px','-webkit-border-radius':'8px'})

  if ($.cookie('map') == "open"){
    if(fr) $("<div class='notice'><a href='/carte/' class='maplink iframe'>Retour à la carte</a></div>").hide().insertBefore('#wrapper').show(500)
    if(en) $("<div class='notice'><a href='/map/' class='maplink iframe'>Return to map</a></div>").hide().insertBefore('#wrapper').show(500)
    $.cookie('map',null)
  }

  if($(".maplink").length > 0){
    $(".maplink").attr('title',"Pour naviguer dans la carte, glissez votre souris, ou bien déplacez le rectangle rouge sur la petite carte à droite. Cliquez sur l'icône pour découvrir l’artiste qui s’y trouve.").fancybox(
      { 
        'zoomSpeedIn': 300, 
        'zoomSpeedOut': 300, 
        'overlayShow': true,
        'overlayOpacity': .8,
        'frameWidth': 900,
        'frameHeight': 600,
        'type':'iframe',
        'padding':0
      }
    ).click(function(){return false;})
  }
  
  // load artist video (aitow)
  $('body.artist #content > div').each(function(){
  //$('img.video').each(function(){
    if($(this).attr('ian:video')==undefined) return true
    video = $(this).attr('ian:video')
    subs = $(this).attr('ian:subtitles')
    runtime = $(this).attr('ian:runtime')
    viddivid = $(this).attr('class')+"_video"
    //viddivid = $(this).attr('ian:artist_uri')+"_video"
    // preload subs
    $.get(subs)

    vid = inline_video
    vid.flashvars.image = $("img:first",this).attr('src')
    //vid.flashvars.image = $(this).attr('src')
    vid.flashvars.duration = runtime
    vid.flashvars['captions.file'] = subs
    vid.attributes['name'] = vid.attributes['id'] = vid.flashvars['id'] = viddivid
    vid.flashvars.file = video

    $("img:first",this).replaceWith("<div class='video' id='"+viddivid+"'/>")
    //$(this).replaceWith("<div class='video' id='"+viddivid+"'/>")

    swfobject.embedSWF("/swf/player.swf", viddivid, vid.width, vid.height+32, vid.quality, false, vid.flashvars, vid.params, vid.attributes);

    $(this).append('<div><p>(Taille du fichier: '+$(this).attr('ian:video_size').replace('.',',')+' Mo)</p></div>')

  })  
  
  // thumbnail video click
  $('img.thumbnail').each(function(){
    if($(this).attr('ian:video')==undefined) return true
    $(this).attr('src',$(this).attr('src').replace(/\.jpg/,"-play.jpg")).css({cursor:'pointer'})
  }).click(function(){
    if($(this).attr('ian:video')==undefined) return true
    video = $(this).attr('ian:video')
    viddivid = $(this).attr('ian:artist_uri')+"_video"

    vid = thumbnail_video
    vid.flashvars.image = $(this).attr('src')
    vid.flashvars['captions.file'] = subs
    vid.attributes['name'] = vid.attributes['id'] = vid.flashvars['id'] = viddivid
    vid.flashvars.file = video
    
    $(this).replaceWith("<div class='thumbnail_video' id='"+viddivid+"'/>")

    swfobject.embedSWF("/swf/player.swf", viddivid, vid.width, vid.height, vid.quality, false, vid.flashvars, vid.params, vid.attributes);    

  })  
  
  // large thumbnail video click
  $('img.video').each(function(){
    if($(this).attr('ian:video')==undefined) return true
    video = $(this).attr('ian:video')
    runtime = $(this).attr('ian:runtime')
    subs = $(this).attr('ian:subtitles')
    viddivid = $(this).attr('ian:artist_uri')+"_video"

    vid = inline_video
    vid.flashvars.image = $(this).attr('src')
    vid.flashvars['captions.file'] = subs
    vid.flashvars.duration = runtime
    vid.attributes['name'] = vid.attributes['id'] = vid.flashvars['id'] = viddivid
    vid.flashvars.file = video
    
    $(this).replaceWith("<div class='inline_video' id='"+viddivid+"'/>")

    swfobject.embedSWF("/swf/player.swf", viddivid, vid.width, vid.height+32, vid.quality, false, vid.flashvars, vid.params, vid.attributes);

  })
  
  
  $('#gallery img').show()
  $('#gallery').cycle({ 
    fx:     'scrollLeft',
    //fx:     'fade',  
    speed:   300, 
    timeout: 6000, 
    next:   '#gallery',
    pause:   1 
  });
  
  
  $('#features .feature').show()
  $('#features').cycle({ 
    //fx:     'scrollLeft',
    fx:     'fade',  
    speed:   300, 
    timeout: 8000, 
    pause:   1 
  });
  

})

inline_video = {
  width: 360,
  height: 240,
  quality: "9",
  flashvars: {
    plugins: "viral-1,/swf/captions,googlytics-1",
    autostart: false,
    skin: '/swf/stylish.swf',
    usecaptions: false,
    wmode: 'opaque',
    'captions.fontsize': '18',
    allownetworking: 'all'
  },
  params: {
    wmode: 'opaque',
    allowfullscreen: "true",
    allowscriptaccess: "always"
  },
  attributes: {
    wmode: 'opaque',
    'class': "video"
  }
}


thumbnail_video = {
  width: 180,
  height: 120,
  quality: "9",
  flashvars: {
    wmode: 'opaque',
    autostart: true,
    controlbar: 'none',
    skin: '/swf/stylish.swf'
  },
  params: {
    wmode: 'opaque',
    allowfullscreen: "false",
    allowscriptaccess: "always"
  },
  attributes: {
    wmode: 'opaque',
    'class': "thumbnail_video"
  }
}


