
var Site = {
	start: function() {
		Site.textSize.load('utilTextResize');
		Site.rate.load();
		Site.poll.load();
		Site.forms.load();
		Site.displays.load();
		//Site.vidPlayer.load('vidStyle');
		Site.slider.load();
	},
	textSize: {
		myCookie: null,
		opts: { duration: 60 },
		els: null,
		curr: 0,
		load: function(id) {
			this.els = $(id).getElements('a');
			this.els.each(function(el,i) {
				var size 	= el.get('class');
				var _size 	= (size == 'sm') ? 'small' : (size == 'md') ? 'medium' : 'large'; 				
				el.store('size', _size).store('index', i)
				el.addEvent('click', function() {Site.textSize.loadCookie(el)})
				//el.set('href','javascript:void(0);');
			})							
			this.myCookie = Cookie.read('text_size');			
			if(!$chk(this.myCookie)) this.setCookie()
			this.loadCookie();			
		},
		setCookie: function() {
			//Writes default text-size
			this.myCookie = Cookie.write('text_size', 'small', this.opts);
		},
		loadCookie: function(el) {
			var chk		= $chk(el);
			var bdy 	= $(document.body);
			var txtSize = (chk) ? el.retrieve('size') : Cookie.read('text_size');
			var index	= (txtSize == 'small') ? 0 : (txtSize == 'medium') ? 1 : (txtSize == 'large') ? 2 : 0;
			//Reset cookie with new value
			this.myCookie = Cookie.write('text_size', txtSize, this.opts);
			//toggle on state if present
			if (this.els[this.curr].hasClass('on')) {
				this.els[this.curr].toggleClass('on');
			}
			bdy.setStyle('font-size', txtSize);			
			this.els[index].toggleClass('on');	
			this.curr	= index;											
		}		
	},
	rate: {
		id: 'utilRate',
		scale: 16,
		rateID: null,
		myPoll: null,
		currLI: null,
		requestGet: new Request({
			url: window.root+'ratePost.aspx',
			method: 'get',
			onSuccess: function(txt, xml) {
				Site.rate.update(txt);
				//console.log(this)
			}
		}),
		requestPost: new Request({
			url: window.root+'ratePost.aspx',
			method: 'get'
		}),			
		load: function() {
			this.myPoll	= $(this.id).getElement('div').get('id').split('_')[1] //get poll id
			this.currLI	= $(this.id).getElements('li')[0] //LI displaying current			
			var els 	= $(this.id).getElements('a') //Anchors
			//var txt 	= curr.get('html') //text string in current
            this.requestGet.send('method=get&ratingId='+this.myPoll)

			els.each(function(el, i) {						
				el.set('href', 'javascript:void(0);')
				el.addEvent('click', function() {
					this.check(this.myPoll, (i+1) )
				}.bind(this))
				//el.set('onclick', 'Site.rate.check(' + this.myPoll + ',' + (i + 1) + ')').set('href', 'javascript:void(0);')
				//el.onclick = new Function ('evt', 'Site.rate.check(' + myPoll + ',' + (i + 1) + ')');
			}.bind(this))					
						
		},
		update: function(txt) {
		    var rating = txt;
		    var cookie = Cookie.read('rate')
		    cookie = (cookie == null) ? "" : cookie
			var rated = ($chk(cookie) ) ? cookie.split('%') : []
		    for (var i=0; i < rated.length; i++ ) {
			    var rated2 = rated[i].split('_')
				if (rated2[0] == this.myPoll) {
					rating = rated2[1];
				}				
			}
            this.currLI.setStyle('width', rating * this.scale)			    
		},
		check: function(poll, star) {
			var chk = false;
			var cookie 	= Cookie.read('rate')
			cookie = (cookie == null) ? "" : cookie
			var rated 	= ($chk(cookie) ) ? cookie.split('%') : []
					
			//loop through cookie values, if the clicked poll has been voted on already, exit
			for (var i=0; i < rated.length; i++ ) {
			    var rated2 = rated[i].split('_')
				if (rated2[0] == poll) {
					chk = true;
					//alert('already rated');
					return;
				}				
			}
			
			//if new poll, create new string to store in cookie
			if (!chk) {
			    cookie = cookie + poll + "_" + star + '%'		
                //for (i = 0; i < rated.length; i++ ) {
                //cookie += (rated[i] + '%')
                //} 
			    Cookie.write('rate', cookie)
			    this.send(poll, star)
			    //alert('thank you');  
		     }
		},
		send: function(poll, star) {
		    this.requestPost.send('method=post&ratingId='+poll+'&rate='+star)
		    //this.request.open('POST',window.root + 'ratePost.aspx?method=post&ratingId='+poll+'&rate='+star, true);
			//this.request.send('');
			this.load();
		}				
	},
	poll: {
		pollL: null,
		pollO: null,
		pollB: null,				
		pollQ: null,	
		pollA: null,			
		pollId: null,
		btns: null,
		myPoll: null,	
		myResults: null,
		chosen: new Array(),
		barScale: 75,
		fx: {},
		requestGet: new Request.JSON({
			url: window.root+'poll.aspx',
			method: 'get',
			onSuccess: function(jsonObj, txt) {
				Site.poll.processGet(jsonObj, txt);
			}
		}),
		requestSend: new Request.JSON({
			url: window.root+'poll.aspx',
			method: 'get',
			onSuccess: function(jsonObj, txt) {
				Site.poll.processSend(jsonObj);
			}
		}),		
		load: function() {
			//if there isn't a poll, stop
			if (!$('quickPoll')) return
			
			//destroy the default banner for non-js users
			//$('pollDefault').destroy()
			
			this.pollL 		= $('quickLoading')
			this.pollO		= $('quickOption')
			this.pollB 		= $('quickBubble')						
			this.pollQ 		= $('quickQuestion')			
			this.pollA 		= $('quickAnswer')
			
			//this.pollId	 	= $('pollId').get('html')
			this.pollId 	= $random(0,9)
			
			//effects
			this.fx.fxL = new Fx.Tween(this.pollL, {duration: 500, property: 'opacity', link: 'cancel'}).set(0)
			this.fx.fxB = new Fx.Tween(this.pollB, {duration: 500, property: 'opacity'}).set(0)
			this.fx.fxQ = new Fx.Tween(this.pollQ, {duration: 500, property: 'opacity'}).set(0)
			this.fx.fxA = new Fx.Tween(this.pollA, {duration: 500, property: 'opacity'}).set(0)
			
			this.fx.fxL.start(1).chain(function() {
				this.requestGet.send('method=get&pollID='+this.pollId)						
			}.bind(this))

							
		},
		processGet: function(obj) {
			this.myPoll = obj;
      	        	
        	//build using radios/checks
			if (this.myPoll.styleType.toLowerCase() == "multi") {
				this.pollO.set('id', 'multi')
				
				var checkType 	= (!this.myPoll.grouped) ? 'checkbox' : 'radio';
				var checks 		= new Array(); //array to hold all of our elements
								
				divQ 		= new Element('div', {id: 'pollQuestion', 'class': 'pollQuestion', html: '<p>'+this.myPoll.question+'</p>'}).inject(this.pollQ)
				var qTable 	= new Element('table', {id:'qTable', 'class':'qTable'}).inject(this.pollQ)
				var pollBtn = new Element('a', {'class': 'btn', html: '<img src="'+window.root+'images/btn_pollSubmit.gif" alt="Submit" />'}).addEvent('click', function(e) {
				//alert('called');
				toTrack();
				//alert('calledafter');
					e.stop();
					pollBtn.removeEvents('click')
					this.sendPoll();					
				}.bind(this)).inject(this.pollQ)
				
				for (var i=0; i < this.myPoll.options.length; i++) {
					opt = new Element('table', {'class': 'optTable'}).adopt($$([
						tr = new Element('tr').adopt($$([
							th = new Element('th').set('html', '<input type="'+checkType+'" name="poll_'+((checkType == 'radio') ? 'RadioGroup1' : ('check'+i))+'" id="poll_'+(checkType+i)+'" />'),
							td = new Element('td').adopt($$([
								p = new Element('p').set('html', '<label name="poll_'+(checkType+i)+'" for="poll_'+(checkType+i)+'">'+this.myPoll.options[i]+'</label>')
								]))
							]))
						]))				
					checks.push(opt)
				}

				//inject those option elements into table
				for (var i=0; i < checks.length; i++) {
					if (i == 0 || i == 2) {
						var tblRow = new Element('tr')//.inject(qTable)
						qTable.adopt(tblRow)
					}
					
					var rows = qTable.getChildren('tr')

					var con = rows[rows.length - 1].getChildren()
					var cell = null;
					if (con.length == 0) {
						cell = new Element('th');
					} 
					else {
						cell = new Element('td')
					}
					cell.adopt(checks[i])
					rows[rows.length - 1].adopt(cell)													
				};								
				//reset qtable for IE
				qTable.set('html', qTable.get('html'))
				
				//hide loader show question
				this.fx.fxL.start(0).chain(function() {
					this.fx.fxB.start(1)
					this.fx.fxQ.start(1)
				}.bind(this))
				
			}
			
			//two options, using True/False or Yes/No with buttons
			else if (this.myPoll.styleType.toLowerCase() == "nomulti") {
				this.pollO.set('id', 'nomulti')

				var tbl = new Element('table', {'class':'nomultiTable', html: '<tr><td class="quickCopy"><p>'+this.myPoll.question+'</p></td></tr>'}).inject(this.pollQ)

					
				qR = new Element('div', {id: 'quickResult', html:
				'<table class="wrap"><tr><td><table><tr><th><a class="blue" onclick="javascript:toTrack();"><span>'+this.myPoll.options[0]+'</span></a></th><td><table><tr><td><div class="blue" id="barOne"/></td><td><span id="valueOne"/></td></tr></table></td></tr><tr><td style="height: 5px;"/></tr><tr><th><a class="brown" onclick="javascript:toTrack();"><span>'+this.myPoll.options[1]+'</span></a></th><td><table><tr><td><div class="brown" id="barTwo"/></td><td><span id="valueTwo"/></td></tr></table></td></tr></table></td></tr></table>'														
				}).setStyle('opacity', 0)
				qR.inject($('nomulti'))					
					
				this.fx.fxR = new Fx.Tween($('quickResult'), {duration: 500, property: 'opacity'})//.set(0)					
				
				$('valueOne').setStyle('opacity', 0)
				$('valueTwo').setStyle('opacity', 0)
				
				this.btns = $$('table.wrap')[0].getElements('a')
				this.btns.each(function(el, i) {
					el.addEvent('click', function(e) {
						e.stop()
						this.btns.removeEvents('click')
						el.set('class', 'on')
						el.getParent('tr').getElement('td').getElements('td')[0].getElement('div').set('class', 'on')
						
						this.sendPoll()
					}.bind(this))
					
				}.bind(this))
				//hide loader show question
				this.fx.fxL.start(0).chain(function() {
					this.fx.fxB.start(1)
					this.fx.fxQ.start(1)
					this.fx.fxR.start(1)
				}.bind(this))				
			}
						
		},
		processSend: function(obj) {
			this.myResults = obj.results;				
			
			if (this.myPoll.styleType.toLowerCase() == "multi") {				
				//create the Key
				key = new Element('div', {'class':'resultKey'}).adopt($$([
						keyYou =  new Element('span', {'class':'youKey', html: 'Your Answer'})
					])).inject(this.pollQ)
				
				
				
				$('pollQuestion').getElement('p').set('html', this.myPoll.response)
				
				var total = null;
				for (var i=0; i < this.myResults.length; i++) {
					total = total + this.myResults[i]
				};					
				
				var cells = $$('.optTable th')
				cells.each(function(el, i) {
					if (this.chosen[i]) {
						el.set('class', 'you')
					}
					else {
						el.set('class', 'other')	
					}
					el.set('html', ((this.myResults[i] / total) * 100).round() + '%')
					
				}.bind(this))				
				
				
				this.fx.fxL.start(0).chain(function() {
					this.fx.fxB.start(1)
					this.fx.fxQ.start(1)
				}.bind(this))
			}
			else if (this.myPoll.styleType.toLowerCase() == "nomulti") { 
								
				var val1 = this.myResults[0]
				var val2 = this.myResults[1]
	
				var p1 = (val1 / (val1 + val2) * 100).round()// + '%'
				var p2 = (val2 / (val1 + val2) * 100).round()// + '%'
				
				$('valueOne').set('html', p1 + '%')
				$('valueTwo').set('html', p2 + '%')
										
				this.fx.fxL.start(0).chain(function() {
					
					$('nomulti').getElement('td.quickCopy').set({
						'class':'quickCopyAlt',
						html: '<p>'+this.myPoll.response+'</p>'
					})
					
					this.fx.fxB.start(1)
					this.fx.fxQ.start(1)
					
					$$([$('valueOne'), $('valueTwo')]).tween('opacity', 1)
					$('barOne').tween('width', (this.barScale * (p1 / 100)).toInt())
					$('barTwo').tween('width', (this.barScale * (p2 / 100)).toInt())
					this.fx.fxA.start(1)
				}.bind(this))
			}				
						
		},
		sendPoll: function() {
			if (this.myPoll.styleType.toLowerCase() == "multi") {			
				this.fx.fxB.start(0)
				this.fx.fxQ.start(0).chain(function() {
					this.pollB.set('id', 'quickBubbleAlt')
					this.pollQ.getElements('a.btn').destroy()
					$('qTable').set('class', 'qTableResults')
					this.fx.fxL.start(1)				
										
					var inputs = $('qTable').getElements('input')
					var results = "";
					
					inputs.each(function(el, i) {
						var c = (el.get('checked')) ? 'true' : 'false'
						var o = el.get('checked')
						
						results = results + ('&val'+i+'='+c)
						this.chosen.push(o)						
																		
					}.bind(this))
					this.trackPoll(this.pollId) //tracking
					this.requestSend.send('method=post&id='+this.pollId+results);	
																														
				}.bind(this))
	
			}
			else if (this.myPoll.styleType.toLowerCase() == "nomulti") {
				this.fx.fxB.start(0)
				this.fx.fxQ.start(0).chain(function() {
					this.pollB.set('id', 'quickBubbleAlt')
					
					this.fx.fxL.start(1)				
										
						var inputs = $('quickResult').getElements('a')
						var results = "";
						
						inputs.each(function(el, i) {
							var c = (el.hasClass('on')) ? 'true' : 'false'							
							results = results + ('&val'+i+'='+c)																	
						}.bind(this))
						this.trackPoll(this.pollId) //tracking
						this.requestSend.send('method=post&id='+this.pollId+results);	
																											
				}.bind(this))				
			
			}						
		},
		trackPoll: function(int) {
			var trackObj = 
			[
				{'uri': '/polls/nobel_prize.aspx', 'ti': 'Poll - Nobel Prize Question Submit'},
				{'uri': '/polls/5_million.aspx', 'ti': 'Poll - 5 Million Americans Submit' },
				{'uri': '/polls/ask_doctor_insulin.aspx', 'ti': 'Poll - Ask Your Doctor About Insulin Submit'},
				{'uri': '/polls/doctor_talk_insulin.aspx', 'ti': 'Poll - Doctor Talk to You Insulin Submit'},
				{'uri': '/polls/talk_cde.aspx', 'ti': 'Poll - Talk CDE Submit'},
				{'uri': '/polls/pens.aspx', 'ti': 'Poll - Did You Know Pens Submit'},
				{'uri': '/polls/how_often_a1c_test.aspx', 'ti': 'Poll - How Often A1C Test Submit'},
				{'uri': '/polls/how_often_doctor.aspx', 'ti': 'Poll - How Often Doctor Submit'},
				{'uri': '/polls/type_2_how_long.aspx', 'ti': 'Poll - Type 2 How Long Submit'},
				{'uri': '/polls/where_information.aspx', 'ti': 'Poll - Where Get Information Submit'}
			]
			try {
				//dcsMultiTrack('DCS.dcsuri', trackObj[int]['uri'],'WT.ti', trackObj[int]['ti']);
			} catch(e) {}
			
		}
	},
  	forms: {
		checks: [],
		selecAll: null,
		load: function() {
			this.checks = $$('.checkList input[type=checkbox]');
			
			var _tmp = []
			
			if (this.checks.length > 0) {
				this.checks.each(function(el, i) {
					if (el.hasClass('selectAll')) {						
						el.addEvent('click', function() {
							this.checkAll(el)
							this.checked(el)
						}.bind(this))
						if (el.get('checked')) el.fireEvent('click')
						//this.selectAll = el
					}
					else {
						el.addEvent('click', function() { this.checked(el)}.bind(this))
						if (el.get('checked')) el.fireEvent('click')
						_tmp.push(el)
					}
					
				}.bind(this))
			this.checks = _tmp;								
			}						
		},
		checked: function(el) {
			if (el.get('checked')) {
				try {el.getParent('tr').getElement('p').set('class','on')} catch(e) {}
			}
			else if (!el.get('checked')) {
				try {el.getParent('tr').getElement('p').removeClass('on')} catch(e) {}
			}
			
		},
		checkAll: function(el) {
			if (el.get('checked')) {
				this.checks.each(function(el) {
					el.set('checked', true)
					this.checked(el)
				}.bind(this))
			}
			else if (!el.get('checked')) {
				this.checks.each(function(el) {
					el.set('checked', false)
					this.checked(el)
				}.bind(this))			
			}
		}		
	},
    overlay: {
        updateVars: function(obj) {
            try {
                var hash = window.location.hash.substr(1).split(':');
                if (hash[0]) obj.startingQuestion = hash[0];
                if (hash[1]) obj.startingAnswer = hash[1];
            } catch(e) {}
        },
        
	    els: {overlay: 'myOverlay', wrap: 'wrapOut', flashHolder: 'flashHolder', surveyURL: 'http://www.zoomerang.com/Survey/?p=WEB228J9W9VL8F'},
	    launch: function(which) {
	    	this.els.wrap = (which == 'survey') ? 'surveyWrap' : (which == 'moa') ? 'moaWrap' : 'wrapOut' 
	    		
		    var body = $(document.body);
			var botHTML = {}
			botHTML.id = 'copyRight'
			botHTML.html = (which == 'survey') ? '<p>&copy; 2009 SANOFI-AVENTIS U.S. LLC</p>' : '<p>&copy; 2009 SANOFI-AVENTIS U.S. LLC</p>'
		    //if (bool) return; //comment out this line to activate exit survey
		    //if (bool) this.els.wrap = 'surveyWrap'
		    body.adopt($$([
			    overlay 	= new Element('div',{id: this.els.overlay}).setStyle('opacity', (Browser.Platform.mac && Browser.Engine.gecko && Browser.Engine.version < 19) ? 1.0 : 0.9).addEvent('click', function() { this.exitGame() }.bind(this)),
			    wrapOut 	= new Element('div',{id: this.els.wrap}).adopt($$([
				    wrapIn		= new Element('div',{id: 'wrapIn'}).adopt($$([
					    topPanel 	= new Element('div',{id: 'topPanel'}).adopt($$([
						    closeBtn = new Element('div', {id: 'closeBtn'}).addEvent('click', function() { this.exitGame() }.bind(this))
						    ])),
					    midPanel 	= new Element('div',{id: 'midPanel'}).adopt($$([
						    flashHolder	= new Element('div',{id: this.els.flashHolder})
					    ])),
					    botPanel 	= new Element('div',{id: 'botPanel'}).adopt($$([
						    copy = new Element('div', botHTML)
					    ]))
				    ]))
			    ]))
		    ]))
		    if (which == 'survey') {		    
		    	$(this.els.flashHolder).destroy();
		    	var frag = document.createDocumentFragment();
		    	var h4 = new Element('h4', {html: 'At GoInsulin.com, we would like your feedback.<br/>'})
		    		frag.appendChild(h4)
		    	var p = new Element('p', {html: '<br/>Information you provide will be used to improve this Web site and help us continue to provide valuable tools and information about type 2 diabetes and insulin.<br/>'})
		    		frag.appendChild(p)	
		    	var h5 = new Element('h5', {html: 'Would you like to participate in a short, 3-question survey?'})
		    		frag.appendChild(h5)
		    	var ctas = new Element('div', {'class':'surveyCTAWrap'}).adopt($$([
		    		yes = new Element('a', {'class':'yesBtn', href: this.els.surveyURL, target: '_blank', html:'Yes, launch survey'}).addEvent('click', function() {this.exitGame()}.bind(this)),	
		    		no = new Element('a', {'class':'noBtn', href: 'javascript:void(0);', html:'No thanks'}).addEvent('click', function() {this.exitGame()}.bind(this))
		    	]))	
		    		frag.appendChild(ctas)
		    		
		    	$('midPanel').appendChild(frag)
		    }
		    else {
		       //alert('called');
		        //WT_TrackAction('5','MOA Video'); 
		    	var flashType = (which == 'moa') ? 'moa' : 'myth'
		    	this.insertFlash(flashType)		    
	    	}			    
		    	
			//fix for FF2 on a Mac
			if (Browser.Platform.mac && Browser.Engine.gecko && Browser.Engine.version < 19) {
				var myfx = new Fx.Scroll($(document.body)).toTop();
				$(this.els.overlay).setStyles({top:0,height:window.getScrollHeight()});
			    $(this.els.wrap).setStyles({left: (((document.body.getSize().x - $(this.els.wrap).getStyle('width').toInt()) / 2) > 0) ? (document.body.getSize().x - $(this.els.wrap).getStyle('width').toInt()) / 2 : 0, top: 100 });									
				return
			}
			
				    		
		    this.resizeOverlay();
			
		    window.addEvent("scroll",function() {
			    this.resizeOverlay()								
		    }.bind(this))
		    .addEvent("resize", function() {
				    this.resizeOverlay()
		    }.bind(this)
		    );
					
	    },
	    resizeOverlay: function() {
		    $(this.els.overlay).setStyles({top:window.getScrollTop(),height:window.getHeight()});
	        $(this.els.wrap).setStyles({left: (((document.body.getSize().x - $(this.els.wrap).getStyle('width').toInt()) / 2) > 0) ? (document.body.getSize().x - $(this.els.wrap).getStyle('width').toInt()) / 2 : 0, top: ((window.getScrollTop() + ((window.getHeight() - 529) / 2)) > 0) ? window.getScrollTop() + ((window.getHeight() - 529) / 2) : 0 });				
	    },
	    exitGame: function() {
		    window.removeEvents("scroll").removeEvents("resize");
			
		    try {
			    $(this.els.overlay).destroy();
			    $(this.els.wrap).destroy();
		    } catch(e) {}
	    },
	    insertFlash: function(which) {			
			var flashvars = {}
			var params = {}
			var attributes = {}
			
			if (which == 'myth') {

				flashvars.xmlURL =  'xml/qanda.xml'
				flashvars.discussURL = window.root+'insulin-resources/insulin-discussion-guide.aspx'
				flashvars.sendURL = window.root+'sendtofriend.aspx'
				flashvars.URLroot = window.root
                
                Site.overlay.updateVars(flashvars);
                
                //console.log("flash vars", flashvars);
                
			    params.allowScriptAccess = 'always'
			    params.base = window.root+'docs/swf' 
			    params['wmode'] = 'opaque'
			    	
			    attributes.id = 'mythGame'
			    attributes.name = 'mythGame'	
			    
			    swfobject.embedSWF(window.root+'docs/swf/goinsulin_game4.swf', 'flashHolder', 765, 435, '8.0.0', window.root+'docs/swf/expressInstall.swf', flashvars, params, attributes)		
			}
			else if (which == 'moa') {
				flashvars.xmlConfigUrl =  'xml/standAlonePlayerConfig.xml'
				flashvars.autoStart = "true"
				flashvars.autoStartId = "1"
				flashvars.width = "766"
				flashvars.height = "459"
				flashvars.clickTag = window.root + "insulin-resources/insulin-discussion-guide.aspx"
				flashvars.pageUrl = window.root + "why-insulin/insulin-importance.aspx"
				flashvars.sendPageURL = window.root+'sendtofriend.aspx'
					
			    attributes.id = 'mythGame'
			    attributes.name = 'mythGame'	
			
				params.menu = "true"
				params['wmode'] = "opaque"
				params.bgcolor = "#ffffff"
				params.swliveconnect = "true"
				params.allowscriptaccess = "always"
				params.allowfullscreen = "true"
				params.base = window.root+'docs/swf'		
								
				swfobject.embedSWF(window.root+"docs/swf/videoLarge.swf?r="+(Math.random()*100000), "flashHolder", "766", "454", "9.0.0", window.root+'docs/swf/expressInstall.swf', flashvars, params, attributes);	    				
			}

			
		    
	    }
    },
	vidPlayer: {
		currId: 0,
		currEl: null,
		toggles: null,
		vidWrap: null,
		load: function(id) {
			if (!$chk($(id))) return
			else {			
			    this.toggles = $(id).getElements('a');				
				this.toggles.each(function(el) {
					el.set('href', 'javascript:void(0);')
					/*
					if (el.hasClass('on')) {
						this.currId = parseInt(el.get('rel'));
						this.currEl = el;
					}
					*/
				}.bind(this))
								
                var _tmp = 1
                if (window.location.hash != '') {
                    if (window.location.hash.indexOf('#vid=') != -1) {
                        _tmp = ((window.location.hash.split('#vid=')[1]).toInt() > this.toggles.length) ? 1 : (window.location.hash.split('#vid=')[1]).toInt()
                    }   
                }			
			    //var _tmp = (window.location.hash != '') ? window.location.hash.split('#vid=')[1] : 1			    		    			    
			    this.currId = _tmp// - 1			    			    				
				this.currEl = this.toggles[this.currId - 1];
				this.currEl.toggleClass('on').getElement('.cta').set('html', 'Now Playing')                
			}			
		},
		toggle: function(id, bool) {
			this.currEl.toggleClass('on');
			this.currEl.getElement('.cta').set('html', 'Watch Video')
						
			this.toggles.each(function(el) {
				if (parseInt(el.get('rel')) == id) {
					this.currEl = el
					this.currId = parseInt(el.get('rel'))
					el.getElement('.cta').set('html', 'Now Playing')
					el.toggleClass('on')
				}
			}.bind(this))
			if (!bool) {				
				try {
					loadVideoById(this.currId);
				} catch(e) {}					
			}
						
		}
	},	
	displays: {
		load: function() {
			var shows = $$('.showMe')
			var hides = $$('.hideMe')
			
			if (shows.length > 0) {
				shows.each(function(el) { el.setStyle('display', '')})
			}
			if (hides.length > 0) {
				hides.each(function(el) { el.setStyle('display', 'none')})
			}			
		}
	},
	general: {
		showElement: function(id) {
			if ($type(id) != 'string') return;			
			$(id).setStyle('display','')
		},
		setCookie: function(id, value) {
			
		}
	},
	slider: {
		curr: 0,
		firstTime: true,
		cons: null,
		togs: null,
		load: function() {
			if (!$chk($('fearItems'))) return
			
			$('fearItems').setStyle('height', 230)
								
			this.togs = $$('.fearNav a')
			this.togs.each(function(el, i) {
				el.set('href', 'javascript:void(0);')
				el.addEvent('click', function() {
					this.goTo(i);					
				}.bind(this))
				
			}.bind(this))
			
			
			this.cons = $$('.fearItem')
			this.cons.each(function(el, i) {
				if (i == 0) el.setStyle('display', '')
				else {
					el.setStyle('display', 'none')
				}				
			})
			
		},
		goTo: function(id) {
			if (this.firstTime) {
				this.cons[0].destroy()
				this.cons = $$('.fearItem')
				this.firstTime = false;
			}
			this.togs[this.curr].removeClass('on')
			this.cons[this.curr].setStyle('display', 'none')
			
			this.cons[id].setStyle('display', '')			
			this.togs[id].addClass('on')
			this.curr = id					
		}		
	}
		
}


function showDiv(element, checkBox)
{
    
    
    var div;
    var check;

    checkbox = document.getElementById(checkBox);
    div = document.getElementById(element);

    if(checkbox.checked)
    {
        div.style.display  = "block";
    }else{
        div.style.display  = "none";
    }

}

function showDivFor(divId)
{
 document.getElementById(divId).style.display = 'block';
}
function hideDiv(divId)
{
 document.getElementById(divId).style.display = 'none';
}



// movie functions
function thisMovie(movieName) {
	 if (navigator.appName.indexOf("Microsoft") != -1) {
		 return window[movieName];
	 } else {
		 return document[movieName];
	 }
}
function playVideo()
{
    thisMovie("videoSection").playVideo();
}
function pauseVideo()
{
    thisMovie("videoSection").pauseVideo();
}
function stopVideo()
{
    thisMovie("videoSection").stopVideo();
}
function seekVideo(offset)
{
    thisMovie("videoSection").seekVideo(offset);
}
function setVideoVolume(level)
{
    thisMovie("videoSection").setVideoVolume(level);
}
function fullScreenVideo(state)
{
    thisMovie("videoSection").fullScreenVideo(state);
}
function loadVideoById(id)
{
    thisMovie("videoSection").loadVideoById(id);
}
function resumeVideo()
{
    thisMovie("videoSection").resumeVideo();
}


window.addEvent('domready', function() {
	Site.start();	
})

function launchMoaPopup() {
window.location = window.root+'why-insulin/insulin-importance.aspx'
	//Site.overlay.launch("moa")
}


function validateBirthDate(source, args) 
{
    var year = document.getElementById('ctl00_ContentPlaceHolder1_UserDateOfBirthYear');
    var month = document.getElementById('ctl00_ContentPlaceHolder1_UserDateOfBirthMonth');
    var day = document.getElementById('ctl00_ContentPlaceHolder1_UserDateOfBirthDay');
    
    if(year.selectedIndex == 0 || month.selectedIndex == 0 || day.selectedIndex == 0) {
        args.IsValid = true;
        return;
    }
    
    var myDate = new Date();
    myDate.setFullYear(year.options[year.selectedIndex].value,month.options[month.selectedIndex-1].value,day.options[day.selectedIndex].value);
    args.IsValid = (myDate.getMonth() == month.options[month.selectedIndex-1].value)
}

function validateAge(source, args) {
    var yearObj = document.getElementById('ctl00_ContentPlaceHolder1_UserDateOfBirthYear');
    //yearObj.selectedValue
    var now = new Date();
    //alert(now.getFullYear() + "-" + yearObj.options[yearObj.selectedIndex].value);
    if(yearObj.selectedIndex == 0) {
        args.IsValid = true;
        return;
    }
    var dif = eval (now.getFullYear() + "-" + yearObj.options[yearObj.selectedIndex].value);
    args.IsValid = dif > 17;
}

function validateGender(source,args)
{
    args.IsValid = false;
    args.IsValid = (document.getElementById('ctl00_ContentPlaceHolder1_F').checked || document.getElementById('ctl00_ContentPlaceHolder1_M').checked);
}


function toTrack()
{
    //alert('d');
    WT_TrackAction('1','/poll.aspx');
}

function toTrackMOAVideo()
{
    
    var args = $A(arguments);
    var step = args.getLast();
    //alert(step);
     if (step == 1)
        //alert(step);
        WT_TrackAction('5', window.root+'why-insulin/insulin-importance.aspx');
        
    if (step == 6)
        WT_TrackAction('10', window.root+'why-insulin/insulin-importance.aspx');
    dcsMultiTrack.apply(null, args);
    
    //console.log(args);
   
    
}

function toTrackLorethaVideo()
{
    var args = $A(arguments);
    var step = args.getLast();
    if (step == 1)
        WT_TrackAction('5', window.root+'insulin-success/videos/loretha.aspx');  
    dcsMultiTrack.apply(null, args);
    
    //console.log(args);
    
          

}

function toTrackGregVideo()
{
    var args = $A(arguments);
    var step = args.getLast();
    if (step == 1)
        WT_TrackAction('5', window.root+'insulin-success/videos/greg.aspx');  
    dcsMultiTrack.apply(null, args);
    
    //console.log(args);
    
          

}

