function backToMainImage($mainImage){
	$('.heroImage img').attr('src',$mainImage);
	//$('#mainImageBack').css({'display' :'none'});
}
	
$(function(){
	var $mainImage = $('.heroImage img').attr('src');
	var heroHeight = $('.heroImage img').height();
	var heroWidth = $('.heroImage img').width();
	var smallHeight = "";
	var smallWidth = "";
	
	//$('.heroImage .image span').append('<div id="mainImageBack" style="display: none; text-align: right;"><a href="#" style="text-align: right;" class="menu menuID775" onclick="backToMainImage(); return false;">Back to main image</a></div>');
	$('img',$('.mainImageBack')).bind('click',function(){backToMainImage($mainImage);})
	$('img',$('#div27523')).bind('click',function(){
		$tinysrc = $(this).attr('src');
		//default image in the /img folder
		if($tinysrc.indexOf('/img')!=-1) return false;
		$alt = $(this).attr('alt');
		$title = $(this).attr('title');
			
		smallHeight = $(this).height();
		smallWidth =  $(this).width();
		heroHeight = $('.heroImage img').height();
		heroWidth = $('.heroImage img').width();
		$bigsrc = $tinysrc.replace('width:'+smallWidth,'width:'+heroWidth).replace('height:'+smallHeight,'height:'+heroHeight);
		
		$img = $('<img src="'+$bigsrc+'" alt="'+$alt+'" title="'+$title+'" style="border: none;"/>');
		//console.debug($img);
		//console.debug('img',$mainImage);
		$('.heroImage img').after($img).remove();
		//$('#mainImageBack').css({'display' :'block'});
		$('.heroImage img')[0].scrollIntoView(true);
	})
	$('img',$('.mainImageBack')).css({'cursor':'hand','cursor':'pointer'});
	$('img',$('#div27523')).css({'cursor':'hand','cursor':'pointer'});
	
	$('img',$('.mainImageEnlarge')).css({'cursor':'hand','cursor':'pointer'});
	$('.image img',$('#div37523')).css({'cursor':'hand','cursor':'pointer'});
	
	$('img',$('.mainImageEnlarge')).bind('click',function(){
		
		heroHeight = $('.largeImage img').height();
		heroWidth = $('.largeImage img').width();
		$tinysrc = $('.largeImage img').attr('src');
		$bigsrc = $tinysrc.replace('width:'+heroWidth,'width:600').replace('height:'+heroHeight,'height:379');
		alt =  $('img',$('.heroImage')).attr('alt');
		var a = $('<a href="'+$bigsrc+'" rel="lytebox" title="'+alt+'"></a>');
		//console.debug(a);
		try{
			myLytebox.start(a[0],false,false);
		}
		catch(e){}
	});
	
	$('.image img',$('#div37523')).bind('click',function(){

		$tinysrc = $(this).attr('src');
		smallHeight = $(this).height();
		smallWidth =  $(this).width();
		alt =  $(this).attr('alt');
		$bigsrc = $tinysrc.replace('width:'+smallWidth,'width:600').replace('height:'+smallHeight,'height:200');

		var a = $('<a href="'+$bigsrc+'" rel="lytebox" title="'+alt+'"></a>');
		//console.debug(a);
		try{
			myLytebox.start(a[0],false,false);
		}
		catch(e){}
	});
	$('.enlargeSwatch').css({'cursor':'hand','cursor':'pointer'});
	$('.enlargeSwatch').bind('click',function(){
		//console.debug($('.image',$(this).parent().parent()));
		$('img',$('.image',$(this).parent().parent())).trigger('click');
	});
	
	$('.boxingBanner a').addClass('iframe');
	$('.boxingBanner a').attr('title','Complete this form to print your 50 pound voucher');
	$('.boxingBanner a').fancybox({
		frameWidth : 950,
		frameHeight : 450
	});
});

/*
Moved this to just above the /body tag to make sure it is fired early
$(function(){
	//preload
   $('img.rollover').each(function(){
		$img = $("<img>").attr("src", $(this).attr('src'));
		console.debug($img);
	});
   
	$('img.rollover').bind('mouseover',function(){
		$jsonRaw = eval('jsonRollover = '+$(this).attr('longdesc'));
		//console.debug($jsonRaw.rollover);
		$(this).attr('src',$jsonRaw.rollover);
	});
	$('img.rollover').bind('mouseout',function(){
		$jsonRaw = eval('jsonRollover = '+$(this).attr('longdesc'));
		//console.debug($jsonRaw.rollout);
		$(this).attr('src',$jsonRaw.rollout);
	});
	
});*/

$(function(){
		   
		   if($('.accordionHeader').length)
		   {
			   $('.accordionHeader').each( function(){
											
						classes = $(this).parent()[0].className.split(" ");
					
						groupGlass = classes[classes.length - 1];											
						if(groupGlass.indexOf("group") > -1)
						{
							$(this).bind('click',function() { 
								  classes = $(this).parent()[0].className.split(" ");

									groupGlass = classes[classes.length - 1];		

									$parent= $(this).parent()[0];
									
									if($('.'+groupGlass).not($(this).parent()).parent().is(':hidden'))
									{
										$('.'+groupGlass).not($(this).parent()).parent().show('slow')
										//$('.'+groupGlass).not($(this).parent()).parent().slideDown('slow')
									}
									else
									{
										//$('.'+groupGlass).not($(this).parent()).parent().hide('slow')
										$('.'+groupGlass).not($(this).parent()).parent().slideUp('slow')
									}
								})
						}
						
				})
		   }
										   
		   
		   });

$(function(){
		   
		   $('.submit',$('.printDiv')).bind('click', checkFormInput );
				
		   }
		   )

var checkFormInput = function()
{
	
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	var alphaPattern = /^[a-zA-Z .']+$/;
	var alphaNumericPattern = /^[ a-zA-Z0-9 '$%^&*()!"@#~.,]/;
	var numerialPattern = /^[0-9]+$/;
	var formValue = true;
	itemValid = false;
	errorMessage = "";

	$('.formItem').each( function() { 
					itemValid = false;
				
					if(($(this).is('.required') && ($(this).val() != null) || $(this).val() != ""))
					{
						if($(this).is('.alphabetical'))
						{
							itemValid = alphaPattern.test($(this).val())
							if(itemValid == false)
							{
								label = $("label[for='"+$(this).attr("id")+"']").html() 
								errorMessage = errorMessage + "Only letters are allowed for '" + label + "'\n\r"
							}
						}
						else if($(this).is('.numerical'))
						{
							itemValid = numerialPattern.test($(this).val())
							
							if(itemValid == false)
							{
								label = $("label[for='"+$(this).attr("id")+"']").html() 
								errorMessage = errorMessage + "Only numbers are allowed for '" + label + "'\n\r"
							}
						}
						else if($(this).is('.emailaddress'))
						{
							itemValid = emailPattern.test($(this).val())
							
							if(itemValid == false)
							{
								label = $("label[for='"+$(this).attr("id")+"']").html() 
								
								errorMessage = errorMessage + "Please eneter a valid email address for '" + label + "'\n\r"
							}
						}
						else if($(this).is('.alphanumerical'))
						{
							itemValid = alphaNumericPattern.test($(this).val())
							if(itemValid == false)
							{
								label = $("label[for='"+$(this).attr("id")+"']").html() 
								errorMessage = errorMessage + "Invalid character in '" + label + "'\n\r"
							}
						}
						else
						{
							itemValid = true;	
						}
					}
					else
					{
						label = $("label[for='"+$(this).attr("id")+"']").html() 
						errorMessage = errorMessage+ "'"+ label + "' requires a input\n\r"	
					}
					theID = $(this).attr("id");
					
					if(itemValid == false)
					{
						formValue = false;
						$("label[for='"+theID+"']").css({"color":"#ff0000"})
					}
					else
					{
						$("label[for='"+theID+"']").css({"color":null})
					}				
				})	
	if(formValue != true)
	{
		alert(errorMessage);
		return false;
	}
	
	
}

$(function(){
		   //google map
			if($('.googleMapDiv').length){
				//http://maps.google.co.uk/?ie=UTF8&ll=53.473335,-2.232971&spn=1.034793,3.570557&z=9
				createLocationsMapFromXml(53.5156756, -2.9455352, 7, '/library/mapmarkers.xml');
				$('.googleMarkerControl').bind('click',function(){ 
														namedMarkers[$(this).attr('id')].openInfoWindowHtml($(this).html());
														}
												);	
				//console.debug(gmap);
			}
})



$(function(){
		   $('.flashMovie_58414-19').bind('click',function(){
				///library/flashElements/Home Page/new york csl tv advert.swf				
				var a = document.createElement("a");
				a.href = '/library/flashElements/Homepage/robots advert.swf';
				a.rel = "lyteframe";
				a.title = "Robots Tv Advert";
				a.rev = "width: 886; height: 500px; scrolling: none;";
				myLytebox.start( a, false, true);
			})
		   
		   	$('.flashMovie_53200-20').bind('click',function(){
				///library/flashElements/Home Page/new york csl tv advert.swf				
				var a = document.createElement("a");
				a.href = '/library/flashElements/Homepage/new york advert.swf';
				a.rel = "lyteframe";
				a.title = "New York Tv Advert";
				a.rev = "width: 888; height: 500px; scrolling: none;";
				myLytebox.start( a, false, true);
			})
});

