// Load Shadowbox Skin
Shadowbox.loadSkin('skin', base_url+'public/js/shadowbox');

$(document).ready(function() { 
	
	// IE6 png fix
	if($.browser.msie && ($.browser.version == 6.0)) { $.ifixpng(base_url+'public/images/pixel.gif'); $('.pngFix').ifixpng(); }
	
	// Initiate Shadownbox
	Shadowbox.init({
		skipSetup: true,
		overlayColor: '#000',
		animSequence: 'sync'
	});
	
	// Open in new window
	$('.newWindow').click(function() { 
		window.open(this.href, 'new_window');
		return false;
	});
	
	// Open Terms and Conditions Popup
	$('.terms').click(function() { 
		window.open(this.href, 'TermsandConditions', 'height=600, width=500, channelmode=no, directories=no, fullscreen=no, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, titlebar=no, toolbar=no');
		return false;
	});  
	
	// Large UK Map
	$("#area_links_large a, #uk_map_large_map area").hover(
		function () {
	   		$('#uk_map_large_hover').addClass($(this).attr('class'));
			if($(this).parent().attr('id') == 'uk_map_large_map') { $('#area_links_large .'+$(this).attr('class')).addClass('selected'); }
			
			if($.browser.msie && ($.browser.version == 6.0)) {
				$('#uk_map_large').prepend('<img src="'+base_url+'public/images/ie6/uk-map-'+$(this).attr('class')+'.jpg" id="ie6_map_large" />');
			}
	   	}, 
	    function () {
	    	$('#uk_map_large_hover').removeClass($(this).attr('class'));
			if($(this).parent().attr('id') == 'uk_map_large_map') { $('#area_links_large a').removeClass('selected'); }
			
			if($.browser.msie && ($.browser.version == 6.0)) { $('#ie6_map_large').remove(); }
	    }
	);
	
	// Small UK Map
	$("#small_map_holder .areas a, #uk_map_small_map area").hover(
		function () {
	   		$('#uk_map_small_hover').addClass($(this).attr('class'));
			if($(this).parent().attr('id') == 'uk_map_small_map') { $('#small_map_holder .areas a.'+$(this).attr('class')).addClass('selected'); }
			
			if($.browser.msie && ($.browser.version == 6.0)) {
				$('#uk_map_small').prepend('<img src="'+base_url+'public/images/ie6/small-uk-map-'+$(this).attr('class')+'.jpg" id="ie6_map_small" />');
			}
	   	}, 
	    function () {
	    	$('#uk_map_small_hover').removeClass($(this).attr('class'));
			if($(this).parent().attr('id') == 'uk_map_small_map') { $('#small_map_holder .areas a').removeClass('selected'); }
			
			if($.browser.msie && ($.browser.version == 6.0)) { $('#ie6_map_small').remove(); }
	    }
	);
	
	// Hover for submit button
	$("#sort_by_form input").hover(
		function () { $(this).attr({src: base_url+'public/images/submit-button-hover.gif'}); }, 
	    function () { $(this).attr({src: base_url+'public/images/submit-button.gif'}); }
	);
	
	// Great Days Out Results Table
	$("#results_table tr").hover(
		function () { $(this).addClass('hover'); }, 
	    function () { $(this).removeClass('hover'); }
	);
	
	$("#results_table tr").click(function () {
		var $link = $(this).children('.attraction').children('a');
		location.href = $link.attr('href');
	});
	
	// Great Days Out open form
	$(".print_voucher_button.greatDaysOut").click(function () {
//DISABLE
		$("#shadowbox_body").css({marginTop: '0'}).removeClass('white_border');
		
		Shadowbox.open({
			player:     'iframe',
		    content:    $(this).attr('href'),
			height:     475,
		    width:      634,
			title: 		'&nbsp;'
		});
		
		return false;
	}); 
	
	// Exclusive Offers roll-overs
	$('#select_offer a').hover(
		function () {
			$('#more_great_offers .right_column').show();
		},
		function () {
			$('#more_great_offers .right_column').hide();
		}
	);
	
	// Exclusive Offers open form
	$(".print_voucher_button.moreGreatOffers").click(function () {
//DISABLE
		$("#shadowbox_body").css({marginTop: '0'}).removeClass('white_border');
		
		Shadowbox.open({
			player:     'iframe',
		    content:    $(this).attr('href'),
			height:     475,
		    width:      664,
			title: 		'&nbsp;'
		});
		
		return false;
	}); 
	
	// FAQs sliders
	$("#faqs a.link").click(function () {
		
		var openSlider = !$(this).hasClass('selected');
		
		$('.sliderOpen').slideUp().removeClass('sliderOpen');
		$('#faqs .button').html('Open');
		$('#faqs a').removeClass('selected');
		
		if(openSlider) {
			$(this).next().slideDown().addClass('sliderOpen');
			$(this).children('.button').html('Close');
			$(this).addClass('selected');
		}
		
		return false;
	});
	
	// Tell a Friend Form
	$("#tell_a_friend .submit_button").click(function () {
		
		var id = '';
		var errors = '';
		
		$("#tell_a_friend .error").removeClass('error');
		$("#errors ul").html('');
		
		$("#tell_a_friend .required").each(function() 
		{
			if($(this).attr('value') == '') 
			{
				id =  $(this).attr('id');
				id = id.substr(4);
				id = id.replace('_', ' ').replace('_', ' ').replace('_', ' ').replace('_', ' ').replace('_', ' ');
				 
				errors = errors+'<li>'+id+'</li>'; 
				$(this).addClass('error');
			}
		});
		
		if(errors == '')
		{
			$("#errors").hide();
			
			//if(confirm('DO SOME PROPER AJAX STUFF'))
			//{
				// location.href = $(this).attr('href');
			//}

			$('#tell_a_friend form').submit();
		}
		else
		{
			$("#errors ul").append(errors);
			
			$("#errors").slideDown();
		}
		
		return false;
	});
	
});

$(function() {
	closeToHomePage = function() {
		$('#shadowbox_nav_close, #shadowbox_title_inner').click(function(){
			window.location.href = base_url;
			return false;
		});
	};
});

function innerCloseToHomePage() {
	$("#shadowbox_container", top.document).fadeOut(function() {
		window.parent.location = base_url; 
	});
}