var no_flash  = false;
var links_share = {
                    sharefacebook_button: 'http://www.facebook.com/sharer.php',
                    sharetwitter_button: 'http://twitter.com',
                    sharemyspace_button: 'https://www.myspace.com',
                    sharedigg_button: 'http://digg.com',
                    sharedelicious_button: 'https://secure.delicious.com',
                    sharestumbleupon_button: 'http://www.stumbleupon.com'
                  }

$(document).ready(function(){
	$(".launchgallery").colorbox({width:"800", inline:true, href:"#photo-gallery"});
	
	$("#main-icon-loadding").css('visibility', 'visible');
	
	//Example of preserving a JavaScript event for inline calls.
	$("#click").click(function(){ 
		$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
		return false;
	});
	$(".glasses-switch").click(function(){ 
		$('.regular-section').hide();
		$('.glasses-section').show();
	});
	$(".regular-switch").click(function(){ 
		$('.glasses-section').hide();
		$('.regular-section').show();
	});
  $('.trailer-button').click(function(event){
    event.stopPropagation();
    event.preventDefault();
    no_flash ? open_html_player() : openOverlay();
  });
  
  Shadowbox.init({ moadal :true, animate: false, initialWidth: 640, overlayOpacity: .8, initialHeight: 425 });

  window.setTimeout(start_application, 3000);

      $(".play-button").click(function(event)
      {
        event.stopPropagation();
        event.preventDefault();

        var url = $(this).attr("href");

        if (isOmnitureExists())  sCode.trackFeaturedContentClick(url, 'entergame_button'); 

        open_page(url);
      });
      
      $(".priest-yourself-button").click(function(event)
      {
        event.stopPropagation();
        event.preventDefault();

        var url = $(this).attr("href");

        if (isOmnitureExists())  sCode.trackOutboundClick(url, 'priest_3d_app_button'); 

        open_page(url);
      });

      $(".challenge-button").click(function(event)
      {
        event.stopPropagation();
        event.preventDefault();

		var url = $(this).attr("href");

        if (isOmnitureExists())  sCode.trackOutboundClick(url,'challenge_button'); 

		open_page(url);
      });
      
      $(".launchgallery").click(function(event)
      {
         $("#background").css('display', 'none');
         
        if (isOmnitureExists()) sCode.trackFeaturedContentClick("http://" + window.location.host,'gallery_button');
      });
      
      $("#cboxOverlay").click(function(event)
      {
        $("#background").css('display', 'block');
      });
      
      $("#cboxClose").click(function(event)
      {
        $("#background").css('display', 'block');
      });
      
      // Click share buttons
      $("a[class*='share']").click(function(event)
      {
        event.stopPropagation();
        event.preventDefault();
            
        var url       = $(this).attr("href");
        var uniqueId  = $(this).attr("class");
        
        if (isOmnitureExists())
        {
          sCode.trackOutboundClick(links_share[uniqueId], uniqueId); 
        }
    
        open_page(url);
      });
});

function start_application(){
  if( swfobject.hasFlashPlayerVersion('9.0.18') != true ){
    no_flash = true;
    $("#background").css('display', 'none');
    $("#background").css('visibility', 'visible');
    $("#background").ready(function(){
      show_page();
    });
  }
}

function show_page(){
  $("body").find('#main-icon-loadding').remove();

  if(!no_flash)sCode.trackPageView('splash.flash'); 
  if(is_mobile())$("#flashcontent").css('display', 'none');
     
  $("#likebar").fadeIn(600);
  
  if(is_mobile() || !no_flash) 
  {
    $("#background").fadeIn(600);
    $("#container").fadeIn(600);
  }
  else if(no_flash)
  {
    $("#background").css('background-image', 'none');
    $("#background").fadeIn(600);
    $('#flashcontent').append("<div id='feedback'><h1>Priest</h1><p>Based on the comic book by Min-Woo Hyung, Priest centers on a warrior priest (Paul Bettany) who disobeys church law by teaming with a young sheriff (Cam Gigandet) who is part vampire and a priestess to track down a band of renegade vampires who have kidnapped the priest's niece.</p><br><p>To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. <a rel='external' href='http://www.adobe.com/go/getflashplayer' target='_blank'>Get the free Adobe Flash Player.</a></p></div>");
  }

}

function open_html_player(){
  Shadowbox.open({ player: 'iframe', content: 'videoplayer.html', width: 640, height: 425 });
}

function open_page(link)
{
		var pop = window.open( link, 'open_rating', '' );
	  !pop ? alert('Please disable your popup blocker and try again.') : '';
}

function is_mobile() { return /iP(ad|hone)/.test(navigator.userAgent.toString()) ? true : false; }

function isOmnitureExists()
{
    //s.pageName is passed in through omniture code. This is assuming
    //that omniture code exists on every page. It is currently inject thru treatments
    //hence currently omniture code does exist in every page. 
    if (s != null && (s.pageName.length != 0))
        return true;
    else return false;
}
