<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="Casio YouTube Contest" title_url=""
      description=""
      author=""
      author_email="jakkad@youtube.com"
      author_affiliation=""
      author_location=""
      width="560"
      height="465"
      screenshot="http://contests.labpixies.com/gadget/images/screenshot.jpg"
      thumbnail="http://contests.labpixies.com/gadget/images/thumbnail.jpg"
      scaling="false"
      scrolling="false">
	  
	<Require feature="tabs" />
	<Require feature="flash" />
	<Require feature="analytics" />
	<Require feature="locked-domain" />
</ModulePrefs>

<UserPref name="phase" datatype="hidden" default_value="none"/>

<Content type="html">
<![CDATA[
<title>Casio Dream Digs</title>
<style type="text/css">
	body{
		width:560px;
		height:465px;
	}
  
	form { margin-bottom: 0px; }
	
	.tablib_main_container{
		width:560px;
        background-image: url(http://gmodules.com/ig/proxy?url=http%3A%2F%2Fcontests.labpixies.com%2Fgadget%2Fcasio%2Fimages%2Fbackground_new1.jpg);
        background-repeat: no-repeat;
	}

	.tablib_table{
		width:560px;
		height:22px;
		
	}

	.tablib_spacerTab{
		
	}

	.tablib_selected{
		padding-left:3px;
		padding-right:3px;
        color: #224668; 
        background-color: #e7ecf0;
		border-color: #839aac;
	}

	.tablib_unselected{
		font-weight: bold;
		padding-left:3px;
		padding-right:3px;
        color: #e7ecf0; 
        background-color: #224668;
		border-color: #839aac;
	}
	
	.tablib_emptyTab{
		border-color: #839aac;
	}
	.tablib_content_container{
		width:560px;
		height:303px;
	}
  
	.blacktext {
		font-family: Verdana, Arial, Helvetica, sans-serif;
		font-size: 12px;
		line-height: 16px;
		color: #000000;
	}
	
	.whitetext {
		font-family: Verdana, Arial, Helvetica, sans-serif;
		font-size: 12px;
		line-height: 16px;
		color: #FFFFFF;
	}
  
</style>

<script type="text/javascript">
	var mAll = _IG_GetCachedUrl("http://contests.labpixies.com/gadget/casio/contest_meta.js");
	document.write('<scr'+'ipt type="text/javascript" src="'+mAll+'"></scr'+'ipt>');
	var mAll3 = _IG_GetCachedUrl("http://contests.labpixies.com/ga.js");
	document.write('<scr'+'ipt type="text/javascript" src="'+mAll3+'"></scr'+'ipt>');
	//DEBUG remove before publish
	var prefs = new _IG_Prefs(__MODULE_ID__);
	//END_DEBUG
	
	var contestID = 5;
	var vlist = null;
	var temp_vlist = null;
	var search_start_idx = 0;
	var vOfCount = 0;
	var tabs = null;
	var gtabID;
	var selectedVid = 0;
	var totalVotes = 0;
	var user_vid = "";
	var user_id = "";
	var _json_with_no_cache = 1;
	var timerHandle = 0;
	var voted_on_video = false;
	var page = 1;
	
	function initTabs() {
		
		if(tabs==null){
			
			tabs = new _IG_Tabs(__MODULE_ID__,"Home");
			
			var phase = meta.phase;
			
			//DEBUG remove before publish
			var debug_phase = prefs.getString("phase")
			if( debug_phase != "none"){
				phase = debug_phase;
			}
			//END_DEBUG
			
			tabs.addTab("Home","mainTbl", callback_home);
			
			if(phase == "1"){	
				tabs.addTab("Submit", "submit", callback_submit);
				tabs.addTab("Watch","view", callback)
			}else if(phase == "2"){
				tabs.addTab("Vote","view", callback);
			}else if(phase == "3"){
				tabs.addTab("Results", "results",callback_results);
			}
			
			tabs.alignTabs("left");
			
			var link = document.createElement('a');
			link.setAttribute('href', 'http://www.youtube.com/casiousa');
			link.setAttribute('target', '_blank');
			link.setAttribute('border', '0');
			link.innerHTML = '<img id="bannerImg" class="headerImg" border="0" usemap="#map3" src="" width="560" height="140" />';
			link.setAttribute('id', 'mainBanner');
			link.setAttribute("onclick","gadgetTracker._trackEvent('topBannerClick');");
			
			document.body.insertBefore(link,document.body.firstChild);
			_gel("bannerImg").src = _IG_GetImageUrl("http://contests.labpixies.com/gadget/casio/images/header_new1.jpg");
		}else{
			
			returned_from_home = true;
			tabs.displayTabs(true);
			tabs.setSelectedTab(2);
		}

		_gel("mainBanner").style.display = "block";
	}

	function callback_home(tabId){
		//gadgetTracker._trackEvent('home-tabSelect');
		
		stopVids();
		
		var phase = meta.phase;
			
		//DEBUG remove before publish
		var debug_phase = prefs.getString("phase")
		if( debug_phase != "none"){
			phase = debug_phase;
		}
		//END_DEBUG
		
		if(phase == "1"){
			_gel("main_left").src = _IG_GetImageUrl("http://contests.labpixies.com/gadget/casio/images/enter_the_contest.gif");
			
		}else if(phase == "2"){
			_gel("main_left").src = _IG_GetImageUrl("http://contests.labpixies.com/gadget/casio/images/submit_text.gif");
			
		}else if(phase == "3"){
			_gel("main_left").src = _IG_GetImageUrl("http://contests.labpixies.com/gadget/casio/images/submit_text.gif");
			
		}
		
		_gel("img_rules").src = _IG_GetImageUrl("http://contests.labpixies.com/gadget/casio/images/secondary_text.gif");
		
		var curl = ("http://www.youtube.com/v/1Wsy_Yrafc0&rel=0&autoplay=1&border=0");
		_LP_EmbedFlash(curl, "home_vid", {width: 265,height: 220,wmode:'transparent'});
	}

	function callback(tabId) {
		stopVids();
		
    gadgetTracker._trackEvent('vote-tabSelect');
		_gel('view').style.backgroundImage = "url("+ _IG_GetImageUrl("http://contests.labpixies.com/gadget/casio/images/background1.jpg") +")";
    _gel('view').style.backgroundPosition = "0px -22px";
    var url = "http://contests.labpixies.com/get_videos/?cid="+contestID+"&v_phase="+meta.v_phase;

		_IG_FetchContent(url, parseResponse, { refreshInterval: (60 * 1) });
		return false;
	}

	function callback_submit(tabId){
		gadgetTracker._trackEvent('submit-tabSelect');
		_gel('submit').style.backgroundImage = "url("+ _IG_GetImageUrl("http://contests.labpixies.com/gadget/casio/images/background1.jpg") +")";
		_gel('submit').style.backgroundPosition = "0px -22px";
		_gel('captcha').src='http://contests.labpixies.com/image.php?width=120&height=50&r='+Math.round(Math.random()*10000)
		_gel("userCaptchaError").innerHTML =  "";
		_gel("captcha_text").value = "";
		
		_gel("submit0").style.display = "block";
		_gel("submit1").style.display = "none";
		_gel("submit2").style.display = "none";
		_gel("submit3").style.display = "none";
		stopVids();
	}

	function callback_results(tabId){
		gadgetTracker._trackEvent('results-tabSelect');
		stopVids();
		var url = "http://contests.labpixies.com/get_videos/get_winners.php?cid="+contestID;
		_IG_FetchContent(url, parseWinResponse,{ refreshInterval: (60 * 1) }); //remove cache busterpefore launch
		return false;
	}
  
	function stopVids(){
		
		_gel("home_vid").innerHTML = "&nbsp;";
		
		_gel("plDiv").innerHTML = '<table width="330" height="100%"><tr><td  align="center"><span id="loading_vid" style="font-size:12px;font-family:arial;align:center;margin-top:100px;">Loading Video...</span></td></tr></table>';

		_gel("smallVid").innerHTML = '<table width="172" height="129" style="background-color:black;"><tr><td  align="center"><span id="loading_small" style="font-size:12px;font-family:arial;align:center;color:white;margin-top:60px;">Click on a video thumbnail to view</span></td></tr></table>';

		_gel("resDiv").innerHTML = '<table width="240"><tr><td  align="center"><span id="loading_res_vid" style="font-size:12px;font-family:arial;align:center;margin-top:80px;">&nbsp;</span></td></tr></table>';
	}
  
	function parseResponse(response){
		
		if (response == null || typeof(response) != "string") {
			_gel("loading_vid").innerHTML = "Temporary unavailable, please try again in a few seconds";
			return;
		}
		videos_data = eval("("+response+")");
		
		
		vlist = videos_data.list;
		vlist.splice(vlist.length-1,1);
		
		if(vlist.length == 0){
			_gel("loading_vid").innerHTML = "No video available, please try again in a few seconds";
			return;
		}
		
		vlist.sort( randOrd );
		vOfCount = vlist.length;
		selectedVid = Math.floor(Math.random()*vOfCount);
		
		embedVid();
		
	}
	
	function parseSearchResponse(response){
		
		if (response == null || typeof(response) != "string") {
			
			_gel("search_results").innerHTML = 'Temporary unavailable, please try again in a few seconds';
			
			return;
		}
		temp_vlist = null;
    
		search_data = eval("("+response+")");
		temp_vlist = search_data.list;
		
		var html = 'No Videos Found';
		if(temp_vlist.length > 1){
			
			html = getSearchResultsHTML(0,4);
		}
		
		embedVid();
		_gel("search_results").innerHTML = html;
	}
	
	function parseWinResponse(response){
		
		if (response == null || typeof(response) != "string") {
			_gel("win_results").innerHTML = 'Temporary unavailable, please try again in a few seconds';
			return;
		}
		
		temp_vlist = null;
    
		search_data = eval("("+response+")");
		temp_vlist = search_data.list;
		
		var html = 'No Videos Found';
		if(temp_vlist.length > 1){
			totalVotes = 0;
			var i = 0;
			for(i=0;i<temp_vlist.length-1;i++){
			  totalVotes += parseInt(temp_vlist[i].votes);
			}
			html = getWinResultsHTML(0,4);
			embedWinVid(0);
		}

		_gel("win_results").innerHTML = html;
		
	}

	function getSearchResultsHTML(start,end){
		var html = '<table width="560" border="0" cellpadding="0" cellspacing="0"><tr><td  width="40" align="center"><img src="'+_IG_GetImageUrl('http://contests.labpixies.com/gadget/casio/images/left_arrow.gif')+'" onclick="scrollSearch(-1);" /></td><td align="center" bgcolor="white"><table border="0" cellpadding="2" cellspacing="0"><tr>';
			
		var i = 0;
		for(i=start;((i<end) && (i<start+4) && (i<temp_vlist.length-1));i++){
			html += '<td width="114"><div style=" width:114px;overflow:hidden;"><img onclick="embedVid('+i+')" title="'+temp_vlist[i].v_name+'" width="45" height="45" style="cursor:pointer;vertical-align: middle" src="http://img.youtube.com/vi/'+temp_vlist[i].yt_id+'/default.jpg" />&nbsp;<a title="'+temp_vlist[i].u_name+'" href="javascript:void(0);" onclick="embedVid('+i+')" style="vertical-align: middle;font-size:10px;font-weight:bold;" >'+temp_vlist[i].u_name.substring(0,10)+'</a></div></td>'
		}
		
		html += '</tr></table></td><td width="40" align="center"><img src="'+_IG_GetImageUrl('http://contests.labpixies.com/gadget/casio/images/right_arrow.gif')+'" onclick="scrollSearch(1);" /></td></tr></table>';
		return html;
	}
  
	function getWinResultsHTML(start,end){
		var html = '<table width="560" border="0" cellpadding="0" cellspacing="0"><tr><td  width="40" align="center"><img src="'+_IG_GetImageUrl('http://contests.labpixies.com/gadget/casio/images/left_arrow.gif')+'" onclick="scrollWin(-1);" /></td><td align="center" bgcolor="white"><table border="0" cellpadding="2" cellspacing="0"><tr>';
			
		var i = 0;
		for(i=start;((i<end) && (i<start+4) && (i<temp_vlist.length-1));i++){
			html += '<td width="100">'+
					'<table width="100%" border="0" cellpadding="0" cellspacing="2">'+
						'<tr><td colspan="2" style="width:90px;overflow:hidden;" ><img onclick="embedWinVid('+i+')" title="'+temp_vlist[i].v_name+'" width="90" height="58" style="cursor:pointer;vertical-align: middle" src="http://img.youtube.com/vi/'+temp_vlist[i].yt_id+'/default.jpg" /></td></tr>'+
						'<tr><td colspan="2" style="width:90px;overflow:hidden;" ><a title="'+temp_vlist[i].v_name+'" href="javascript:void(0);" onclick="embedWinVid('+i+')" style="vertical-align: middle;font-size:10px;font-weight:bold;" >'+(i+1)+". "+temp_vlist[i].v_name.substring(0,10)+'...</a></td></tr>'+
					'</table>'+
				'</td>';
		}
		
		html += '</tr></table></td><td width="40" align="center"><img src="'+_IG_GetImageUrl('http://contests.labpixies.com/gadget/casio/images/right_arrow.gif')+'" onclick="scrollWin(1);" /></td></tr></table>';
		return html;
	}
  
	function scrollSearch(dir){
		gadgetTracker._trackEvent('vote-scrollSearch');
		if(temp_vlist.length<=5){
			return;
		}
		search_start_idx += dir;
		if(search_start_idx < 0) search_start_idx = 0;
		if(search_start_idx > temp_vlist.length-5 && temp_vlist.length-5 > 0) search_start_idx = temp_vlist.length-5;

		var html = getSearchResultsHTML(search_start_idx,search_start_idx+4);
		_gel("search_results").innerHTML = html;
	}
	function scrollWin(dir){
		gadgetTracker._trackEvent('results-scroll');
		if(temp_vlist.length<=5){
			return;
		}
		search_start_idx += dir;
		if(search_start_idx < 0) search_start_idx = 0;
		if(search_start_idx > temp_vlist.length-5 && temp_vlist.length-5 > 0) search_start_idx = temp_vlist.length-5;

		var html = getWinResultsHTML(search_start_idx,search_start_idx+4);
		_gel("win_results").innerHTML = html;
	}
  
	function embedVid(s_idx){
		voted_on_video = false;
		var butt0 = _gel("butt0");
		var butt1 = _gel("butt1");
		butt0.src =butt0.src.replace("_on","_off");
		butt1.src =butt1.src.replace("_on","_off");
		
		if(s_idx == null){
			video = vlist[selectedVid];
		}else{
			video = temp_vlist[s_idx];
		}
		
		if(video == null){
			return;
		}
		var el = _gel("plDiv");
		
		var curl = ("http://www.youtube.com/v/"+video.yt_id+"&rel=0&autoplay=1&border=0");
		
		
		if(_gel("search_results").style.display == "block"){
			el.style.width = "280px";
			el.style.height = "210px";
			 _LP_EmbedFlash(curl, "plDiv", {width: 258,height: 210,wmode:'transparent'});
       //_gel("plDiv").innerHTML = '<object width="258" height="210"><param name="movie" value="'+curl+'"></param><param name="wmode" value="transparent"></param><embed src="'+curl+'" type="application/x-shockwave-flash" wmode="transparent" width="258" height="210"></embed></object>';
		}else{
			el.style.width = "330px";
			el.style.height = "240px";
			 _LP_EmbedFlash(curl, "plDiv", {width: 296,height: 240,wmode:'transparent'});
       //_gel("plDiv").innerHTML = '<object width="296" height="240"><param name="movie" value="'+curl+'"></param><param name="wmode" value="transparent"></param><embed src="'+curl+'" type="application/x-shockwave-flash" wmode="transparent" width="296" height="240"></embed></object>';
		}
		
		 
		//_gel("serial").innerHTML = video.serial;
		//_gel("ofCount").innerHTML = "of "+vOfCount;
		if(video.v_name.length >=30){
			_gel("vname").innerHTML = (video.v_name.substring(0,29) + "...");
		}else{
			_gel("vname").innerHTML = video.v_name;
		}
		_gel("vname").title = video.v_name;
		_gel("uname").innerHTML = video.u_name;
		_gel("uname").href = ("http://www.youtube.com/user/"+video.u_name);
		_gel("views").innerHTML = video.views;
		
		var txtEL = _gel("vote_text");
		txtEL.innerHTML = "0";
		txtEL.style.color = "#919191";
		
		gadgetTracker._trackEvent('vote-playVideo',video.v_name);
		_gel("report_pixel").src = "http://contests.labpixies.com/view.php?vid="+video.yt_id+"&cont_id="+contestID+"&rand="+Math.round(Math.random()*100000);
	}
  
	function embedSmallVid(id,name){
		name = unescape(name);
		var el = _gel("smallVid");
		
		var curl = ("http://www.youtube.com/v/"+id+"&rel=0&autoplay=1&border=0");
		
		_LP_EmbedFlash(curl, "smallVid", {width: 168,height: 135,wmode:'transparent'});
    //_gel("smallVid").innerHTML = '<object width="168" height="135"><param name="movie" value="'+curl+'"></param><param name="wmode" value="transparent"></param><embed src="'+curl+'" type="application/x-shockwave-flash" wmode="transparent" width="168" height="135"></embed></object>';
		if(name.length >=30){
			_gel("smallName").innerHTML = (name.substring(0,29) + "...");
		}else{
			_gel("smallName").innerHTML = name;
		}
		_gel("smallName").title = name;
		gadgetTracker._trackEvent('submit-playUserVideo',name);
	}
	
	function embedWinVid(s_idx){
		video = temp_vlist[s_idx];
		
		var el = _gel("resDiv");
		
		var curl = ("http://www.youtube.com/v/"+video.yt_id+"&rel=0&autoplay=1&border=0");
		
		_LP_EmbedFlash(curl, "resDiv", {width: 220,height: 178,wmode:'transparent'});
    //_gel("resDiv").innerHTML = '<object width="220" height="178"><param name="movie" value="'+curl+'"></param><param name="wmode" value="transparent"></param><embed src="'+curl+'" type="application/x-shockwave-flash" wmode="transparent" width="220" height="178"></embed></object>';
		//_gel("res_serial").innerHTML = video.serial;
		//_gel("res_ofCount").innerHTML = "of "+vOfCount;
		if(video.v_name.length >=30){
			_gel("res_vname").innerHTML = (video.v_name.substring(0,29) + "...");
		}else{
			_gel("res_vname").innerHTML = video.v_name;
		}
		_gel("res_vname").title = video.v_name;
		_gel("res_uname").innerHTML = video.u_name;
		_gel("res_uname").href = ("http://www.youtube.com/user/"+video.u_name);
		_gel("bar_selected").style.width = (Math.round((video.votes/totalVotes)*100)+'%');
		_gel("percent_selected").innerHTML = ('&nbsp;<strong>'+(Math.round((video.votes/totalVotes)*100)+'%')+'</strong>');
		_gel("res_views").innerHTML = video.views;
		
		gadgetTracker._trackEvent('results-playVideo',video.v_name);
	}
	
	function changeVid(){
		if(vlist==null) return;
		gadgetTracker._trackEvent('vote-NextVideoClick');
		selectedVid = (selectedVid+1)%vOfCount;
		_gel("search_results").style.display = "none";
		embedVid();
	}
	
	function reportVote(dir){
		if(video==null)return;
		if(voted_on_video)return;
		voted_on_video = true;
		var txtEL = _gel("vote_text");
		var color = "rgb(9,92,20)";
		var text  = "+1";
		var report = "vote-thumbsUp";
		if(dir==0){
			color = "rgb(218,41,69)";
			text  = "-1";
			report = "vote-thumbsDown";
		}
		txtEL.innerHTML = text;
		txtEL.style.color = color;
		gadgetTracker._trackEvent(report,video.yt_id);
		_gel("report_pixel").src = "http://contests.labpixies.com/vote.php?dir="+dir+"&vid="+video.id+"&cont_id="+contestID+"&rand="+Math.round(Math.random()*100000);
	}
  
	function search(){
		_gel("search_results").style.display = "none";
		var search_term = _gel("search_text").value.trim();
		search_term = search_term.replace(/ /g,"+");
		gadgetTracker._trackEvent('vote-searchVideoClick');
		if(search_term==""){return}
		var url = "http://contests.labpixies.com/get_videos/?cid="+contestID+"&search="+search_term;
		_IG_FetchContent(url, parseSearchResponse);
		_gel("search_results").innerHTML = '<img src="'+_IG_GetImageUrl('http://contests.labpixies.com/gadget/casio/images/loading.gif')+'" />';
		_gel("search_results").style.display = "block";
		return false;
	}
	
  
	function getUserVideos(n_page){
		gadgetTracker._trackEvent('submit-searchUserClick');
		_gel("userContent").innerHTML = "Loading..."
		_gel("userSearchError").innerHTML = '<img src="'+_IG_GetImageUrl('http://contests.labpixies.com/gadget/l4l/images/loading.gif')+'" />';
		if(n_page!=null) {page = n_page};
		var userName = _gel("user_name").value.trim();
		user_id = userName;
		var url = "http://www.youtube.com/api2_rest?method=youtube.videos.list_by_user&dev_id=8DNZTBMAqZI&user="+escape(userName)+"&per_page=100&page="+page;
		_IG_FetchXmlContent(url, parseUserVidResponse);
		return false;
	}
  
  
	function parseUserVidResponse(response){
		var el = _gel("userContent");
		_gel("userSearchError").innerHTML = "";
		
		if (response == null || typeof(response) != "object" || response.firstChild == null) {
			_gel("userSearchError").innerHTML = 'Temporary unavailable, please try again in a few seconds';
			return;
		}
    
	    
	    if(response.getElementsByTagName("total").length != 0){
			maxResults = response.getElementsByTagName("total").item(0).firstChild.nodeValue;
		}
		
	    var itemList = response.getElementsByTagName("video");
	    if(itemList.length == 0){
			_gel("userSearchError").innerHTML = 'No videos found for given user, please try again';
			return;
	    }
	
		var currResults = itemList.length;
    
    
    
	    var html = '<table>';
	    var i = 0;
	    var last_jump = 0;
	    for(i=0;i<currResults;i++){
			if(i%3 == 0){
				html += '<tr>';
			}
			
			var nodeList = itemList.item(i).childNodes;

            var yt_id = "";
			var name = "";
			
             for (var j = 0; j < nodeList.length ; j++) {
                var node = nodeList.item(j);
                if (node.nodeName == "id") {
                   yt_id = node.firstChild.nodeValue;
                }
                if (node.nodeName == "title") {
                   name = node.firstChild.nodeValue; 
                }
            } 
			 
			

			html += '<td align="center" width="110" height="80"><input onclick="setSelected(\''+yt_id+'\');" type="radio" name="userVid" id="rad_'+i+'" value="'+yt_id+'" />'+
				  '<img onclick="embedSmallVid(\''+yt_id+'\',\''+escape(name)+'\')" title="'+name+'" width="70" height="55" style="cursor:pointer;vertical-align: middle" src="http://img.youtube.com/vi/'+yt_id+'/default.jpg" /><br/>'+
				  '<a title="'+name+'" href="javascript:void(0);" onclick="embedSmallVid(\''+yt_id+'\',\''+escape(name)+'\')" style="vertical-align: middle;font-size:10px;font-weight:bold;" >'+name.substring(0,10)+'</a></td>';

			if(i-last_jump==2){
				html += '</tr>';
				last_jump = i+1;
			}
	    }
    
		var nav = '<tr><td colspan="3" width="330" align="center" style="font-family:arial;font-size:10px;">';
		if(maxResults>100 && page>1){
			nav += '<a href="javascript:void(0)" onclick="getUserVideos('+(page-1)+')" style="font-family:arial;font-size:10px;"><< Back</a>';
			if(maxResults > (page*100)){
				nav += '&nbsp; | &nbsp;';
			}
		}
		if(maxResults > (page*100)){
			nav += '<a href="javascript:void(0)" onclick="getUserVideos('+(page+1)+')" style="font-family:arial;font-size:10px;">Next >></a>';
		}
		nav += '</td></tr>';
	
		if(nav!='<tr><td colspan="3" width="330" align="center" style="font-family:arial;font-size:10px;"></td></tr>'){
			html += nav;
		}
	
	    html += '</table>';
	    el.innerHTML = html;
		
		
		if(itemList.item(0)!=null){
		
			var nodeList = itemList.item(0).childNodes;
            for (var j = 0; j < nodeList.length ; j++) {
                var node = nodeList.item(j);
                if (node.nodeName == "id") {
                   setSelected(node.firstChild.nodeValue);
                }
            } 
			_gel("rad_0").checked = true;
		}
	    
		
		_gel("agree").checked = false;
	    _gel("submit0").style.display = "none";
	    _gel("submit1").style.display = "block";
	}
	
	function setSelected(yt_id){
		user_vid = yt_id;
		gadgetTracker._trackEvent('submit-videoRadioButtonClick');
	}
	function addToContest(){
		gadgetTracker._trackEvent('submit-addToContestClick');
		if(!_gel("agree").checked){
			alert("Please confirm that you agree to the stated rules");
			return;
		}
		
		
		
		
		stopVids();
		//show 
		_gel("submit0").style.display = "none";
		_gel("submit1").style.display = "none";
		_gel("submit3").style.display = "block";
	}
	
	function post(){
		if(video != null){
			gadgetTracker._trackEvent('postResponseClick');
		   window.open ("http://www.youtube.com/watch?v="+video.yt_id,"_blank");
		}
	}
	
	function upload(){
		gadgetTracker._trackEvent('uploadNewVidClick');
		window.open ("http://youtube.com/my_videos_upload","_blank");
	}
	
	function verifyCaptcha(){
		var url = "http://contests.labpixies.com/submit_video.php?cid="+contestID+"&vid="+user_vid+"&uid="+user_id+"&code="+_gel("captcha_text").value.toLowerCase()+"&cb=captchaResponse&tc="+escape("http://www.youtube.com/casiousa")+"&rand="+Math.round(Math.random()*100000);
		
		getJson(url, function(){_gel("userCaptchaError").innerHTML = 'Temporary unavailable, please try again in a few seconds';});
		_gel("userCaptchaError").innerHTML = '<img src="'+_IG_GetImageUrl('http://contests.labpixies.com/gadget/casio/images/loading.gif')+'" />';
		gadgetTracker._trackEvent('submit-imageTextEntered');
		return false;

	}
	
	function captchaResponse(response){
		clearTimeout(timerHandle);
		var el = _gel("userCaptchaError");
		el.innerHTML = '';
		if (response == null || typeof(response) != "object") {
			el.innerHTML = 'Temporary unavailable, please try again in a few seconds';
			return;
		}
		
		
		if(response.iserror == 0){
			_gel("submit0").style.display = "none";
			_gel("submit1").style.display = "none";
			_gel("submit3").style.display = "none";
			_gel("submit2").style.display = "block";
		}else if(response.iserror == 1){
			_gel('captcha').src='http://contests.labpixies.com/image.php?width=120&height=50&r='+Math.round(Math.random()*10000)
			el.innerHTML = '<span style="font-family:arial;color:red;">Please retype image text</span>';
			gadgetTracker._trackEvent('submit-imageTextWrong');
		}else if(response.iserror == 3){
			_gel('captcha').src='http://contests.labpixies.com/image.php?width=120&height=50&r='+Math.round(Math.random()*10000)
			el.innerHTML = '<span style="font-family:arial;color:red;">Sorry, you can only submit one video per contest</span>';
			gadgetTracker._trackEvent('submit-MoreThanOneVidError');
		}else{
			_gel('captcha').src='http://contests.labpixies.com/image.php?width=120&height=50&r='+Math.round(Math.random()*10000)
			el.innerHTML = '<span style="font-family:arial;color:red;">Temporary unavailable, please try again in a few seconds</span>';
			gadgetTracker._trackEvent('submit-submitError');
		}
	}
	
	function toggleButton(el){
		if(!voted_on_video){
			
			if(el.src.indexOf("_off")!=-1){
				el.src = el.src.replace("_off","_on");
			}else{
				el.src = el.src.replace("_on","_off");
			}
		}
	}
  
  //Utils
  function randOrd(){
	return (Math.round(Math.random())-0.5); 
  }
	 
  function getJson(b,errorReportFunction){
        
        clearTimeout(timerHandle);
        timerHandle = setTimeout(errorReportFunction,30000);
        var c=document.getElementsByTagName("head")[0];
        var d=document.createElement("script");
        d.type="text/javascript";
        d.charset="utf-8";
        d.defer="defer";
        var e=b;
        e=e+"&nocache="+_json_with_no_cache++;
        d.src=e;
        var f=function(){
            var j=d.parentNode;
            j.removeChild(d);
            delete d
        };
        var g=function(j){
            var s=(j?j:window.event).target?(j?j:window.event).target:(j?j:window.event).srcElement;
            if(s.readyState=="loaded"||s.readyState=="complete"){
                f();
                return;
            }
        };
        if(navigator.product=="Gecko"){
            d.onload=f;
        }else{
            d.onreadystatechange=g;
        }
        c.appendChild(d)
    }
  function _LP_EmbedFlash(_url, _id, _params){
      var isFF = ((navigator.userAgent.toLowerCase().indexOf("firefox") >= 0) || (navigator.userAgent.toLowerCase().indexOf("camino") >= 0));
      if(!isFF){
        _IG_EmbedFlash(_url, _id,  _params);
      }else{
        var params = _params;//eval("("+_params+")");
        _gel(_id).innerHTML = '<object width="'+params.width+'" height="'+params.height+'"><param name="movie" value="'+_url+'"></param><param name="wmode" value="'+params.wmode+'"></param><embed src="'+_url+'" type="application/x-shockwave-flash" wmode="'+params.wmode+'" width="'+params.width+'" height="'+params.height+'"></embed></object>';    
      }
    }
    
  String.prototype.trim = function() {
    a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
  };
  

   
</script>




<table id="mainTbl" style="display:none;" width="560" height="100%" border="0" cellpadding="0" cellspacing="0" >
  <tr>
    <td height="100%" width="275">
		<img id="main_left" border="0"  src="" style="margin-top:10px;" usemap="#map1" />
	</td>
	<td height="100%" width="285">
		<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
			<tr><td align="left" id="home_vid" width="285"></td></tr>
			<tr>
				<td align="right" width="285" valign="bottom" style="padding-right:1px;"><img id="img_rules"  src="" border="0" usemap="#map2"/></td>
			</tr>
		</table>
	</td>
  </tr>
 
</table>



<table width="560" height="300" id="submit" style="display:none;color:white" border="0" cellpadding="0" cellspacing="0">
	<tr>
    <td id="submit0" width="560" height="300">
      <table width="560" height="300" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td style="color:white;padding-left:60px;padding-right:60px;padding-top:60px;padding-bottom:20px;font-family:arial;font-size:12px;" width="560" height="150" align="left">
                Enter your YouTube user name to select one of your videos to be entered in the contest. Once you have selected the video, you will be asked to confirm your entry via email used to sign up for a YouTube account. 
            </td>
        </tr>
        <tr>
            <td width="560" align="center" valign="top">
              <form onsubmit="getUserVideos(); return false;"><input id="user_name" style="margin:2px; height:20px; font-family:arial;font-size:12px;" type="text" style="width:155px" /><input style="margin:2px; height:20px;font-family:arial;font-size:12px;" type="submit" value="Go" /></form>
            </td>
        </tr>
		<tr>
            <td id="userSearchError" width="560" align="center" valign="top" style="font-size:10px;color:red;font-family:arial">
              
            </td>
        </tr>
      </table>
    </td>
    <td id="submit1" style="display:none;padding:5px;" width="560" height="300">
        <table width="550" height="288" border="0" cellpadding="0" cellspacing="0">
          <tr>
              <td>
                <form onsubmit="addToContest(); return false;">
                <table width="550" height="260" border="0" cellpadding="0" cellspacing="0">
                  <tr>
                    <td width="370" height="260" align="center">
                      <table width="100%" style="background-color:#545454" height="260" border="0" cellpadding="0" cellspacing="0">
                        <tr><td style="padding-top:2px" align="center" height="20"><input type="button" onclick="upload(); return false;" value="Upload a New Video" /></td></tr>
						<tr><td style="padding:2px 10px 2px 10px;"><div style="width:350px;height:210px;background-color:white; overflow:auto;" id="userContent">&nbsp;</div></td></tr>
                        <tr><td style="padding-bottom:2px" align="center" height="20"><input type="submit" value="Add to Contest" /></td></tr>
                      </table>
                    </td>
                    <td width="100%" height="260">
                      <table width="100%" height="260" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                          <td id="smallVid"  align="center" height="195" valign="bottom">
                            <table width="172" height="129" style="">
									            <tr>
										            <td  align="center">
											            <span id="loading_small" style="font-size:12px;font-family:arial;align:center;margin-top:60px;">Click on a video thumbnail to view</span>
										            </td>
									            </tr>
								            </table>
                          </td>
                        </tr>
                        <tr><td id="smallName" align="center" style="font-size:10px;font-family:arial" valign="top">&nbsp;</td></tr>
                      </table>
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2" align="center" style="font-family:arial;font-size:11px; color:white;"><input onclick="gadgetTracker._trackEvent('submit-TnCCheck');" type="checkbox" id="agree" /> I agree to these <a target="_blank" onclick="gadgetTracker._trackEvent('submit-TnCLinkClick');" href="http://www.youtube.com/casiousa" style="color:white;">rules</a></td>
                  </tr>
                </table>
                </form>
              </td>
          </tr>
        </table>
    </td>
    <td id="submit2" style="display:none;" width="560" height="300">
        <table width="560" height="300" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td style="color:white;padding-left:60px;padding-right:60px;padding-top:60px;padding-bottom:20px;font-family:arial;font-size:12px;" width="560" height="150" align="left">
                We have sent you an email at the address provided during your YouTube sign up. Please click on the link to confirm that you have read the T&amp;C and want to enter this contest. To find the email associated with your YouTube account, please go to My Account -&gt; more -&gt; Account Settings -&gt; Email Options 
            </td>
        </tr>
        <tr>
            <td width="560" align="left" valign="top" style="padding-left:60px;">
              &nbsp;
            </td>
        </tr>
		<tr>
            <td id="userSearchError2" width="560" align="center" valign="top" style="font-size:10px;color:red;font-family:arial">
              
            </td>
        </tr>
      </table>
    </td>
	<td id="submit3" width="560" height="300">
      <table width="560" height="300" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td style="color:white;padding-top:60px;font-family:arial;font-size:12px;" width="560" height="100" align="center">
                Please type the text that appears in the following image
            </td>
        </tr>
		<tr>
            <td height="100" width="560" align="center">
                <img id="captcha" style="border: solid 1px rgb(20,40,100);" width="120" height="50" src="" /><br/>
				<a style="font-family:arial;font-size:10px;color:white;" href="javascript:void(0)" onclick="_gel('captcha').src='http://contests.labpixies.com/image.php?width=120&height=50&r='+Math.round(Math.random()*10000)">Can't read?</a>
            </td>
        </tr>
        <tr>
            <td width="560" align="center" valign="top">
              <form onsubmit="verifyCaptcha(); return false;"><input id="captcha_text" style="margin:2px; height:20px; font-family:arial;font-size:12px;" type="text" style="width:50px" /><input style="margin:2px; height:20px;font-family:arial;font-size:12px;" type="submit" value="Go" /></form>
            </td>
        </tr>
		<tr>
            <td id="userCaptchaError" width="560" align="center" valign="top" style="font-size:10px;color:red;font-family:arial">
              
            </td>
        </tr>
      </table>
    </td>
  </tr>
  
</table>
	
<div id="view" style="display:none;">
	<table  id="viewTbl" width="560" height="300" border="0" cellpadding="0" cellspacing="0" >
		<tr>
			<td  width="100%">
				<table  width="560"  border="0" cellpadding="0" cellspacing="0" >
					<tr>
						<td width="350" height="100%" align="center">
							<div id="plDiv" style="font-family:arial;width:330px;height:100%;align:center;vertical-align:middle;">
								<table width="280">
									<tr>
										<td  align="center">
											<span id="loading_vid" style="font-size:12px;font-family:arial;color:white;align:center;margin-top:100px;">Loading Video...</span>
										</td>
									</tr>
								</table>
							</div>
						</td>
						<td valign="top">
							<table  width="100%" border="0" cellpadding="0" cellspacing="0" >
								<tr><td height="20" style="font-family:arial;font-size:12px;color:white"><span id="vname" style="font-weight:bold;color:white"></span></td></tr>
								<tr><td height="20" style="font-family:arial;font-size:12px;color:white">From: <a href="javascript:void(0);" style="font-weight:bold;color:white" id="uname" target="_blank">--</a></td></tr>
								<tr><td height="20" style="font-family:arial;font-size:12px;color:white">Views: <span id="views" >--</span></td></tr>
								<tr><td height="35" valign="bottom"><input style="font-weight:bold;font-family:arial;font-size:12px;" type="button" onclick="post();" value="Post A Response" /></td></tr>
								<tr><td height="60" ><span style="color:#919191;font-weight:bold;font-size:11px;font-family:arial;" id="vote_text">0</span>&nbsp;&nbsp;<img id="butt0" style="cursor:pointer;vertical-align: middle" onmouseout="toggleButton(this);" onmouseover="toggleButton(this);" onclick="reportVote(1);" src="" />&nbsp;&nbsp;<img id="butt1" style="cursor:pointer;vertical-align: middle" onmouseout="toggleButton(this);" onmouseover="toggleButton(this);" onclick="reportVote(0);" src="" /></td></tr>
								<tr><td height="20" valign="middle" style="cursor:pointer;color:white" onclick="changeVid();"><strong>Next Video >></strong></td></tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td  width="100%" align="center" style="font-family:arial;font-size:12px; " valign="middle">
			<form onsubmit="search(); return false;"><span style="margin:2px; height:20px;color:white">Search for a video:</span> <input id="search_text" style="margin:2px; height:20px; font-family:arial;font-size:12px;" type="text" style="width:155px" /><input style="margin:2px; height:20px;font-family:arial;font-size:12px;" type="submit" value="Go" /></form>
			<div id="search_results"  width="100%" align="center" style="display:none;font-family:arial;font-size:12px;color:white;">
				Search results
			</div>
			</td>
			
		</tr>
		
<table>
</div>

<img id="report_pixel" src="" width="1" height="1" style="position:absolute;top:-10px;left:-10px;" />


<table  id="results" style="margin-top:3px;display:none;height:300px;" width="560" height="300" border="0" cellpadding="0" cellspacing="0" >
	<tr >
		<td  width="100%" align="center" style="padding-top:5px;padding-bottom:5px;font-family:arial;font-size:12px; " valign="middle">
		<div id="win_results"  width="100%" align="center" style="font-family:arial;font-size:12px; ">
			Loading...
		</div>
		</td>
		
	</tr>	
	<tr>
		<td  width="100%" valign="top" style="padding-top:5px;">
			<table  width="560" height="180" border="0" cellpadding="0" cellspacing="0" >
				<tr>
					<td width="340" height="100%" align="right" valign="top">
						<div id="resDiv" style="font-family:arial;width:240px;height:180px;align:center;vertical-align:middle;">
							<table width="240">
								<tr>
									<td  align="center">
										<span id="loading_res_vid" style="font-size:12px;font-family:arial;align:center;margin-top:80px;">Loading Video...</span>
									</td>
								</tr>
							</table>
						</div>
					</td>
					<td valign="top" align="left" style="padding-left:10px">
						<table  width="100%" border="0" cellpadding="0" cellspacing="0" >
							<tr><td colspan="2" height="20" style="font-family:arial;font-size:12px;color:white;"><span id="res_vname" style="font-weight:bold;color:white;"></span></td></tr>
							<tr><td colspan="2" height="20" style="font-family:arial;font-size:12px;color:white;">From: <a href="javascript:void(0);" style="font-weight:bold;color:white;" id="res_uname" target="_blank">--</a></td></tr>
							<tr><td colspan="2" height="20" style="font-family:arial;font-size:12px;color:white;">Views: <span id="res_views" style="color:white;">--</span></td></tr>
							<tr style="display:none;"><td id="bar_selected" style="background-color:#55A90B;width:0px;">&nbsp;</td><td height="20" valign="middle" id="percent_selected"><strong>&nbsp;</strong> </td></tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	
<table>

<map name="map1" id="map1"><area shape="rect" coords="35,76,215,119" href="#" onclick="tabs.setSelectedTab(1);return false;" /></map>

<map name="map2" id="map2"><area shape="rect" coords="50,4,173,20" href="http://www.pointshootupload.com/rules.html" target="_blank" /></map>
<map name="map3" id="map3">
  <area shape="rect" coords="316,15,523,91" href="http://www.bestbuy.com/casio" target="_blank">
</map>
<script type="text/javascript">
	
	_gel("butt0").src = _IG_GetImageUrl("http://contests.labpixies.com/gadget/casio/images/love_it_off.gif");
	_gel("butt1").src = _IG_GetImageUrl("http://contests.labpixies.com/gadget/casio/images/down_off.gif");
	
	
	
	window.onload = initTabs;
</script>

<script type="text/javascript">
	var pageTracker = _gat._getTracker("UA-784260-35");//rby-13-nov
    pageTracker._initData();
    pageTracker._trackPageview();
	var gadgetTracker = pageTracker._createEventTracker('Gadget');
</script>


	]]>
</Content>
</Module>