﻿// share config
share.tracking = true;
share.url = 'http://www.GreenHornetMovie.com';
share.title = 'Check out the The Green Hornet official movie site!';
share.tweet = 'Check out the @GreenHornet official movie site! http://www.GreenHornetMovie.com';
share.description = 'Check out the The Green Hornet official movie site!';


// overlayPlayer config
feedUrl = "http://www.sonypictures.com/previews/movies/thegreenhornet.xml";
autocloseToggle = true;
singlevideoToggle = false;

var flashversion = '10';

if(typeof(swfobject)=='object' && swfobject.hasFlashPlayerVersion(flashversion)){
	var head = document.getElementsByTagName('head');
	var flashstyle = document.createElement('style');
	var css = '#enterthesite-button, #ticketing p {display: none}';
	flashstyle.setAttribute('type','text/css');

	if(head[0]){
		if(flashstyle.styleSheet){ //cause you can't put text in the webstandards way in ie
			flashstyle.styleSheet.cssText = css;
		}else{
			flashstyle.appendChild(document.createTextNode(css));
		}
		head[0].appendChild(flashstyle);
	}
}

function loadEnterButton() {
	var swfName,
		height,
		divName = 'entersite',
		rand = Math.floor(Math.random() * 2);
		
	switch(rand) {
	case 0: 
		swfName = 'enterbutton-a.swf';
		height = 80;
		break;
	case 1: 
		swfName = 'enterbutton-b.swf';
		height = 174;
		break;
	}

	var flashvars = {};
	var params = {
		allowscriptaccess: 'always',
		wmode: 'opaque'
	};	
	var attributes = {};	
	
	if(typeof(swfobject)=='object' && swfobject.hasFlashPlayerVersion(flashversion)){	
		document.getElementById(divName).style.height = height + 'px';
		swfobject.embedSWF('media/' + swfName, divName, '265', height, flashversion, '', flashvars, params, attributes);
	}
}

function ticketingWidget() {
	var flashvars = {};
	var params = {
		allowscriptaccess: 'always',
		wmode: 'opaque'		
	};	
	var attributes = {};
	swfobject.embedSWF('media/sa_widget.swf', 'ticketing', '257', '335', flashversion, '', flashvars, params, attributes);
}

addLoadEvent(loadEnterButton);
addLoadEvent(ticketingWidget);

function shareLinks() {
	$('#share li a').bind('click', function() {
		share.send($(this).attr('rel'));
		return false;
	});
}

function watchVideo() {
	
	$('#watch-video').hover(
		function () {
			if($('#videos').is(':hidden')) {
				$('#watch-video').addClass('video-hover');
			}
		},
		function () {
			$('#watch-video').removeClass('video-hover');
		}
	);
	
	$('#watch-video').bind('click', function() {
	
		if (!$('#connect').is(':animated')) {
			if($('#connect').is(':visible')) {
				$('#connect').slideToggle('normal', function() {
					$('#connect-share').css({ 'background-position': '0px 0px' });
				});
			}
		}
		
		var self = $(this);
		if (!$('#videos').is(':animated')) {
			if($('#videos').is(':hidden')) {
				$('#videos').slideToggle();
				self.removeClass('video-hover');
				self.addClass('video-expanded');				
			} else {					
				$('#videos').slideToggle('normal', function() {
					self.removeClass('video-expanded');
				});
			}			
			return false;
		}
	});
	
	$('#watch-trailer').bind('click', function() {
		openOverlay();
		return false;
	});
	
	$('#watch-itrailer').bind('click', function() {
		window.open(this.href, '', 'width=640, height=410, scrollbars=no, resizable=no');
		return false;
	});
}

function connectAndShare() {
	
	$('#connect-share').hover(
		function () {
			if($('#connect').is(':hidden')) {
				$('#share').addClass('connect-hover');
			}
		},
		function () {
			$('#share').removeClass('connect-hover');
		}
	);
	
	$('#connect-share').bind('click', function(e) {	
	
		if (!$('#videos').is(':animated')) {
			if($('#videos').is(':visible')) {
				$('#videos').slideToggle('normal', function() {
					$('#watch-video').removeClass('video-expanded');
				});
			}
		}
		
		var self = $(this);
		if (!$('#connect').is(':animated')) {
			if($('#connect').is(':hidden')) {
				self.css({ 'background-position': '0px -118px' });
				$('#connect').slideToggle();
				$('#connect').css({ 'background-position': '0px -175px' });
				$('#share').removeClass("connect-hover");
			} else {					
				$('#connect').slideToggle('normal', function() {
					self.css({ 'background-position': '0px 0px' });
				});
			}			
			return false;
		}
	});
}

function regPop() {
	$('#register').bind('click', function() {
		window.open(this.href, '', 'width=446, height=500, scrollbar=no, resizable=no');
		return false;
	});
}

$(function() {

	shareLinks();
	watchVideo();
	connectAndShare();
	regPop();	
	
});


