/* Predefined variables */
var boolBusy = false;
var aObjects = new Array();

var aIds = new Array();
var aShoeIds = new Array();
var aTitle = new Array();


$(document).ready(function() {		
	
	/* Lightbox for jQuery */
	$("a[rel=fancybox],a[rel=lightbox]").fancybox();
	
	// Show/hide Shoes
	//$('a[rel=bigshoe]').click(function(){ showShoe($(this).attr('href')) });

	$("a[rel=bigshoe]").each(function(){ 
		aIds.push( $(this).attr('href').replace('#schoen','') );
		aShoeIds.push( $(this).attr('id').replace('shoe_','') );
		aTitle.push( $(this).attr('title') );
	});

	$("a[rel=bigshoe]").click(function(){
		var id = $(this).attr('href').replace('#schoen','');
		var shoeId = $(this).attr('id').replace('shoe_','');
		var title = $(this).attr('title');
		$.fancybox({ type: 'iframe', width: 731, height: 477, showNavArrows: true, title: title, padding: 0, margin: 0, scrolling: 'no', href: '/ajax/getBigShoe.asp?id='+ id +'&title='+title+'&shoeId='+shoeId });
	});

  // Show/hide Agents
  $('ul#preselect li a').click(function(){ 
    showAgent($(this).attr('href'))
    $(this).addClass('active');
  });

  $('#carousel-collection').jCarouselLite({
    auto: 2000,
    speed: 1000,
    visible: 5,
    vertical: true
  });
  bindCarouselClick();



 $("#previewButton,#preview").addClass('clickable');
 $("#previewButton").click(function(){ showPreview() });
 $("#preview").click(function(){ hidePreview() });

  tradefairs();

  // Add extras
  bindRichInteraction();

  // External links in new window
	ExternalLinks();
});

function bindCarouselClick()
{

  $('#collection li a').bind({
    click:  function() {
              var imgId = $(this).attr('rel')
              var imgTitle = $(this).attr('title')
              $.ajax({
                url:'/image.asp?id='+imgId ,
                complete: function(oResponse) {
                          $('#bigshoe').find('img').attr('src', oResponse.responseText); // Replace src
                          $('#bigshoe').find('span').html(imgTitle); // Replace span
                        }
              });

              
              return false;
            }
  })

}

function tradefairs()
{

  $('a[rel=tradefair]').click(function(){
    var targetId = $(this).attr('id').replace('target_','fair_');
    $('#'+targetId).addClass('visible');
    return false;
  });

  $('a.back').click(function(){
    var targetId = $(this).attr('rel').replace('target_','fair_');
    $('#'+targetId).removeClass('visible');
    return false;
  });


}

function showPreview()
{		
 $('#preview').css({ 'display':'block', 'opacity':0, 'zIndex': 200 });
	$('#preview').animate({ opacity: 100	},1000, function(){	
		                                          $('#preview').css({ 'display':'block', 'zIndex': 200 });
	})	
}
  
function hidePreview()
{
	$('#preview').animate({ opacity: 0 },500, function(){	
		                                          $('#preview').css({ 'display':'none', 'zIndex': 100 });
	})	
}


function showFairs()
{		
 $('#fairs').css({ 'display':'block', 'opacity':0, 'zIndex': 200 });
	$('#fairs').animate({ opacity: 100	},1000, function(){	
		                                          $('#fairs').css({ 'display':'block', 'zIndex': 200 });
	})	
}
  
function hideFairs()
{
	$('#fairs').animate({ opacity: 0 },500, function(){	
		                                          $('#fairs').css({ 'display':'none', 'zIndex': 100 });
	})	
}


/************************/
/* Bind Interaction     */
/************************/

function bindRichInteraction()
{
  // Hide all obtrusive elements
  $('.hidden').addClass('jsHide');
/*
  $('.note').addClass('clickable');
  $('.note').attr('title','Meer informatie over deze clipping?');
  $('.note').click( function(){ $('.note').toggleFade({ speedIn : 350, speedOut : 150 }); });
*/
}

/************************/
/* Supporting Functions */
/************************/

function ExternalLinks() 
{ 
  var hostname=window.location.hostname;hostname=hostname.replace("www.","").toLowerCase();	var a=document.getElementsByTagName("a"); this.check=function(obj){ var href=obj.href.toLowerCase(); return(href.indexOf("http://")!=-1&&href.indexOf(hostname)==-1)?true:false; }; this.set=function(obj){ obj.target="_blank"; }; for(var i=0;i<a.length;i++){ if(check(a[i])) set(a[i]); }; 
};


/* Agents */
function hideAgent(e)
{
  if (e)
  {
    $('li'+e).css({'display':'none'});
  }else{
    $('ul#info').children().css({'display':'none'});
  }
  $('ul#preselect li a').removeClass('active');
}

function showAgent(e)
{
  hideAgent();
  $('li'+e).css({'display':'block'});
}


/* Shoes */
function showShoe(e)
{		
  $(e).fadeIn({ opacity: 100 },1000, function(){ $(e).css({ 'display':'block', 'z-index':'1000' }); });
}

function hideShoe(e)
{
	$(e).animate({ opacity: 0  },1000, function(){ $(e).css({ 'display':'none', 'z-index':'100' }); })	
}
