/**** Add application wide javascripts below this point  ******/
var img_pos = 0;
$(document).ready(function() {
	if($('#image_picker').length) image_picker();
	
});

function image_picker(){
  $('a.switcher').click(function(){
    var image_count = $('a.switcher').length, clicked = $(this).attr('href');
    var this_href = $(this).attr('href'), this_rel = parseInt($(this).attr('rel')), this_alt = 'large '+$(this+' img').attr('alt');
    if(clicked != "#none"){
      if(this_rel < image_count){
        $('.large_image_holder img').attr('src', this_href).attr('alt', this_alt);
        var previous_rel = this_rel-1, next_rel = this_rel+1;
        if(previous_rel >= 0) $('#image_picker a.previous').attr('href', '#img_'+previous_rel);
        else $('#image_picker a.previous').attr('href','#img_'+(image_count-1));
        
        if(next_rel < image_count) $('#image_picker a.next').attr('href', '#img_'+next_rel);
        else $('#image_picker a.next').attr('href','#img_0');        
      }
    }
    return false;
  });
  $('#image_picker a').click(function(){
    
    var image_count = $('a.switcher').length, clicked = $(this).attr('href');
    
    if(clicked != "#none"){
      var this_href = $(clicked).attr('href'), this_rel = parseInt($(clicked).attr('rel')), this_alt = 'large '+$(clicked+' img').attr('alt');
      if(this_rel < image_count){
        $('.large_image_holder img').attr('src', this_href).attr('alt', this_alt);
        var previous_rel = this_rel-1, next_rel = this_rel+1;
        if(previous_rel >= 0) $('#image_picker a.previous').attr('href', '#img_'+previous_rel);
        else $('#image_picker a.previous').attr('href','#img_'+(image_count-1));
        
        if(next_rel < image_count) $('#image_picker a.next').attr('href', '#img_'+next_rel);
        else $('#image_picker a.next').attr('href','#img_0');
        
      }
    }
    
    return false;
  });
  
}