function initialize() {
    var myLatlng = new google.maps.LatLng(55.3119222, -4.8317552);
    var myOptions = {
      zoom: 15,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("header"), myOptions);
	
	var image = 'http://www.turnberryresort.co.uk/assets/no-index/attraction_icon/propertyIcon.png';
    var myLatLng = new google.maps.LatLng(55.3119222, -4.8317552);
    var beachMarker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: image
    });

}


$(function(){
	
	$('#main_search_box').focus(function(){
		if($(this).val()=='Search'){
			$(this).val('');
		}
	});
	
	$('#main_search_box').blur(function(){
		if($(this).val()==''){
			$(this).val("Search");
		}
	});
	
	$('#main_search_box').keypress(function(event){
		if(event.which == '13') {
			window.location.href='http://turnberry.co.uk/search?q='+$(this).val();
		}
	});
		   
	$('.items').mouseover(function(){
		$(this).siblings('.selected').removeClass('selected').addClass('unselected');
		$(this).removeClass('unselected').addClass('selected');
		$(this).siblings('.cur').removeClass('unselected');
	});
	
	$('.items').mouseout(function(){
		
	});
	
	$('#submit').click(function(){
		var title = $('#title').val();
		var name = $('#name').val();
		var email = $('#email').val();
		var reemail = $('#reemail').val();
		var contact = $('#contact').val();
		var callme = $('#callme').is(':checked');
		var emailme = $('#mailme').is(':checked');
		var guests = $('#guests').val();
		var nights = $('#nights').val();
		var zone = $('#zone').val();
		var arrdate = $('#arrdate').val();
		
		if(!name){
			alert('Please enter your name.');
			return false;
		}
		
		if(email != reemail || !email) {
			alert('Please enter your E-mail address correctly.');
			return false;
		}
		
		var datastring = 'title='+title + '&name='+ name + '&email=' + email + '&reemail=' + reemail + '&contact=' + contact + '&callme=' + callme + '&emailme=' + emailme + '&guests=' + guests + '&nights=' + nights + '&zone=' + zone + '&arrdate=' + arrdate ;
		
		$.ajax({
			type: 'post',
			url: 'helper/mailer.php',
			data: datastring,
			success: function(){
				alert("You E-mail has been sent successfully");
			}
		});
	});
//////////////////////////////////////////////photo gallery//////////////////////////////////////////////////////////////
	
	$('.photo_gallery_thumb').click(function(){
		$('.cur_foto').removeClass('cur_foto');
		$(this).addClass('cur_foto');
		
		var type = $(this).attr('title');
		var val = $(this).attr('rel');
		
		var title = $(this).children('.g_title').val();
		var desc = $(this).children('.g_desc').val();
		
		var cta_text = $(this).children('.cta_text').val();
		var cta_url = $(this).children('.cta_url').val();
		
		if(type == 'video'){
			$('#photo_gallery_image').html('<embed width="550" height="310" src="http://www.youtube.com/v/'+ val+ '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent">');
		}else{
			$('#photo_gallery_image').html('<img width="550" height="310" title="'+ title +'" alt="'+ title +'" src="http://www.turnberry.co.uk/assets/u/' + val + '">');
		}
		
		$('#photo_gallery_title').html(title);
		$('#photo_gallery_copy').html(desc);
		$('#photo_cta_button').html(cta_text);
		$('#photo_cta_button').attr('href', cta_url);		
	});
	
	
	$('.photo_gallery_page').click(function(){
		$('.photo_gallery_thumbs').hide();
		var page = $(this).attr('title');
		
		$('#photo_gallery_thumbs_' + page).show();
		$('.cur_foto').removeClass('cur_foto');
		$('#photo_gallery_thumbs_' + page).children('.photo_gallery_thumb:first').addClass('cur_foto');
		$(this).addClass('cur_page');
		
		var type = $('.cur_foto').attr('title');
		var val = $('.cur_foto').attr('rel');
		
		var title = $('.cur_foto').children('.g_title').val();
		var desc = $('.cur_foto').children('.g_desc').val();
		
		var cta_text = $('.cur_foto').children('.cta_text').val();
		var cta_url = $('.cur_foto').children('.cta_url').val();
		
		if(type == 'video'){
			$('#photo_gallery_image').html('<embed width="550" height="310" src="http://www.youtube.com/v/'+ val+ '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent">');
		}else{
			$('#photo_gallery_image').html('<img width="550" height="310" title="'+ title +'" alt="'+ title +'" src="http://www.turnberry.co.uk/assets/u/' + val + '">');
		}
		
		$('#photo_gallery_title').html(title);
		$('#photo_gallery_copy').html(desc);
		$('#photo_cta_button').html(cta_text);
		$('#photo_cta_button').attr('href', cta_url);
		
		$('.cur_page').removeClass('cur_page');
		$(this).addClass('cur_page');
		
	});
	
	$('#cate').change(function(){
		var dataString = 'category=' + $('#cate').val();
		$.ajax({
			type:'post',
			url: 'ajax/get_gallery.php',
			data: dataString,
			success: function(content){
				$('#gallery_content').html(content);
				
				$('#pv').children().first().attr('selected', 'selected');
				
				if(content != ""){
					var type = $('#photo_gallery_thumb_0').attr('title');
					var val = $('#photo_gallery_thumb_0').attr('rel');
					
					var title = $('#photo_gallery_thumb_0').children('.g_title').val();
					var desc = $('#photo_gallery_thumb_0').children('.g_desc').val();
					
					var cta_text = $('#photo_gallery_thumb_0').children('.cta_text').val();
					var cta_url = $('#photo_gallery_thumb_0').children('.cta_url').val();
					
					if(type == 'video'){
						$('#photo_gallery_image').html('<embed width="550" height="310" src="http://www.youtube.com/v/'+ val+ '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent">');
					}else{
						$('#photo_gallery_image').html('<img width="550" height="310" title="'+ title +'" alt="'+ title +'" src="http://www.turnberry.co.uk/assets/u/' + val + '">');
					}
			
					$('#photo_gallery_title').html(title);
					$('#photo_gallery_copy').html(desc);
					$('#photo_cta_button').html(cta_text);
					$('#photo_cta_button').attr('href', cta_url);
				}else{
					$('#photo_gallery_image').html('');
					$('#photo_gallery_title').html('');
					$('#photo_gallery_copy').html('');
					$('#photo_cta_button').html('');
					$('#photo_cta_button').attr('');
					
				}
			}
			
		});
	});
	
	$('#pv').change(function(){
		var dataString = 'pv=' + $('#pv').val() + '&category=' + $('#cate').val();
		
		$.ajax({
			type:'post',
			url: 'ajax/get_gallery.php',
			data: dataString,
			success: function(content){
				$('#gallery_content').html(content);			
				
				if(content != ""){
					var type = $('#photo_gallery_thumb_0').attr('title');
					var val = $('#photo_gallery_thumb_0').attr('rel');
					
					var title = $('#photo_gallery_thumb_0').children('.g_title').val();
					var desc = $('#photo_gallery_thumb_0').children('.g_desc').val();
					
					var cta_text = $('#photo_gallery_thumb_0').children('.cta_text').val();
					var cta_url = $('#photo_gallery_thumb_0').children('.cta_url').val();
					
					if(type == 'video'){
						$('#photo_gallery_image').html('<embed width="550" height="310" src="http://www.youtube.com/v/'+ val+ '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent">');
					}else{
						$('#photo_gallery_image').html('<img width="550" height="310" title="'+ title +'" alt="'+ title +'" src="http://www.turnberry.co.uk/assets/u/' + val + '">');
					}
			
					$('#photo_gallery_title').html(title);
					$('#photo_gallery_copy').html(desc);
					$('#photo_cta_button').html(cta_text); 
					$('#photo_cta_button').attr('href', cta_url);					
				}else{
					$('#photo_gallery_image').html('');
					$('#photo_gallery_title').html('');
					$('#photo_gallery_copy').html('');
					$('#photo_cta_button').html('');
					$('#photo_cta_button').attr('');
				}
			}
			
		});
	});
	
	$('#next').click(function(){
		var index = $('.cur_foto').attr('index');
		index = parseInt(index) + 1; 
		
		$('.cur_foto').removeClass('cur_foto');
		
		if($('#photo_gallery_thumb_' + index).length != 0){
			$('#photo_gallery_thumb_' + index).addClass('cur_foto');
		}else{
			$('#photo_gallery_thumb_0').addClass('cur_foto');
		}
		
		$('.photo_gallery_thumbs').hide();
		$('.cur_foto').parent('.photo_gallery_thumbs').show();
		
		var page = parseInt($('.cur_foto').parent('.photo_gallery_thumbs').index('.photo_gallery_thumbs'));
		
		$('.cur_page').removeClass('cur_page');
		$('.photo_gallery_page:eq('+ page +')').addClass('cur_page').show();
		
		var type = $('.cur_foto').attr('title');
		var val = $('.cur_foto').attr('rel');
		
		var title = $('.cur_foto').children('.g_title').val();
		var desc = $('.cur_foto').children('.g_desc').val();
		
		var cta_text = $('.cur_foto').children('.cta_text').val();
		var cta_url = $('.cur_foto').children('.cta_url').val();
		
		if(type == 'video'){
			$('#photo_gallery_image').html('<embed width="550" height="310" src="http://www.youtube.com/v/'+ val+ '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent">');
		}else{
			$('#photo_gallery_image').html('<img width="550" height="310" title="'+ title +'" alt="'+ title +'" src="http://www.turnberry.co.uk/assets/u/' + val + '">');
		}
		
		$('#photo_gallery_title').html(title);
		$('#photo_gallery_copy').html(desc);
		$('#photo_cta_button').html(cta_text);
		$('#photo_cta_button').attr('href', cta_url);
		
		return false;
	});
	
	$('#prev').click(function(){
		var index = $('.cur_foto').attr('index');
		index = parseInt(index) - 1;
		
		var total =	$('.photo_gallery_thumb').length;
		var last_index = parseInt(total) - 1;

		$('.cur_foto').removeClass('cur_foto');
		
		if(index < 0){
			$('#photo_gallery_thumb_' + last_index).addClass('cur_foto');
		}else{
			$('#photo_gallery_thumb_' + index).addClass('cur_foto');
		}		
		
		$('.photo_gallery_thumbs').hide();
		$('.cur_foto').parent('.photo_gallery_thumbs').show();
		
		var page = parseInt($('.cur_foto').parent('.photo_gallery_thumbs').index('.photo_gallery_thumbs'));
		
		$('.cur_page').removeClass('cur_page');
		$('.photo_gallery_page:eq('+ page +')').addClass('cur_page').show();
		
		
		var type = $('.cur_foto').attr('title');
		var val = $('.cur_foto').attr('rel');
		
		var title = $('.cur_foto').children('.g_title').val();
		var desc = $('.cur_foto').children('.g_desc').val();
		
		var cta_text = $('.cur_foto').children('.cta_text').val();
		var cta_url = $('.cur_foto').children('.cta_url').val();
		
		if(type == 'video'){
			$('#photo_gallery_image').html('<embed width="550" height="310" src="http://www.youtube.com/v/'+ val+ '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent">');
		}else{
			$('#photo_gallery_image').html('<img width="550" height="310" title="'+ title +'" alt="'+ title +'" src="http://www.turnberry.co.uk/assets/u/' + val + '">');
		}
		
		$('#photo_gallery_title').html(title);
		$('#photo_gallery_copy').html(desc);
		$('#photo_cta_button').html(cta_text);
		$('#photo_cta_button').attr('href', cta_url);		
		
		return false;
	});
});
