$().ready(function(){
  
  //$(".images a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook'});
  $("a[rel^='prettyPhoto'], a[rel^='gabgal']").prettyPhoto({allowresize:false,theme:'facebook',social_tools: false,deeplinking:false,changepicturecallback:function(){
    $("a.pp_arrow_next, a.pp_arrow_previous").click(function(e){
      e.preventDefault();
    });
  }});
  
  //load the internal ads
  $.getJSON('http://cdn.dotnology.co.uk/gabbitas_internal_ads/ads.json.php?callback=?', function(data) {
    gab_ads=data;
    next_gab_ad();
  });

  if(jQuery().accordion){
    $(".accordion").accordion();
  }
  
});


//internal adverts code
var gab_ads;
var gab_ad=0;
function next_gab_ad(){
  $('<img />').addClass('img').attr('src',  gab_ads[gab_ad].img ).one('load',function(){
    var new_img=this;
    $('#internal_ads_content').slideUp(600,function(){
      $('#internal_ads_content .title').html( gab_ads[gab_ad].title );
      $('#internal_ads_content .description').html( gab_ads[gab_ad].description );
      $('#internal_ads_content .call_to_action').html( gab_ads[gab_ad].call_to_action );
      $('#internal_ads_content .img').replaceWith( new_img );
      $('#internal_ads_content').slideDown(600,function(){
        gab_ad++;
        if(gab_ad>=gab_ads.length){
          gab_ad=0;
        }
        setTimeout('next_gab_ad()',10000);        
      });  
    });
  }).each(function() {
    if(this.complete) $(this).load();
  });
}


