$(function(){
	if($('input#gift:checked').val()){
		$('p#gift_div').show();
	}else{
		$('p#gift_div').hide();
	}
	$('div.finishPreview div ul li img').click(function(e){
		
		var ul     = $($(this).context.parentNode).context.parentNode;
		var li     = $($(':parent', this).context.parentNode);
		var div    = $($(':parent',this).context.offsetParent).context.parentNode;
		var select = $('label select', $(div).context.parentNode);
		
		$(ul).each(function(){$(':parent', this).removeClass('selected');});
		
		var style = $(li).attr('class');
		$(li).addClass('selected');
		
		$('option', select).each(function(){
			if($(this).val() == style)
			{
				$(this).attr('selected', 'selected');
			}
		});
		$('div.finishPreview div').fadeOut();
	});
	$('div.finishPreview div a').click(function(e){
		e.preventDefault();
		$('div.finishPreview div').fadeOut();
	});
	$('a.preview').click(function(e){
		e.preventDefault();
		var div = $('+div', this);
		var select = $('label select', $($(':parent', this).context.parentNode).context.parentNode);
		var current = $(select).val();
		$('ul li', div).removeClass('selected');
		$('ul li', div).each(function(){
			if($(this).attr('class') == current)
			{
				$(this).addClass('selected');
			}
		});
		$(div).toggle();
	});
//	 $('div#lightBox a').click(function(e){
//		 e.preventDefault();
//		 $('div#overlay').fadeOut('fast', function(){$('div#lightBox').fadeOut();});
//	 });
//	 $('p.boxType a img').toggle(function(e){
//		 $('div#candleBoxInfo').css({
//			 top: e.pageY + 10 + 'px',
//			 left: e.pageX + 10 + 'px'
//		 }).show();
//	 },
//	 function(){
//		 $('div#candleBoxInfo').hide();
//	 });
//     $('div#candleBoxInfo a.close').click(function(e){
//             e.preventDefault();
//             $('div#candleBoxInfo').toggle();
//     });
//     $(window).scroll(function() {
//         if($('div#overlay').css('display') == 'block'){
//            $('div#overlay').css('height', $(window).height() + $(window).scrollTop() + 'px');
//            var centerFudge = ($(window).scrollTop() + ($(window).height() / 2));
//   		    $('div#lightBox').css('top', centerFudge + 'px');
//         }
//     });
//     
//     $('p.boxtype a').click(function(e){
//    	 e.preventDefault();
//    	 var box = $('div#lightBox');
//    	 $('> img', box).attr('src', $(this).attr('href'));
//    	 $('div#overlay').fadeIn("fast",function(){
//    		 var centerFudge = ($(window).scrollTop() + ($(window).height() / 2))/2;
//    		 $(box).css('top', centerFudge + 'px').fadeIn("fast");
//    	 });
//     });
     $('div#overlay').click(function(){
    	 $('div#lightBox').fadeOut("fast", function(){
    		 $('div#overlay').fadeOut("fast");
    	 });
	 });
     var candle = $("p.boxtype a, a.candle-preview");
     if($(candle)){
    	 $(candle).colorbox({
	    	 slideshow:true,
	    	 scrolling: true,
	    	 title: true,
	    	 photo: true,
	    	 speed: 300,
	    	 maxWidth: '800px',
	    	 maxHeight: '600px',
	    	 transition: 'elastic'
		 });
	 }
     


     var $fader = $('#homeFader');
     var timer = 5000;
     var doFade = function (){
       var $first = $('li:first', $fader);
       $first.fadeOut('slow', function(){
         $(this).clone().appendTo($fader).css({'display': 'block', 'z-index': 3});
         $(this).remove();
         var nth = Math.ceil($fader.length / 2);
         $('li:eq(' + nth + ')', $fader).css('z-index', 4);
         $('li:first', $fader).css('z-index', 5);
       });
       setTimeout(doFade, timer);
     };
     setTimeout(doFade, timer);


     $('.fix-z-index').bgiframe();
     /*$('ul#homeFader').innerfade( {
         timeout : 7000,
         speed : 2000
     });*/
});

