var images = new Array("/templates/3/2011/im/bg-band2.jpg",
					   "/templates/3/2011/im/bg-charlotte1.jpg",
					   "/templates/3/2011/im/bg-frozen1.jpg",
					   "/templates/3/2011/im/bg-martijn2.jpg",
					   "/templates/3/2011/im/bg-sander1.jpg",
					   "/templates/3/2011/im/bg-otto1.jpg");

var random=Math.floor(Math.random()*images.length);
var randomint = Math.floor(Math.random()*Math.random()*Math.random()*1000000)+1;
$(document).ready(function()
{
if (jQuery.browser.safari && document.readyState != "complete"){
    //console.info('ready...');
    setTimeout( arguments.callee, 100 );
    return;
  } 
  var height = ($("#main").height() < $(document).height()) ? $(document).height() : $("#main").height();
  
  $("#left").css('height', (height)+"px");
  
  /*$("ul img").each(function()
  {
  	if ($(this).attr("src") == "/templates/3/gfx/menu/menu_spacer.png")
  		$(this).hide();
  	if ($(this).attr("src") == "/templates/3/2011/im/menu-spacer.png")
  		$(this).show();
  });*/
  
  $(".menubtn").hide();
  $("#menu li").show();
  $("#menu li a img").show();
  $("#bgspinner").hide().css('background-image', "url('"+images[random]+"?rand="+randomint+"')").fadeIn(250);
  
  for (var i = 0; i< images.length; i++)
  {
  	$("#sliderswitch").append('<a href="#" class="slide" count="'+(i)+'">'+(i+1)+'</a>');
  
  	if (i < images.length-1) $("#sliderswitch").append(' <b>|</b> ');
  	if (i == random) $(".slide:last").addClass("active");
  }
  
  $("ul#menu li.notactive a img").hover(
  	function()
  	{
  		var image = $(this).attr("src");
  		image = image.replace(".png", "-on.png");
  		$(this).attr("src", image);
  	},
  	function()
  	{
	  	var image = $(this).attr("src");
  		image = image.replace("-on.png", ".png");
  		$(this).attr("src", image);	
  	});
  	
  	$(".slide").click(function(e)
  	{
  		e.preventDefault();
  			
  		randomint = Math.floor(Math.random()*Math.random()*Math.random()*1000000)+1;		
  		var clicked = $(this).attr('count');
  		
  		if (clicked == random) return false;

  		$(".slide").removeClass('active');
  		$(this).addClass("active");
  		
  		$("#bgspinner").fadeOut(250, function() {
  			$(this).css('background-image', "url('"+images[clicked]+"?rand="+randomint+"')").fadeIn(250);
  			random = clicked;
  		});
  		
  	});
  	
  	
  	$("#contentone .block img").each(function()
  	{ 	
  		var blockwidth = 380; //$("#contentone .block .text").width();

	    var imgwidth = $(this).width();
	    
		if (imgwidth >= blockwidth)
		{
			$(this).width(blockwidth);
		}
  	});

  	
  	$(".block object").each(function()
  	{
  		var blockwidth = 380;//$(this).parent('div .text').width();
  		 if ($(this).width() >= blockwidth)
		 {
		 	$(this).width(blockwidth);
		 	$(this).children("embed").width(blockwidth)
		 }
  	});
  	
  	$.get("/index.php?component=Twitter", function(data){
  		$("#tweet").html(data);
	});

	$(".buylink").click(function(e)
	{
		if ($(this).attr("href") == "")
		{
			e.preventDefault();
			alert("This product is not available or we haven't added the correct link, please try again later");
		}
	});
  
});

function getOriginalWidthOfImg(img_element) {
    var t = new Image();
    t.src = (img_element.getAttribute ? img_element.getAttribute("src") : false) || img_element.src;
    return t.width;
}
