﻿// PRELOAD ROLLOVER IMAGES
// -----------------------
if (document.images) {
	img1 = new Image();
	img1.src = "images/stables_button-on.jpg";
	img2 = new Image();
	img2.src = "images/hospital_button-on.jpg";
	img3 = new Image();
	img3.src = "images/labs_button-on.jpg";
	img4 = new Image();
	img4.src = "images/news_button_bg-on.jpg";
	img5 = new Image();
	img5.src = "images/navbar_bgs/about_us.jpg";
	img6 = new Image();
	img6.src = "images/navbar_bgs/education.jpg";
	img7 = new Image();
	img7.src = "images/navbar_bgs/internships.jpg";
	img8 = new Image();
	img8.src = "images/navbar_bgs/referrals.jpg";
	img9 = new Image();
	img9.src = "images/navbar_bgs/services.jpg";
	img10 = new Image();
	img10.src = "images/navbar_bgs/visitors.jpg";
	img11 = new Image();
	img11.src = "images/news/news_arrow_back-over.gif";
	img12 = new Image();
	img12.src = "images/news/news_arrow_next-over.gif";
	img13 = new Image();
	img13.src = "images/news/news_arrow2_back-over.gif";
	img14 = new Image();
	img14.src = "images/news/news_arrow2_next-over.gif";
	img15 = new Image();
	img15.src = "images/open_nav_icon.gif";
	img16 = new Image();
	img16.src = "images/closed_nav_icon.gif";
}


// POPUP WINDOW
// ------------
function createWindow(page, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'width='+w+',height='+h+',top='+wint+',left='+winl+',scrollbars=no';
	newwindow = window.open(page,'name',winprops);
	return false;
}


// POPUP INFO FOR PARTNERS PAGE
// ----------------------------
function show_partner_popup(div_class) {
	// create array of <div> classes	
	var mydivs = document.getElementById('partners_info').getElementsByTagName('div');
	// foreach <div>
	for(var i = 0; i < mydivs.length; i++) {
		// if div_class provided and matches current <div> - make <div> visible
		if (div_class != null & mydivs[i].className == div_class) mydivs[i].style.display = 'block';
		else mydivs[i].style.display = 'none';		// else - hide it
	}
	return false;
}


// SIDE NAV MENU
// -------------
function treeclick(a) {
    var curr_status = a.parentNode.className;
    
    // create array of <li> classes
	var mylis = document.getElementById('side_nav').getElementsByTagName('li');
	// hide all <li>s
	for(var i = 0; i < mylis.length; i++) {
		if(mylis[i].className = 'open') mylis[i].className = 'closed';
	}
	
    if(curr_status == 'open') a.parentNode.className = 'closed';
    else a.parentNode.className = 'open';
    return false;
}


// CHANGE SEARCH RESULTS PAGE
// --------------------------
function change_search_results(div_class) {
	
	// create array of <div> tags within #search_results	
	var mydivs = document.getElementById('search_results').getElementsByTagName('div');
	// foreach <div>
	for(var i = 0; i < mydivs.length; i++) {
		// if div_class provided and matches current <div> - make <div> visible
		if (div_class != null & mydivs[i].className == div_class) mydivs[i].style.display = 'block';
		else if (mydivs[i].className == 'nav') mydivs[i].style.display = 'block';
		else mydivs[i].style.display = 'none';		// else - hide it
	}
	
	return false;
}




// jQUERY STUFF

// fading/animated photos - used on all pages
function fading_photos(container_id, total_images, img_path) {
	var img_extension = ".jpg";
	var i = 1;
	
	// insert first image
	$('<img src="' + img_path + i + img_extension + '" class="pic' + i + '" />').appendTo(container_id).show();
	i++;
	
	// every 5 seconds - run the change_photo function
	setInterval(change_photo, 6000);

	function change_photo() {
		
		if(i > total_images) {
			i = 1;
			current_img = 1;
		}
		else current_img = i;
		
		if(current_img == 1) last_img = total_images;
		else last_img = (current_img - 1);
		
		// fade in the new image
		$('<img src="' + img_path + current_img + img_extension + '" class="pic' + current_img + '" />').appendTo(container_id).fadeIn(1500);
		// fade out + remove the existing image
		$(container_id + ' img.pic' + last_img).fadeOut(1500, function() {
			$(container_id + ' img.pic' + last_img).remove();
		});
		
		i++;
	
	}
}




// GOOGLE MAPS

var infowindow;

(function () {

})();

function initialize() {

	google.maps.Map.prototype.markers = new Array();
	
	google.maps.Map.prototype.addMarker = function(marker) {
		this.markers[this.markers.length] = marker;
	};

	var latlng = new google.maps.LatLng(52.259437, 0.393791);
	var myOptions = {
		zoom: 12,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	map = new google.maps.Map(document.getElementById("googlemaps_canvas"), myOptions);
	
	var myLats = new Array();
	var myLngs = new Array();
	var myContents = new Array();
	
	myLats[0] = 52.244316;
	myLngs[0] = 0.401838;
	myContents[0] = '<div id="googlemaps_infowindow"><strong>Beaufort Cottage Stables and Beaufort Cottage Laboratories</strong><br/>';
	myContents[0] = myContents[0] + '<a href="http://www.rossdales.com/downloads/rossdales_dir_newmarket.pdf">get directions</a></div>';
	/* myContents[0] = '<div id="googlemaps_infowindow"><h1>Beaufort Cottage Stables &amp; Beaufort Cottage Laboratories</h1>';
	myContents[0] = myContents[0] + '<img src="http://www.rossdales.com/image_uploads/stables_reception_th.jpg" />';
	myContents[0] = myContents[0] + '<p>High Street <br/>Newmarket <br/>Suffolk CB8 8JS</p>';
	myContents[0] = myContents[0] + '<p><a href="http://www.rossdales.com/downloads/rossdales_dir_newmarket.pdf">get directions</a></p></div>'; */
	
	myLats[1] = 52.270271;
	myLngs[1] = 0.37324;
	myContents[1] = '<div id="googlemaps_infowindow"><strong>Rossdales Equine Hospital and Diagnostic Centre</strong><br/>';
	myContents[1] = myContents[1] + '<a href="http://www.rossdales.com/downloads/rossdales_dir_exning.pdf">get directions</a></div>';
	/* myContents[1] = '<div id="googlemaps_infowindow"><h1>Rossdales Equine Hospital &amp; Diagnostic Centre</h1>';
	myContents[1] = myContents[1] + '<img src="http://www.rossdales.com/image_uploads/exning_entrance_th.jpg" />';
	myContents[1] = myContents[1] + '<p>Cotton End Road <br/>Exning <br/>Newmarket <br/>Suffolk CB8 7NN</p>';
	myContents[1] = myContents[1] + '<p><a href="http://www.rossdales.com/downloads/rossdales_dir_exning.pdf">get directions</a></p></div>'; */
	
	for (var i = 0; i < myLats.length; i++) {
		var latlng = new google.maps.LatLng(myLats[i], myLngs[i]);
		map.addMarker(createMarker(myContents[i], latlng));
	}
	
}
	
function createMarker(name, latlng) {
	var marker = new google.maps.Marker({
		position: latlng,
		map: map
	});
	
	google.maps.event.addListener(marker, "click", function() {
		if (infowindow) infowindow.close();
		infowindow = new google.maps.InfoWindow({content: name});
		infowindow.open(map, marker);
	});
	
	return marker;
}