var ct={};
ct.counter = 0;
var get = YAHOO.util.Dom.get;
var replaceClass = YAHOO.util.Dom.replaceClass;
var hasClass = YAHOO.util.Dom.hasClass;
var getElementsByClassName = YAHOO.util.Dom.getElementsByClassName;
var batch = YAHOO.util.Dom.batch;
var yc = YAHOO.util.Connect;
var vp = parseInt((YAHOO.util.Dom.getViewportWidth()-665)/2,10);
ct.distroyPanel = function (){
    ct.panel.hide(); 
    removeElement('panel');
}
var getScreencast = {
    
    handleSuccess:function(o){
        // This member handles the success response
        // and passes the response object o to saveRound
        // processResult member.
        
        this.processResult(o); 
    },

    handleFailure:function(o){
        // Failure handler
        var msg = "An error occured while loading the screen cast. Please wait a few seconds and try again.";
        validationMSG(msg);
        YAHOO.rnd.dlg.show();
    },

    processResult:function(o){
        // This member is called by handleSuccess
        var scroll = YAHOO.util.Dom.getDocumentScrollTop();
        ct.panel = new YAHOO.widget.Panel("panel",{ width:"665px", 
                                          fixedcenter:false, 
                                          close:true, 
                                          draggable:true, 
                                          modal:true,
                                          visible:false,
                                          xy:[vp,scroll],
                                          effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
                                          }); 
        ct.panel.setHeader(ct.header);
        ct.panel.setBody(o.responseText);
        ct.panel.render(document.body);
        ct.panel.show();
        //YAHOO.util.Event.onContentReady("media", playScreencast.start);
        
        
    },
    startRequest:function(sc) {
        
        yc.asyncRequest('GET', ct.screencast, getScreencastCallback);
    }
};
/**
 * Define the callback object for getRoundVideo
 * success and failure handlers as well as scope.
 */
var getScreencastCallback = {
    success:getScreencast.handleSuccess,
    failure:getScreencast.handleFailure,
    scope: getScreencast,
    timeout: 15000
};
var handle_testimonial = {
    init: function () {
        get("test-div").innerHTML = testimonials[0];
    },
    next: function (){
        ct.counter += 1;
        if (ct.counter > 5){
            ct.counter = 0;
        }
        get("test-div").innerHTML = testimonials[ct.counter];
    },
    previous : function (){
        ct.counter -= 1;
        if (ct.counter < 0){
            ct.counter = 5;
        }
        get("test-div").innerHTML = testimonials[ct.counter];
    }
}
var ar_img = {
    'l-card-enterround':'http://media.mysmartgolf.com.s3.amazonaws.com/l-card-enterround.png',
    'l-card-evaluations':'http://media.mysmartgolf.com.s3.amazonaws.com/l-card-evaluations.png',
    'l-card-seeyourgame':'http://media.mysmartgolf.com.s3.amazonaws.com/l-card-seeyourgame.png',
    'l-card-video':'http://media.mysmartgolf.com.s3.amazonaws.com/l-card-video.png',
    'r-card-enterround':'http://media.mysmartgolf.com.s3.amazonaws.com/r-card-enterround.png',
    'r-card-seeyourgame':'http://media.mysmartgolf.com.s3.amazonaws.com/r-card-seeyourgame.png',
    'r-card-evaluations':'http://media.mysmartgolf.com.s3.amazonaws.com/r-card-evaluations.png',
    'r-card-video':'http://media.mysmartgolf.com.s3.amazonaws.com/r-card-video.png'
};
var ar_map = {
    'r-card-enterround':'roundentryforhomepage12-9-08.html',
    'r-card-seeyourgame':'statsforhomepage12-9-08.html',
    'r-card-evaluations':'roundevalscreencast11-23-08.html',
    'r-card-video':'videosample.html',
    'introtour11-23-08': 'introtour11-23-08.html',
    'Tproscreencast12-8-08':'Tproscreencast12-8-08.html',
    'coachscreencast12-2-08':'coachscreencast12-2-08.html'
};
var ar_header = {
    'r-card-enterround':'Round entry screencast.',
    'r-card-seeyourgame':'See your game screencast',
    'r-card-evaluations':'Evaluations screencast',
    'r-card-video':'Video sample',
    'introtour11-23-08': 'Tour of MySmartGolf.com features',
    'Tproscreencast12-8-08':'Tour for teaching professionals',
    'coachscreencast12-2-08':'Tour for golf teams'
};
/**
* Swaps the images in response to mouse  
* events in the shot result widgets.
* @param {Object,String} htmlobj A reference to the DOM element to update (if
* a string is given, getElement(node) will be used to locate the node)
* 
*/
function handle_card(htmlobj) {
    var id1 = null;
    var id2 = null;
    var is_demo = false;
    if (htmlobj =="l_card_video"){
        id1='l-card-video';
        id2='r-card-video';
        is_demo=true;
    } else if (htmlobj =="l_card_round"){
        id1='l-card-enterround';
        id2='r-card-enterround';
        is_demo=true;
    }else if (htmlobj.id =="l_card_video"){
        id1='l-card-video';
        id2='r-card-video';
        is_demo=true;
    }else if (htmlobj =="l_card_eval"){
        id1='l-card-evaluations';
        id2='r-card-evaluations';
        is_demo=true;
    }else if (htmlobj =="l_card_game"){
        id1='l-card-seeyourgame';
        id2='r-card-seeyourgame';
        is_demo=true;
    }
    ct.screencast=null;
    ct.header=null;
    if (is_demo===true){
        lcard = get('l-card-img');
        rcard = get('r-card-img');
        lcard.src = ar_img[id1];
        rcard.src = ar_img[id2];
        ct.screencast=ar_map[id2];
        ct.header=ar_header[id2];
    } else {
        ct.screencast=ar_map[htmlobj];
        ct.header=ar_header[htmlobj];
        
    }

};

function handle_sc (htmlobj){
    
};
function swapClass(el){
    if (hasClass(el,'learn-msg')){
        replaceClass(el, 'learn-msg', 'invisible')
    } else if (hasClass(el,'invisible')){
        replaceClass(el, 'invisible','learn-msg')
    }    
};

function handle_learn_more (htmlobj){
    var el = get(htmlobj);
    visible_els = getElementsByClassName('learn-msg');
    batch(visible_els,swapClass);
    swapClass(el);
};
function FlashDetectBase(options){
	var self = this;
	var _release = "1.0";
	var options = options || {};
	self.installed = false;
	self.major = -1;
	self.minor = -1;
	self.revision = -1;
	self.revisionStr = "";
	self.activeXVersion = "";
	var activeXDetectRules = options.activeXDetectRules || [
		{
			"name":"ShockwaveFlash.ShockwaveFlash.7",
			"version":function(obj){return getActiveXVersion(obj);}
		},
		{
			"name":"ShockwaveFlash.ShockwaveFlash.6",
			"version":function(obj){
				var version = "6,0,21";
				try{
					obj.AllowScriptAccess = "always";
					version = getActiveXVersion(obj);
				}catch(err){}
				return version;
			}
		},
		{
			"name":"ShockwaveFlash.ShockwaveFlash",
			"version":function(obj){return getActiveXVersion(obj);}
		}
	];
	var getActiveXVersion = function(activeXObj){
		var version = -1;
		try{
			version = activeXObj.GetVariable("$version");
		}catch(err){}
		return version;
	}
	var getActiveXObject = function(name){
		var obj = -1;
		try{
			obj = new ActiveXObject(name);
		}catch(err){}
		return obj;
	}
	var parseActiveXVersion = function(str){
		var versionArray = str.split(",");
		return {
			"major":parseInt(versionArray[0].split(" ")[1]),
			"minor":parseInt(versionArray[1]),
			"revision":parseInt(versionArray[2]),
			"revisionStr":versionArray[2]
		};
	}
	var parseRevisionStrToInt = function(str){
		return parseInt(str.replace(/[a-zA-Z]/g,"")) || self.revision;
	}
	self.majorAtLeast = function(version){
		return self.major >= version;
	}
	self.DetectBase = function(){
		if(navigator.plugins && navigator.plugins.length>0){
			var type = 'application/x-shockwave-flash';
			var mimeTypes = navigator.mimeTypes;
			if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description){
				var desc = mimeTypes[type].enabledPlugin.description;
				var descParts = desc.split(' ');
				var majorMinor = descParts[2].split('.');
				self.major = parseInt(majorMinor[0]);
				self.minor = parseInt(majorMinor[1]); 
				self.revisionStr = descParts[3];
				self.revision = parseRevisionStrToInt(self.revisionStr);
				self.installed = true;
			}
		}else if(navigator.appVersion.indexOf("Mac")==-1 && window.execScript){
			var version = -1;
			for(var i=0; i<activeXDetectRules.length && version==-1; i++){
				var obj = getActiveXObject(activeXDetectRules[i].name);
				if(typeof obj == "object"){
					self.installed = true;
					version = activeXDetectRules[i].version(obj);
					if(version!=-1){
						var obj = parseActiveXVersion(version);
						self.major = obj.major;
						self.minor = obj.minor; 
						self.revision = obj.revision;
						self.revisionStr = obj.revisionStr;
						self.activeXVersion = version;
					}
				}
			}
		}
	}();
}
var FlashDetect = new FlashDetectBase();
var testimonials = new Array();
var moreTestimonials = "<br /><a href=\"/msg/testimonials\">More Testimonials...</a>";
testimonials[0] = "“Understanding my team's strengths and weaknesses is important through accurate statistics and MySmartGolf is a great tool to use to gain that clear understanding. I use it with my team and would recommend it to any golfer out there who is trying to get better.”<br /><br /><b>Conrad Ray<br/> Stanford University Men's Golf Coach</b><br/>";
testimonials[1] = "“MySmartGolf is the most complete and valuable round analysis software I have ever seen.  Combined with the instruction videos and the ability to link the analysis to my instructor, MySmartGolf provides me more avenues for improvement than any other instruction aid out there.  It's a great product.”<br /><br /><b>Mark, California</b><br/>";
testimonials[2] = "“… our experience with your site helped us find a common fault in my son's game.  I have always tracked the normal stats for his game but after entering 2 rounds into MySmartGolf, I discovered that he had a tendency to go right with all phases of his game; drives, pitching, chipping and putting.  We then noticed that he tended to go inside-out with everything and he started to work on correcting this motion.  The next 3 rounds the scores got better and the dispersion became more even. On Wednesday, he was in a tournament where he placed first and shot under his personal par for the first time in a tournament.”<br /><br /><b>Tom, California</b><br />";
testimonials[3] = "“My son has started to compete with himself and think about how he is doing in the drives, approach, greenside, and putting categories of your site. It has given him a framework to evaluate his game and compete against himself.”<br /><br /><b>Tom, California</b><br />";
testimonials[4] = "“MySmartGolf is great.  It takes a little time to get used to keeping stats.  The lessons and evaluations are the best parts.”<br /><br /><b>Pete, California</b><br />";
testimonials[5] = "“Understanding how you play is the only way to improve your game. As a golfer with a high \"teen\" handicap, MySmartGolf enabled me to track my game with great detail.  I quickly went to work on the worst area of my game and used the instructional videos to help my training while I was at the driving range.”<br /><br /><b>Mike, Massachusetts</b><br />";


