// JavaScript Document
//some global variables -- the url of site, boundaries for bouncing ball, arrray of pages and states and default leftSide text.
var BASEURL = 'http://' + window.location.hostname + '/';
if(BASEURL == SECURE) {
	BASEURL = GREENWAY;
}
/*var leftWall = '';
var rightWall = '';
var ceiling = '';
var bottom = '';
var ball = '';
var ballWidth = '';*/
var pages = new Array();
//var union = new Array();
var leftContentDefault = '<span class="copy">Select a state to find a dealer and other information specific to that state.</span>';

//more globals -- for controlling the location, speed, movment and gravity effecting the ball.
/*var vx = 20;
var vy = 2; //vertical velocity
var x = 1100; //starting x coordinate of the ball
var y = 75; //starting y coordinate of the ball
var g = 4;
var r = 0;
var q = 0;
var bounces = 0;*/

//function to move the ball
/*function moveBall() {
	//change vertical velocity by vertical velocity times the gravity
	vy = vy + g;

	//some extra variables for storing the previous location of the ball
	r = q;
	q = y;

	//tells the function what to do if the ball stops at the bottom of the header
	if(y == r && y > bottom)
		return;

	//change the location of the ball
	x = x - vx;
	y = y + (vy / 3);

	//perform several tests to keep the ball on the screen and make it bounce off the edges by inverting the velocities
	//test the left edge
	if(x < leftWall) {
		x = leftWall;
		vx = -vx;
	}

	//test the right edge
	if(x > rightWall) {
		x = rightWall;
		vx = -vx;
	}

	//test the bottom
	if(y > bottom) {
		y = bottom;
		vy = -vy;
		bounces++;
	}

	//test the top
	if(y < ceiling) {
		y = ceiling;
		vy = Math.abs(vy);
	}

	//move the ball to the new position based on values added from above
	ball.css('left', x);
	ball.css('top', y);

	//a simple test to stop the ball after 2 bounces and when it's x position gets to 155 on the screen, if neither has been reached call moveBall function again
	if(bounces <= 2 && x >= 80)
		window.setTimeout('moveBall()', 50);
	else
		window.setTimeout('fadeLogoIn()', 1000);
}
*/
function fadeLogoIn() {
	/*$('#ball')
		.animate({opacity: 0}, 3000, function() {
			//$(this).remove();
		});*/
	$('#logo').animate({opacity: "show"}, 3000);
}

$(function() {
	$('span.navLinks li').each(function() {
		//alert("hello");
		var curLink = this.className;
		pages.push(curLink);
		var html = '<span class="' + curLink + '"><img src="' + BASEURL +'images/roll_' + curLink + '.png"></span>';
		$('#header').append(html);
		$('#header span img').parent().hide().css('opacity', 0);
		$(this).hover(function() {
			$('#header span.' + curLink).show().animate({top: "140", opacity: 0.5}, "fast");
		}, function() {
			$('#header span.' + curLink).animate({top: "170", opacity: 0.1}, "fast", function(){
				$('#header span.' + curLink).hide();
			});
		});
	});
});

$(function() {
	var page = returnDocument();
	$('span#footerLinks > span').removeClass('hide');
	//$('#login').hide();

	if(page == "index.php") {
		$('#logo').hide();
		//Get size constraints for bouncing ball in header
		/*leftWall = $('#header')[0].offsetLeft + 30;
		rightWall = $('#header').width() - 60;
		ceiling = $('#header')[0].offsetTop + 30;
		bottom = $('#header').height() - 108;
	
		//Create the ball and set initial position
		$('#headPic').append('<div id="ball"><img src="images/golfball.png" /></div>');
		ball = $('#ball');
		ball.css({ left: x, top: y}); 
		ballWidth = ball.width();
		$('.trail').hide();
		moveBall();*/
		fadeLogoIn();

		//$('#trail').css({top: "78px", left: "190px"}).DropInRight(800);
		//$('.trail').fadeIn(10000);
		
		//Start of home page slide show
		$('#leftSideHm').crossSlide({
		  sleep: 4,
		  fade: 4,
		  shuffle: true
		}, [
		  {
			src:   'http://www.greenwaygolfanswers.com/images/slide1.png',
		  }, {
			src:  'http://www.greenwaygolfanswers.com/images/slide2.png',
		  }, {
			src:  'http://www.greenwaygolfanswers.com/images/slide3.png',
		  }, {
			src:  'http://www.greenwaygolfanswers.com/images/slide4.png',
		  }, {
			src:  'http://www.greenwaygolfanswers.com/images/slide5.png',
		  }
		]);
		//End of home page slide show
	}
	$('.bioLogicNav').jqDock({align: 'middle', labels: 'bc', duration: 100, size: 40});
	
    //Start of Biologic Manipulators	
	if(page == 'bioLogic2.php') {
		$('.blLeftBox1').width(260);
	}

	if(page == 'bioLogic3.php') {
		$('.blLeftBox1').css({backgroundColor: '#FFFFFF'});
	}

	if(page == 'bioLogic4.php') {
		$('.blLeftBox1').width(290);
		$('.blLeftBox1').css({border: 'none'});
		$('.bioRight').width(290);
	}	
	
	if(page == 'bioLogic5.php' || page =='bioLogic6.php') {
		$('.blLeftBox1').width(455);
		$('.blLeftBox1').css({border: 'none', marginRight: '0'});
		$('.bioRight').width(300);
	
	}	
	
	if(page == 'bioLogic7.php') {
		$('.blLeftBox1').width(220);
		$('.blLeftBox1').css({border: 'none'});
		$('.bioRight').width(400);
		$('.titleL').css({padding: '0'});
	}	
	
	if(page == 'benefits.php') {
		$('#rightSide').width(400);
	}
	
	if(page == 'products.php') {
		$('#content').width(760);
		$('#content').css({left: 50});
	}
	
	if(page == 'index.php') {
		$('#rightSide2').width(315);
		$('#rightSide2').css({right: -30});
	} else if(page == 'login.php') {
		$('#leftSide').css({'left': 50, 'top': 30, 'width': 326});
		$('#rightSide').css({'right': 50, 'top': 30, 'width': 326});
	}
	
	
	
});

//////////////////////////////////////////////////////////////////////////////////////////
//++++++++++++++++++++++++++++++Copywrite Disclaimer++++++++++++++++++++++++++++++++++++//
//The code below was not written by me. I was trying to use AJAX to retrieve images		//
//which would only display the binary representation. I did some searching online		//
// and found that you can't use AJAX to retrieve images, but found the function 		//
//someone had written as a elegant workaround. It did exactly want I need. I would 		//
//have given proper credit where credit is due but could not find a name associated 	//
//with its development. 																//
//++++++++++++++++++++++++++++++Copywrite Disclaimer++++++++++++++++++++++++++++++++++++//
//////////////////////////////////////////////////////////////////////////////////////////
$.fn.image = function(src, f){
	return this.each(function(){
		var i = new Image();
		i.src = src;
		i.onload = f;
		this.appendChild(i);
	});
}

//I also did not write the code below, it returns the current filename from the URL
//below code written by Chris O'Brien 
function returnDocument() {
	var file_name = document.location.href;
	//alert(file_name);
	if(file_name == BASEURL || file_name == "http://greenwaygolfanswers.com/" || file_name == "https://greenwaygolfanswers.com/" || file_name == "https://www.greenwaygolfanswers.com/") {
		file_name = BASEURL + 'index.php';
		//alert(file_name);
	}
	var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
	end = (file_name.indexOf("#") != -1) ? file_name.indexOf("#") : end;
	return file_name.substring(file_name.lastIndexOf("/")+1, end);
}

//////////////////////////////////////////////////////////////////////////////////////////
//++++++++++++++++++++++++++++++Copywrite Disclaimer++++++++++++++++++++++++++++++++++++//
//						END of Disclaimer and Copied Code								//
//++++++++++++++++++++++++++++++Copywrite Disclaimer++++++++++++++++++++++++++++++++++++//
//////////////////////////////////////////////////////////////////////////////////////////




