// JavaScript Document
$(document).ready(function() {
	init_Manello();
	init_Quiz();
});


var numRight = Array();

function init_Quiz() {
	$(".answer").click(function() {
		value = $(this).val();
		group = $(this).attr("name");
		if (value == 0) {
			numRight[parseInt(group)-1] = true;
		}
		else {
			numRight[parseInt(group)-1] = false;			
		}
	});
	
	$('#submitButton').click(function() {
		right = 0;
		for (key in numRight) {
			if (numRight[key] == true) right++;
		}
		$("#response").attr("src", "/images/response_"+right+".png");
		return false;
	})
}


function init_Manello() {
		$('#ca').hide();
		$('img.caFlagLnk').replaceWith('<img src="images/flag_can_off.jpg" class="caFlagLnk"/>');
		$('img.usFlagLnk').live('click', function(){
			$('#us').show();
			$('#ca').hide();
			$(this).replaceWith('<img src="images/flag_usa.jpg" class="usFlagLnk"/>');
			$('img.caFlagLnk').replaceWith('<img src="images/flag_can_off.jpg" class="caFlagLnk"/>');
		});
		$('img.caFlagLnk').live('click', function(){
			$('#ca').show();
			$('#us').hide();
			$(this).replaceWith('<img src="images/flag_can.jpg" class="caFlagLnk"/>');
			$('img.usFlagLnk').replaceWith('<img src="images/flag_usa_off.jpg" class="usFlagLnk"/>');
		});
	  //$('#stores').jShuffle();
	  //$('#stores').slideshow({playframe:false,time:6000,title:false, width: 140, height: 40 }).playSlide();
	  $f("player", "swf/flowplayer-3.1.2.swf", {
	    clip: {
			autoPlay: true,
			scaling: 'fit',
			onCuepoint: [[5000,10000,30000,60000], function(clip, cuepoint) {
			var x = cuepoint/1000;
			if(x==5){
				pageTracker._trackEvent("Videos", 'VideoStart', clip.url);
			}
			else{
				pageTracker._trackEvent("Videos", x + 'Seconds', clip.url);
			}
			 
		}],
		onFinish: function(clip) {             
            pageTracker._trackEvent("Videos", "VideoFinish", clip.url);         
        }
		},
		canvas: {
			backgroundColor: '#ffffff',
			backgroundGradient: 'none'
		},
		plugins: {
			controls: {
				sliderGradient: 'none',
				bufferGradient: 'none',
				tooltipTextColor: '#ffffff',
				durationColor: '#fafafa',
				sliderColor: '#ed1c24',
				buttonColor: '#ed1c24',
				progressGradient: 'medium',
				volumeSliderGradient: 'none',
				backgroundColor: '#ffffff',
				timeBgColor: '#555555',
				toolTipColor: '#5f747c',
				backgroundGradient: 'none',
				borderRadius: '0',
				progressColor: '#ed1c24',
				bufferColor: '#fbdedf',
				buttonOverColor: '#ba161c',
				timeColor: '#e3d9d9',
				volumeSliderColor: '#000000',
				height: 24,
				opacity: 1.0,
				autoHide: true
			}
		}
	  });
	  $('#nav').jcarousel({start: cStart});
	  
		$(".ovAction").overlay({
			onBeforeLoad: function() {
			  $f().hide().pause();
			  this.getBackgroundImage().expose({color: "#000000"});
		    },  
			 onClose: function() {
			   $f().show().resume();
			   $("#info").hide();
			    $.expose.close();
		      } 
		 });
		
	 $("#shareForm").submit(function(e) {
				  var form = $(this);
			      form.fadeTo(500, 0.1);
			      $.getJSON(form.attr("action") + "?" + form.serialize() + "&format=json&jsoncallback=?", function(json) {
				    form.fadeTo(500, 1);
				    var info = $("#info").show();
				    if (json.message) {
					  info.addClass("alert").html(json.message);			
				    } else {
					  info.removeClass("alert").addClass("info").html("Email was successfully sent");
				    } 
			     });	
			     e.preventDefault();
			     return false;		
		       });
			   $("#embedPane textarea").html($f().embed().getEmbedCode());
	    	   $("#shareTabs").tabs("#panes > div");
}


function bookmark(service) {
	switch(service) {
		case "myspace":
			url = "http://www.myspace.com/Modules/PostTo/Pages/?t="+document.title+"&u="+window.location.href;
			break;
		case "facebook":
			url = "http://www.facebook.com/sharer.php?t="+document.title+"&u="+window.location.href;
			break;
		case "digg":
			url = "http://digg.com/submit/?phase=2&url="+window.location.href+"&title="+document.title+"&topic=videos_entertainment"
			break;
		case "delicious":
			url = "http://delicious.com/save?url="+window.location.href+"&title="+document.title;
		break;
		case "twitter":
			url = "http://twitter.com/home?status=I'm playing "+document.title+" at "+window.location.href;
		break;
		case "stumbleupon":
			url = "http://stumbleupon.com/submit?url="+window.location.href+"&title="+document.title;
		break;
		case "slashdot":
			url = "http://slashdot.org/bookmark.pl?url="+window.location.href;
		break;
		case "google":
			url = "http://www.google.com/bookmarks/mark?op=add&bkmk="+window.location.href;
		break;
		case "linkedin":
			url = "http://www.linkedin.com/shareArticle?mini=true&url="+window.location.href;
		break;
		case "reddit":
			url = "http://reddit.com/submit?url="+window.location.href;
		break;
	}
	popout_to(url);
}

function redirect_to(url) {
	window.location.href = url;
}

function popout_to(url, name, features) {
	if (!name) name = null;
	if (!features) features = null;
	window.open(url, name, features);
	return false;
}

function reload() {
	window.location.reload();
}