// JavaScript Document



	function zOrder()
	{
		var zIndexNumber = 9000;
		$('div').each(function() {$(this).css('zIndex', zIndexNumber);zIndexNumber -= 10;});
		
		//alert('test');
		//$('#lightbox').css('zIndex', 9999);
		//$('#overlay').css('zIndex', 9999);
		//$('#overlay img').css('zIndex', 9999);
		//$('#lightboxDetails').css('zIndex', 9999);
		//$('#lightbox img').css('zIndex', 9999);
		//$('#lightbox img').css('zIndex', 9999);
		
	}
	
	var swap_text_boxes = [];
	
	function init_search(){
	  //Store the default value for each box
	  $('#searchBox').each(function() {
		swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
	  });
	  //Add focus and blur events to set or clear the value
	  $('#searchBox').bind('focus', function() {
		if($(this).val() == swap_text_boxes[$(this).attr('id')]) {
		  $(this).val('');
		}
	  });
	  $('#searchBox').bind('blur', function() {
		if($(this).val() == '') {
		  $(this).val(swap_text_boxes[$(this).attr('id')]);
		}
	  });
	}

	$(document).ready(function(){ 
							   
		init_search(); 
		//zOrder();
		
		$("#popup-overlay").click(function(){overlayClose();});
		
	});
	
	function overlayOpen() {
		showElement('#popup-overlay')
	}
	
	function overlayClose() {
		hideElement('#popup-overlay')
		hideElement('.popup')
	}
	
	function setContent(obj,value)
	{
		//$(obj).text(value);
		$(obj).html(value)
	}

	function hideElement(obj)
	{
		$(obj).css('display', 'none');
	}
	
	// Shows the desired element
	function showElement(obj)
	{
		$(obj).css('display', 'block');
	
	}
	
	function resetEnvironment()
	{
		hideElement('.popup #popup-content')
		showElement('.popup #loader')
	}
	
			
	var assetLink;
	var assetData;


	function showAsset()
	{
		
		hideElement('.popup #loader')
		showElement('.popup #popup-content')
		
		setContent('.popup #popup-content',assetData)

		if(assetData.length ==0){
			//showElement('#punable');
		}

	}
	
	function viewAsset(assetID)
	{
		
		resetEnvironment()
		overlayOpen()
				
		showElement('.popup')
		
		
		
		$.ajax({
		  url: '_getAssetLink.asp?id=' + assetID + '&callID=' + Math.random(),
		  success: function( data ) {
			  
			
			assetLink = data
			
			$.ajax({
			  url: assetLink + '?callID=' + Math.random(),
			  success: function( data )
			  {
				assetData = data;
				setTimeout("showAsset()",500) 
			  }
			})
					
		  }
		});
			
	}
		
	
