// ================================================================================================
var products = {
  
  // ==========================================================================
  init: function() {
    // set up the onclicks for the colours
    $('#product_image div a').click(this.change_image);
    
    // set up a fake click for the holder of the colours
    this.setup_clicker();
  },
  
  back:function() {
	$('#product_image').show();
	$('#flash_holder').hide();
  },
  
  // ==========================================================================
  change_image: function() {
    // get the changes needed
    var data = $(this).attr('ref').split('|');

	// flash 360/zoom
	if (data[1]=='flash') {		
		// hide image
		$('#product_image').hide();
		$('#flash_holder').show();
		var params = {allowfullscreen:'true'};
		var flashvars = {};
		swfobject.embedSWF(data[0], "flash_movie", "395", "395", "9.0.0", 'flash/expressInstall.swf', flashvars, params);
	}
	// regular image
	else {
		// show image
		$('#product_image').show();
		$('#flash_holder').hide();
		
		// change the main image
		$('#product_image_main img').attr('src', data[0]);
		
		// change the main url
		$('#product_image_main, #enlarge_button').attr('href', data[1]);
		$('#product_image div span a').attr('href', data[1]);
	}
    
    // check for a buy direct option
    if (data[2])
    {
      $('#buy_direct').attr('href', data[2]);
      $('#buy_direct').show();
    }
    else
    {
      $('#buy_direct').hide();
    }
    
    // change the highlighted colour
    $('#product_image div a img').removeClass('product_thumb_on');
    $(this).children().addClass('product_thumb_on');
    
    // change the colour name
    $('#product_colour').html($(this).children().attr('alt'));
    
    // stop the click from occuring
    return false;
  },
  
  // ==========================================================================
  setup_clicker: function() {
    // give the div a pointer
    $('#product_clickable').css('cursor', 'pointer');
    
    // set up the click
    //$('#product_clickable').click(function() {$('#product_image_main').click();});
  }
};

// ================================================================================================
$(document).ready(function() {
  // check to see if products js is needed
  products.init();
    
  // set up the lightbox (fancybox)
  $('#product_image_main, #enlarge_button').fancybox();
});