$(document).ready(function()
{
	if ($("a#spotlink1").length > 0)
	{
		$("a#spotlink1").fancybox
		({
			'hideOnContentClick': true,
			'overlayOpacity':0.5,
			'centerOnScroll':false,
			'hideOnContentClick':false,
			'onStart': function()
				{
					$('#spotuvapproval').toggle();
					$('object').css('visibility','hidden');
				},
			'onClosed': function()
				{
					$('#spotuvapproval').toggle();
					$('object').css('visibility','visible');
				}	
		});
	}

	if ($("a#spot_service_banner").length > 0)
	{
		$("a#spot_service_banner").fancybox
		({
			'hideOnContentClick': true,
			'overlayOpacity':0.5,
			'centerOnScroll':false,
			'hideOnContentClick':false
		});
	}
	
	if ($("a#spotlink2").length > 0)
	{
		$("a#spotlink2").fancybox({ 'hideOnContentClick': true, 'overlayOpacity':0.5, 'centerOnScroll':false, 'hideOnContentClick':false,
			'onStart': function() {
				$('#spotuvapproval').toggle();
			}, 'onClosed': function() {
				$('#spotuvapproval').toggle();
			}	
		});
	}
	
	if ($("a#spotlink3").length > 0)
	{
		$("a#spotlink3").fancybox({ 'hideOnContentClick': true, 'overlayOpacity':0.5, 'centerOnScroll':false, 'hideOnContentClick':false,
			'onStart': function() {
				$('.spotinfo_footer').hide();
				$('#spotuvapproval').toggle();
			}, 'onClosed': function() {
				$('.spotinfo_footer').show();
				$('#spotuvapproval').toggle();
			}	
		});
	}
	
	if ($("a#newsletterlink").length > 0)
	{
		$("a#newsletterlink").fancybox({ 'hideOnContentClick': false, 'overlayOpacity':0.5, 'centerOnScroll':false});
	}
	
	//Upsell-Sites-Ajax-Requests
	if ($('a[name|="addToCartLink"]').length > 0)
	{
		//alert($('a[name|="addToCartLink"]').length);
		for(i = 0; i < $('a[name|="addToCartLink"]').length; i++)
		{
			$('a[name="addToCartLink-'+i+'"]').fancybox({ 
							'hideOnContentClick': true, 
							'hideOnOverlayClick': true, 
							'overlayOpacity':0.5, 
							'centerOnScroll':true,
							'scrolling'   : 'no'	});
		
		}	
	}
	
	if ($("a#filecheck_link").length > 0)
	{
		$("a#filecheck_link").fancybox({ 'titleShow': false, 'hideOnContentClick': true, 'overlayOpacity':0.5, 'width':320, 'height': 400, 'centerOnScroll':false,'autoDimensions':false,
			'onStart': function() {
				$('#anispot').css('visibility','hidden');
				$('#anihg').css('visibility','hidden');
			}, 'onClosed': function() {
				$('#anispot').css('visibility','visible');
				$('#anihg').css('visibility','visible');
			}	
		});
	}

	if ($("a#cookielightbox").length > 0)
	{
		$('a#cookielightbox').fancybox({'hideOnContentClick': false,'overlayOpacity':0.5,'centerOnScroll':false,'showCloseButton':false,'enableEscapeButton':false,'hideOnOverlayClick':false,
				'onStart': function() {
					$('#banner_spot_homepage').css('visibility','hidden');
				},
				'onClosed': function() {
					$('#banner_spot_homepage').css('visibility','visible');
				}	
			}
		);
	}
	
	if ($('select[name=itemId]').length > 0 && $.cookie('selected_item'))
	{
		old_select_value = $('select[name=itemId]').val();
		old_selected_index = $('select[name=itemId]').get(0).selectedIndex;

		$('select[name=itemId]').get(0).selectedIndex = $.cookie('selected_item');

		new_select_value = $('select[name=itemId]').val();
		if (new_select_value < 1 && old_select_value > 0)
		{
			/* Can't select a negative item, reverting changes now. */
			$('select[name=itemId]').get(0).selectedIndex = old_selected_index;
		}
	}
	
	if ($("select[name=itemId]").length > 0)
	{
		$('select[name=itemId]').live('change', function()
		{
			$.cookie('selected_item', $(this).get(0).selectedIndex);
		});
	}
	
	if ($("body:has(select[name=itemId])").length > 0)
	{
		$('body:has(select[name=itemId])').find('input[type=submit]').live('click', function()
		{
			$.cookie('selected_item', null);
		});
	}

	if ($("#spotbox_link1").length > 0)
	{
		$('#spotbox_link1').live('click', function()
		{
			$('#spotbox_partb').hide();
			$('#spotbox_partc').hide();
			$('#spotbox_link1').hide();
			$('#spotbox_part1').css({'background':'url(img/universal/spotuv/lightbox_1d.jpg) no-repeat top left', 'height':'420px'});
			$('#spot_service_text').css({'float':'none', 'width':'420px', 'margin-left':'35px'});
			$('#spot_text_area').show();
		});
	}

	if ($("#spotbox_cancel").length > 0)
	{
		$('#spotbox_cancel').live('click', function()
		{
			$('#spot_text_area').hide();
			$('#spot_service_text').css({'float':'right', 'width':'270px', 'margin-left':'0px'});
			$('#spotbox_part1').css({'background':'url(img/universal/spotuv/spot_lightbox_1a.jpg) no-repeat top left', 'height':'137px'});
			$('#spotbox_link1').show();
			$('#spotbox_partc').show();
			$('#spotbox_partb').show();
		});
	}



	if ($("a#billpay_type_link").length > 0)
	{
		$("a#billpay_type_link").fancybox
		({
			'hideOnContentClick': true,
			'overlayOpacity': 0.4,
			'centerOnScroll': false,
			'hideOnContentClick': false,
		});
	}

});

