/*LOAD*/
/*var page = $_GET('page');
var section = $_GET('section');
var id = $_GET('id');
var position = $_GET('position');
function $_GET(q,s) {
	s = (s) ? s : window.location.search;
	var re = new RegExp('&'+q+'=([^&]*)','i');
	return (s=s.replace(/^\?/,'&').match(re)) ? s=s[1] : s='';
}*/
//alert("loaded")
$(document).ready(function() {
	if(!section || section == ""){
		section = "home";
		$("html").addClass("landing");
		$('#promo').load('pages/home.php');
		$('#right').hide();
		$('#comments').hide();
		$('#footer').hide();
		$('#navigation').hide();
	}else if(section == "msShift"){
		if(profile){
			//alert(profile)	
			window.location = 'http://www.shiftmx.com/us/msShift#/profiles/'+profile;
		}
		$.address.change(swap);
		$('#right').hide();
		$('#comments').hide();
		$('#main').load('pages/msShift.php', function(){
			$(".msShift input, .msShift textarea, .msShift select,.msShift  button").uniform();
			loadNav();
		});
	}else if(section == "rideClub"){
		$.address.change(swap);
		$('#right').hide();
		$('#comments').hide();
		$('#main').load('pages/rideClub.php', function(){
			$(".rideClub .checkbox").uniform();
			loadNav();
		});
	}else{
		loadsection();
		$('#right').show();
		loadNav();
	}
});
function loadNav(){
	if(section != "" && section != "home"){
		//$('#navigation').hide()
		$('#navigation').load('includes/navigation.php',function() {
				setTimeout(function(){$('#navigation').show();}, 2000 );
				if(section == "msShift" || section == "rideClub"){
					$('#includes').load('pages/msshift/includes.php');
				}
		});
	}
	//$('#promo').load('sections/promo.php');
	$('#footer').load('includes/footer.php');
	$('#right').load('includes/right.php?section='+section);
}
function loadsection(){
	if(section!="home" || id != ""){
		$('#promo').hide();
		if(id != ""){
			$('#comments').show();
		}else if(section != "syndicate"){
			$('#comments').hide();
		}
	}else{
		$('#promo').show();
	}
	$('#main').load('pages/'+section+'.php?id='+id+'&page='+page+'&position='+position+'&request='+request, function(){
		$('a[rel^=lightbox]').lightBox();
		//loadNav();
	});
}

function reload_image(new_src){
	//document.getElementById('image_src').href = new_src;
	$('#image_src').attr('href',new_src)
}
//MS SHIFT//
function checkAge(){
	if($('#ageVerify').is(':checked')){
		window.location = "verified.php";
	}else{
		alert("Please confirm you are over 18!");
	}
}
function swap(e){
	if(e){
		var loc = e.pathNames.toString();
		loadSub(loc);
	}else{
		loadSub("welcome");
	}
}
/*NEW PAGE*/
function loadSub(page){
	$('#main').html("<div class='preloader'><img src='css/images/preloader.gif'></div>");
	if(!page){page = "welcome"};
	var arr = page.split(",");
	var newDate = new Date;
	var uni = newDate.getTime();
	var params = '?uni='+uni+'&page='+arr[0];
	if(arr[1]){
		params += '&id='+arr[1];
	}
	$('#main').load('pages/'+section+'.php'+params, function() {
		//$('#main').fadeIn(500);
	})
}
function rate(num, id){
	$.post("pages/msshift/profiles.php", { rate:"y", id:id, num:num },
	   function(data) {
		 $('#starContainer').html(data);
		 getStars(id);
   });
}
function getStars(id){
	$('#starContainer').html('Calculating...');
	var newDate = new Date;
	var uni = newDate.getTime();
	$('#starContainer').load('pages/msshift/profiles.php?starRating='+id+'&uni='+uni);
}
function getMiniStars(id){
	$('#starContainer').html('Calculating...');
	var newDate = new Date;
	var uni = newDate.getTime();
	$('#starContainer').load('pages/msshift/profiles.php?starRating='+id+'&uni='+uni);
}
function setStars(average){
	var remainder = average.split(".")[1];
	for(i=1; i<=6; i++){
		if(i <= Math.floor(average)){
			//DO NOTHING
		}else if(i == Math.ceil(average)){
			if(remainder.length >1){
				divider = 100;
			}else{
				divider = 10;
			}
			var perc = Math.round(29 * (remainder/divider));
			//alert('remaining = '+remainder+' and % = '+perc)
			$('#'+i+'_star .starCover').css("width", perc+'px');
		}else{
			$('#'+i+'_star .starCover').css("width",'0px');
		}
		
	}
}
function rsvp(id){
	//loadCatalog(300,450,'pages/rideClub/form.php?event='+id+'&interest=Spectator');
	var w = 300;
	var h = 450;
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	if(navigator.appName == 'Microsoft Internet Explorer'){
		window.open('pages/rideClub/form.php?event='+id+'&interest=Spectator')
	}else{
		var targetWin = window.open ('pages/rideClub/form.php?event='+id+'&interest=Spectator', 'Register to Attend', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
	}
}
function race(id){
	//loadCatalog(300,450,'pages/rideClub/form.php?event='+id+'&interest=Rider');
	window.location = '#/race/'+id;
}
function getTerms(){
	$('html').scrollTop(700)
}
