document.observe("dom:loaded", setup_ball_fitting);

var cur_bot_page = 1, cur_last_page = 1;
var cur_right_page = 1, cur_right_last_page = 1;
var fz_rate;

function setup_ball_fitting(e) {
	
	/*if( $('fitting_top') )
	{
		var params = { wmode: "opaque", allowScriptAccess: "sameDomain", allowFullScreen: "true"   };	
		swfobject.embedSWF("../flash/ballFitting.swf", "fitting_top", "962", "385", "9.0.0", false, false, params);
	}*/

	PaginatedGallery($('related_products'), 1, 303);
    PaginatedGallery($('related_pdf'), 1, 226);
	PaginatedGallery($('fitting_facts_2'), 1, 622);
	
	var fz = new FancyZoom2( $('view_larger') );	
	setup_videos();
	setup_facts();
	// if( !parse_url() )
	//		setup_video(); 
}


function launchFittingVideo(videoPath) 
{
	
	var fz = new FancyZoom('');
	
	fz.show_public(videoPath);
	//setup_video();
	
}

function launchFittingApp() 
{
	var wid = screen.width;
	var hei = screen.height;
	window.open('/golf-ball-fitting/app/', 'fittingApp', 'width=' + wid + ',height=' + hei + 'fullscreen=yes,top=0,left=0,scrollbars=no,toolbar=no,resizable=no');
}


function parse_url()
{
	if(window.location.hash == "")
		return false;
	
	var vidID = window.location.hash.replace("#", "");	
	
	if( vidID == "" || !is_positive_int(vidID) )
		return false;
		
	load_video(vidID);
	return true;	
}

function setup_videos()
{
	$$('a.video_link').each(
		function(link)
		{
			//alert($(link)['href']);
			$(link)['rel'] = $(link)['href'];
			$(link)['href'] = '#videoContainer';
			var fz = new FancyZoom( $(link) );
			fz.element.content_div = $('videoContainer');
		}
	);
	
	//$$('a.video_link').invoke( 'observe', 'click', video_clicked );
	//launchFittingVideo('http://media.titleist.com/images/titleist/videoplayer/flvs/US/titleist_winners_circle_030810_villegas_4x3_424x320.flv'); 
}

function setup_facts() {

	$$('#facts_list li a').each(
		function(link)
		{
			//alert($(link)['href']);
			var fz = new FancyZoom2( $(link) );
		}
	);
}

function setup_video(fileUrl)
{	
	
	$$('#videoPlayer').each( 
		function(node)
		{
			$(node).remove();
		});
	
	$('zoom_content').insert('<div id="videoPlayer"></div>');
	var fvars = '_videoURL=' + fileUrl;	
	
	
	var params = { wmode: "transparent", allowScriptAccess: "sameDomain", allowFullScreen: "true"   };	
	swfobject.embedSWF("/flash/videoPlayer.swf?" + fvars, "videoPlayer", "544", "306", "9.0.0", false, false, params);
	
}



function video_clicked(e) {
	//alert('clicked');
	var atag = e.element().up('a');
	
	setup_video( $(atag)['rel'] )
	//load_video(atag.href);
}

function load_video(vidid) {		

	var url = '/golf-ball-fitting/videoAjax.aspx?id=' + vidid
	
	new Ajax.Updater( $('video'), url, {
		method: 'get',
		evalScripts: true,
		onComplete: function() {
			window.location.hash = vidid;
			setup_video(); 
		}
	});
}

/*
function load_video(vidid) {		

	var url = '/ballfitting/videoAjax.aspx?id=' + vidid
	
	new Ajax.Updater( $('video'), url, {
		method: 'get',
		evalScripts: true,
		onComplete: function() {
			window.location.hash = vidid;
			setup_video(); 
		}
	});
}
*/
function is_positive_int(sText)
{
	if(isNaN(parseInt(sText)))
		return false;
	else
		return true;
}
