﻿
var mouseX, mouseY = 0;

$(document).ready(function()
{
        $.easing.def = 'easeOutBounce';
    
        $().mousemove(function(e){
          mouseX = e.pageX;
          mouseY = e.pageY;
       });
       
        loadEffects();
            
        $(window).resize(function(){
            $("#popin_coverDiv").height($(window).height());
	        $("#popin_coverDiv").width($(window).width());
	        $("#popin_coverDiv").height($(document).height());
	        $("#popin_coverDiv").width($(document).width());
        });


        $("input[id$=CritterImage]").change(function()
        {
            if($.browser.mozilla)
            {
                $(window.parent.document.getElementById('uploadImageFrame')).hide();
            }
            this.form.submit();
        });

        $("#uploadImageFrame").ready(function()
        {
            if($("input[id$=CritterImageSrcFileName]").attr("value") > "")
            {
                if($("input[id$=CritterImageSrcFileName]").attr("value") == "BADDATA")
                {
                    alert("Invalid file format.\r\nPlease try a different file.");
                    return;
                }
                //prompt('/SuperDuper.aspx?layout=popin&i=' + $("input[id$=CritterImageSrcFileName]").attr("value") + '&r=' + Math.random(), '/SuperDuper.aspx?layout=popin&i=' + $("input[id$=CritterImageSrcFileName]").attr("value") + '&r=' + Math.random());
                window.parent.showPopin('/SuperDuper.aspx?layout=popin&i=' + $("input[id$=CritterImageSrcFileName]").attr("value") + '&r=' + Math.random(), 682, 483, 'genericPopin');
            }
        });
        
        if(alertMessage != null && alertMessage == "VerifyEmail")
        {
            alert("Check your email to verify your address, keeping in mind our wonderful verification email might've ended up flagged as junk. Click to verify and your mascot should be up.");
        }

        setTimeout("$('#home_top_critter').animate({top:'0px'}, 700);", 300);
        setTimeout("$('#home_bestiary').animate({top:'0px'}, 700);", 600);
        setTimeout("$('#home_submit').animate({top:'491px'}, 300, 'easeInQuad');", 1100);
        setTimeout("$('#home_left_text').show('scale', {percent: 100}, 400);", 1900);
        setTimeout("$('#home_right_text').show('scale', {percent: 100}, 400);", 1900);
        setTimeout("$('#home_top_text').animate({top:'76px'}, 300, 'easeInQuad');", 1300);
        setTimeout("$('#marlin_logo').show('scale', {percent: 100}, 600);", 900);
        

        


});

$(function()
{
 $('.auto-submit-star').rating(
 {
 
  callback: function(value, link)
  {

   var g = this.name.toString().substr(3, 36);

   if(value == '') value = -999;
   $.get("/CastVote.aspx?c=" + g + "&v=" + value + "&r=" + Math.random(), function(data)
    {
    
    });

  }
 });
});


function loadViewCritter(in_CritterId, in_Href)
{
    $("#view_big_" + in_CritterId).load(in_Href, "", function(){
        $("#view_big_" + in_CritterId).fadeIn(400);
    });
}

function triggerImageUpload()
{

      IFrameObj = document.getElementById('uploadImageFrame');
      var IFrameDoc;
      if (navigator.userAgent.indexOf('Gecko') !=-1 
        && !IFrameObj.contentDocument) {
        // we have to give NS6 a fraction of a second
        // to recognize the new IFrame
        setTimeout('callToServer()',10);
        return false;
      }

      if (IFrameObj.contentDocument) {
        // For NS6
        IFrameDoc = IFrameObj.contentDocument; 
      } else if (IFrameObj.contentWindow) {
        // For IE5.5 and IE6
        IFrameDoc = IFrameObj.contentWindow.document;
      } else if (IFrameObj.document) {
        // For IE5
        IFrameDoc = IFrameObj.document;
      } else {
        return true;
      }

    if(!$.browser.mozilla)
    {
        IFrameDoc.getElementById(IFrameDoc.getElementById("critterImageControlId").value).click();
    }
    else
    {
        $(IFrameObj).fadeIn(300);
    }
}

function loadEffects()
{
    if($.browser.msie)
    {
        if($.browser.version == "6.0")
        {
           return;
        }
        
    }

            $(".ui-fade-rollover").each(function(){
	            if($(this).attr("effect_loaded") == "true") return;
	            $(this).attr("effect_loaded", "true"); 
	            var wrapper = "<div style='display: block; height: auto; width: auto; background-repeat: no-repeat; background-image: url(" + $(this).attr("src").replace("_off", "_over") + ")'></div>";
	            if($(this).parent().get(0).tagName == "A")
	            {
		            $(this).parent().wrap(wrapper);
	            }
	            else
	            {
		            $(this).wrap(wrapper);
	            }
	            
	            $(this).bind("mouseenter", function(e){
	                $(this).stop().animate({opacity: 0}, 300);
	            });
	            $(this).bind("mouseleave", function(e){
	                $(this).stop().animate({opacity: 1}, 300);
	            });

            });

            $(".ui-swap-rollover").each(function(){
	            if($(this).attr("effect_loaded") == "true") return;
	            $(this).attr("effect_loaded", "true"); 
	            $(this).bind("mouseenter", function(e){
	                $(this).attr("src", $(this).attr("src").replace("_off", "_over"));
	            });
	            $(this).bind("mouseleave", function(e){
	                $(this).attr("src", $(this).attr("src").replace("_over", "_off"));
	            });

            });
            
            
        	$("#home_top_critter").bind("mouseenter", function(e){
                $("#top_critter_img").attr("src", $("#top_critter_img").attr("src").replace("_off", "_over"));
            });
            
            $("#home_top_critter").bind("mouseleave", function(e){
                $("#top_critter_img").attr("src", $("#top_critter_img").attr("src").replace("_over", "_off"));
            });
            

            
            
}

