/* Predefined variables */
var boolBusy = false;
var aObjects = new Array();

var aIds = new Array();
var aShoeIds = new Array();
var aTitle = new Array();

$(document).ready(function() {	
	
	// Show/hide Shoes
	//$('a[rel=bigshoe]').click(function(){ showShoe($(this).attr('href'),$(this).attr('title'),$(this).attr('id')) });

	$("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');
  });

	/* Lightbox for jQuery */
	$("a[rel=fancybox],a[rel=lightbox]").fancybox();

 $("#previewButton,#preview").addClass('clickable');
 $("#previewButton").click(function(){ showPreview() });
 $("#preview").click(function(){ hidePreview() });

 $("#fairsButton2,#fairs .close").addClass('clickable');
 $("#fairsButton2").click(function(){ showFairs() });

 $("#fairsButton,#fairs .close").addClass('clickable');
 $("#fairsButton").click(function(){ showFairs() });
 $("#fairs .close").click(function(){ hideFairs() });


  // Add extras
  bindRichInteraction();

  // External links in new window
	ExternalLinks();
});


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,title,id)
{
  //$(e).fadeIn({ opacity: 100 },1000, function(){ $(e).css({ 'display':'block', 'z-index':'1000' }); });
  if (!boolBusy){
    var tmpId = e.replace('#schoen','');
    var tmpTitle = title;
    var tmpShoeId = id.replace('shoe_','');
    $.ajax({
      url:'/ajax/getBigShoe.asp?id='+tmpId+'&title='+tmpTitle+'&shoeId='+tmpShoeId,
      beforeSend: function() {
                // Apply loader
                boolBusy = true;
              },
      complete: function(oResponse) {
                // Remove loader
                boolBusy = false;
                $('#schoen #ajaxContent').html(oResponse.responseText); // Replace src
                $('#schoen').show(500);

                $('.locations').hide();
                $('a.accordionHeader').bind({
                  click: function(){ accordionize( $(this) ); return false; }
                });
              }
    });
  }

}
function hideShoe(e)
{
	$('#schoen').hide(250);	
}

function accordionize(e)
{
  $('.locations').hide(0, function(){ $( e.attr('rel') ).show(); });
};
