// JavaScript Document
var shouldHide
var subHideInt;
var subHideWait = 250;

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

$.preLoadImages('/images/layout/cius-hover.png',emptyCart,fullCart);

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


$(document).ready
(
	function()
	{
		$('#menu ul').hide();	
		
		$('#menu > li > a').mouseover
		(
		 function()
		 {
			$('#menu ul').hide();
			$(this).parent().children('ul').fadeIn('fast');
			$(document).stopTime('hide',hideAllSubs);
		 }
		 )
		
		$('#menu ul').mouseover
		(
		 function()
		 {
			$(document).stopTime('hide',hideAllSubs);
		 }
		 )
		
		$('#menu > li > a,#menu ul').mouseout
		(
		 function()
		 {
			 $(document).oneTime(subHideWait,'hide',hideAllSubs);
		 }
		 )
		
		$('a.tip').cluetip(
						   {
							   splitTitle:'|',
							   arrows:true,
							   positionBy:'mouse'
						});
		$('a.tip').click(
						 function(){
							 window.location.href=$(this).attr('href');
							 }
						);
		
		$('#logo img').mouseover
		(
		 function()
		 {
			$(this).attr('src','/images/layout/cius-hover.png'); 
		 }
		 )
		
		$('#logo img').mouseout
		(
		 function()
		 {
			$(this).attr('src','/images/layout/cius.png'); 
		 }
		 )
		
			
	//replace the first character in a dropCap div with a drop cap image
	$('div.dropCap').each
	(
	 function(i)
	 {
		 var firstContainer = $(this);
		 var html = '';
		 var firstLetter;
		 var restOfHTML;
		 var blocks;
		 
		 //alert($(this).html().trim().substring(0,1))
		 
		 if($(this).html().trim().substring(0,1) == '<')
		 {
			blocks = $(this).children('*'); 
			
			firstBlock = $(blocks.get(0));
			
			//if(firstBlock[0].tagName == 'P' || firstBlock[0].tagName == 'DIV')
			//{
				firstContainer = firstBlock;//blocks.get(0);
			//}
		 }
		 
		 html = firstContainer.html();
		 html = html.trim();
		 firstLetter = html.substring(-1,1).toUpperCase();
		 restOfHTML = html.substring(1);
		 
		 if(String(html).length > 0)
		 {
		 	firstContainer.html('<img src="/images/layout/dropCaps/' + firstLetter + '.png" alt="' + firstLetter + '" class="dropCap" />' + restOfHTML);
		 }
	 }
	 )
	}

);

function hideAllSubs()
{
	$('#menu ul').fadeOut('fast');
}


function cartWidgetRemove(id, priceID, node)
{
	var action = 'remove';
	var p = 't';
	
	$.post('/store/cfoscom/ajax/cartAction.cfm',
		   {
			id:id,
			priceID:priceID,
			action:action
		   },
		   function(data,textStatus)
		   {
				onCartRemoved(data,textStatus,node)
		   }
		  )
}
function getList()
{
	$.get('/scripts/php/getGigs.php',putLatestContent);	
}
function onCartRemoved(data,textStatus,node)
{
	$(node).parent().fadeOut('fast',function(){window.location.reload();});
	
}
function getCal(y,m,caller)
{
	var today = new Date();
	y = y == undefined ? today.getFullYear() : y;
	m = m == undefined ? today.getMonth() : m;
	
	$.post('/scripts/php/getCalendar.php',{y:y,m:m},putLatestContent);
}
function putLatestContent(data)
{
	$('#calendar .widgetContent').html(data);
	$('.hasEvents a').cluetip({
					  arrows: true,
					  sticky: true,
					  closePosition: 'title',
					  cursor: 'pointer'
					  });
}
function changeCartQuantity(id)
{
	var q = $('#quantity_' + id).val();
	$.post('/store/cfoscom/ajax/changeQuantityTo.cfm',{q:q,id:id},function(data,textStatus){window.location.replace(window.location.href)});
}