// JavaScript Document
var map;
var edmonton;
var calgary;
var whitby;
var cambridge;
$(document).ready(function(){
if (window.screen.availWidth <= 800){
	window.location = "http://www.reliable-tube.com/mobile/";	
}
	
	
	$('#slideshow').cycle({
		fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	$("#contactlinks img").mouseover(function(){
		$("#contactlinks img").not(this).stop().animate({
			opacity: '.4'												  
		},400);
		$(this).stop().animate({
			opacity: '1'
		},400);
		var id = $(this).attr('id');
		//show this items mappeg
		$("#map img").each(function(){
			if (($(this).attr('src') != '../images/maptip_'+id+'.png') && ($(this).attr('src').substr(0,17)=='../images/maptip_')){
				$(this).fadeOut(400);
			}
			if ($(this).attr('src') =='../images/maptip_'+id+'.png'){
				$(this).fadeIn(400);	
			}
		});
		
		$("#contact_info div").each(function(){
			if ($(this).attr('id') != id+'_contact'){
				$(this).fadeOut(200);
			}else{
				$(this).fadeIn(200);
			}
		});	
	});
	
	if ($("#map").length){
		initialize();	
	}
	
	
});

function initialize() {
	var latlng =  new google.maps.LatLng(51.62, -95.9);
	var myOptions = {
		zoom: 4,
	    center: latlng,
	    mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	map = new google.maps.Map(document.getElementById("map"),myOptions);

	var img = "../images/maptip.png";
	
	markerOptions = { icon: img, setMap: 'map'};
	var latlng = new google.maps.LatLng(53.54318, -113.77456);

	edmonton = new google.maps.Marker({
		position: latlng,
		map: map,
		icon: '../images/maptip_edmonton.png',
		clickable: false
	});
	
	latlng = new google.maps.LatLng(51.01223, -113.97633);
	calgary = new google.maps.Marker({
		position: latlng,
		map: map,
		icon: '../images/maptip_calgary.png',
		clickable: false
	});
	
	latlng = new google.maps.LatLng(43.40184, -80.30158);
	cambridge = new google.maps.Marker({
		position: latlng,
		map: map,
		icon: '../images/maptip_cambridge.png',
		clickable: false
	});
	
	latlng = new google.maps.LatLng(43.86073, -78.92280);
	whitby = new google.maps.Marker({
		position: latlng,
		map: map,
		icon: '../images/maptip_whitby.png',
		clickable: false
	});
	//show this items mappeg
	hideTips();
}
function hideTips(){
	$("#map img").each(function(){
		if ($(this).attr('src').substr(0,17)=='../images/maptip_'){
			$(this).css('display','none');
		}
	});
}

function validateEmail(email) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) {
		return false;
	}else{
		return true;	
	}
}
function submitEmail(){
	if (validateEmail($("#email").val())){
		$.ajax({
			url: 'ajax/addsubscriber.php',
			data: 'email='+$("#email").val(),
			type: 'post',
			success: function(data){
				if (data=='ok'){
					$("#emailform").fadeOut(300,function(){
						$(this).html("<p>Thank you for registering!</p>").fadeIn(300);										 
					 });
				}			
			}
		});
	}else{
		alert("Please enter a valid email address.");	
	}
}
