var mouseOverCounter=0;
var mouseOutCounter=0;
var posnTabVivaLeft="32px";
var posnTabVivaTop="74px";
var posnTabRegimeLeft="135px";
var posnTabRegimeTop="74px";
var posnTabBluHandLeft="236px";
var posnTabBluHandTop="75px";
var posnTabBlogLeft="334px";
var posnTabBlogTop="74px";
var posnTabMediaLeft="433px";
var posnTabMediaTop="74px";
var posnTabAdventuresLeft="535px";
var posnTabAdventuresTop="74px";
var posnTabHelfLeft="637px";
var posnTabHelfTop="74px";

$(document).ready(function(){
  animateHotRod();
  setEmailAddress();
  // used for Videos jquery.media.js plugin
  // overrides value in jquery.media.js
  $.fn.media.defaults.flvPlayer = 'assets/media/mediaplayer.swf';
  $('a.media').media(); 

   // note: $.url.paramAll() returns an associative array object, so it has no .length property
   var params = $.url.paramAll();
   var count = 0;
   for (var i in params) {
      count++;
   }
   // if we have a a.showComments link and a commentsDiv div on the page 
   // and the page has more than 1 url parameter, assume jot comments have turned on shown
   if($(".commentsDiv").length > 0 && $("a.showComments").length > 0 && count > 1) {
     $(".commentsDiv").css({display: "block"});
     $("a.showComments").html("Hide comments");
   }

  // get the id of the main menu item thats active and position it over the tab when the document is ready
  var activeMenuItemId = $(".mainNavUL li.active").attr("id");
  positionActiveIcon(activeMenuItemId);

  function animateHotRod() {
    // reset the hotrod position after the end of the previous animation
    $("#hotRod").css({position: "absolute", left: "-25px", top: "35px"});
    // animate the hotrod
    $("#hotRod").animate({left: "+=2000px"}, 9000, function () {
       // the last parameter to the animate() function is a callback function which is only called once the animation is complete.
      // Once it is complete we call it again. This allows it to keep repeating after it finishes.
      animateHotRod();
    });              
  }

  $('.loginPanelLeftCell').mouseover(function() {
    $(this).css({cursor: "arrow", backgroundImage: 'url(assets/images/login.over.png)'});
    $(this).attr("alt", "Login");
    $(this).attr("title", "Login");
  });	    

  $('.loginPanelLeftCell').mouseout(function() {
    $(this).css({cursor: "pointer", backgroundImage: 'url(assets/images/login.png)'});
    $(this).attr("alt", "");
    $(this).attr("title", "");
  });	   

  $('.loginPanelLeftCell').click(function() {
    var leftValue = $(".loginPanelRow").css("left");
    leftValue = parseInt(leftValue,10);
    log.debug(".loginPanelRow left before: " + leftValue);
    if(leftValue == 0) { 
      $(".loginPanelRow").animate({left: "+=300px"}, 600, function () {
        log.debug("making invisible");
        log.debug(".loginPanelRow left after: " + leftValue);
      });
    } else { 
      $(".loginPanelRow").animate({left: "-=300px"}, 600, function () {
        log.debug("making visible");  
        log.debug(".loginPanelRow left after: " + leftValue);
      });		
    }
    log.debug(".loginPanelRow left after2: " + leftValue);
  });


  $('.logoutPanelLeftCell').mouseover(function() {
    $(this).css({cursor: "arrow", backgroundImage: 'url(assets/images/logout.over.png)'});
    $(this).attr("alt", "Logout");
    $(this).attr("title", "Logout");
  });	    

  $('.logoutPanelLeftCell').mouseout(function() {
    $(this).css({cursor: "pointer", backgroundImage: 'url(assets/images/logout.png)'});
    $(this).attr("alt", "");
    $(this).attr("title", "");
  });	   

  $('.logoutPanelLeftCell').click(function() {
    var leftValue = $(".loginPanelRow").css("left");
    leftValue = parseInt(leftValue,10);
    log.debug(".loginPanelRow left before: " + leftValue);
    if(leftValue == 0) { 
      $(".loginPanelRow").animate({left: "+=300px"}, 600, function () {
        log.debug("making invisible");
        log.debug(".loginPanelRow left after: " + leftValue);
      });
    } else { 
      $(".loginPanelRow").animate({left: "-=300px"}, 600, function () {
        log.debug("making visible");  
        log.debug(".loginPanelRow left after: " + leftValue);
      });		
    }
    log.debug(".loginPanelRow left after2: " + leftValue);
  });

  // handle placement of pescatore icon over tabs on mouseover/mouseout
  $(".mainNavTab").mouseover(function(e) {
    // we need the parent item id of the wrapping list item, since the spiffyNav div doesnt have an id
    // log.debug("DOM parentNode: " + this.parentNode);
    // log.debug("$ parentNode: " + $(this).parent().get(0).id);
    log.debug("mouseover main nav link");
    var currentListItemId = $(this).parent().get(0).id;
    mouseOverCounter = mouseOverCounter + 1;
    log.debug("mouseOVER " + mouseOverCounter + "for element: " + currentListItemId);
    // get the id of the main menu item thats active
    var activeMenuItemId = $(".mainNavUL li.active").attr("id");
    if(activeMenuItemId == currentListItemId) {
      return;
    }
    // remove the active icon from view
    $("#tabBlueHandOn").css({position: "absolute", left: "-50px", top: "-50px"});
    $("#tabPescatoreOn").css({position: "absolute", left: "-50px", top: "-50px"});
    // position the mouseover icon over this tab
    positionMouseOverIcon(currentListItemId);
  });

  $(".mainNavTab").mouseout(function() {
    log.debug("mouseout main nav link");
    // we need the parent item id of the wrapping list item, since the spiffyNav div doesnt have an id
    var currentListItemId = $(this).parent().get(0).id;
    mouseOutCounter = mouseOutCounter + 1;
    log.debug("mouseOUT " + mouseOutCounter + "for element: " + currentListItemId);
    // get the id of the main menu item thats active
    var activeMenuItemId = $(".mainNavUL li.active").attr("id");
    if(activeMenuItemId == currentListItemId) {
      return;
    }
    // remove the mouseover icon from view
    $("#tabBlueHandOver").css({position: "absolute", left: "-50px", top: "-50px"});
    $("#tabPescatoreOver").css({position: "absolute", left: "-50px", top: "-50px"});
    // put the active icon back in place
    positionActiveIcon(activeMenuItemId);
  });
	
    $("a.showComments").click(function() {
      log.debug("clicked showComments ");
      var currentState = $(".commentsDiv").css("display");
	    log.debug("currentState: " + currentState);
	    if(currentState == "none") {
        $(".commentsDiv").css({display: "block"});
	    	$(this).html("Hide comments");
  	  } else {
	      $(".commentsDiv").css({display: "none"});
	      $(this).html("Show comments");
	    }
    });

    $("#ajaxSearch_submit").mouseover(function() {
        $(this).css("background-image","url(assets/images/button.search2a.over.png)");
    });
    $("#ajaxSearch_submit").mouseout(function() {
        $(this).css("background-image","url(assets/images/button.search2.png)");
    });
    
    var strFantasticoPescatore = " Is this the real pescatore? FANASTICO PESCATORE!!!!!!!<br><br>The real pescatore has been sighted by a private detective we hired to follow his movements somewhere in the spanish town of hot dorito. He was seen driving a hot rod and leading the wild life on the high seas. When approached by our private detective and asked if he was the real pescatore, he just filled our detectives glass with wine and said \"FANTASTICO PESCATORE\"! What an incredible man!!!!!<br><br>Have a look around the site for more fabulous pescatore news, and to see if our private detective has made it back from the wild orgies with pescatore !";

    $("#headerImage").mouseover(function() {
      $(this).attr("alt", strFantasticoPescatore);
      $(this).attr("title", strFantasticoPescatore);
      $(this).css({cursor: "arrow"});
    });
    $("#headerImage").mouseout(function() {
      $(this).attr("alt", "");
      $(this).attr("title", "");
      $(this).css({cursor: "pointer"});
    });


/*  turned off: the a href in vpJCarouselVideosLI now does the work instead
    $("#pescatoreVideos111").click(function() {
      $("div.media embed").attr({src: "assets/media/mediaplayer.swf?file=assets/media/pescatore.videos.patatas.bravas.flv"});
      $("div.media div").html("Patatas Bravaas");
	  $("#pescatoreVideos li").removeClass("active");
	  $(this).addClass("active");
    });

    $("#pescatoreVideos112").click(function() {
      log.debug("clicked #pescatoreVideos112");
      $("div.media embed").attr({src: "assets/media/mediaplayer.swf?file=assets/media/pescatore.videos.scary.rabbit.flv"});
      $("div.media div").html("Oooo ... Scary rabbit");
	  $("#pescatoreVideos li").removeClass("active");
	  $(this).addClass("active");
    });

    $("#pescatoreVideos113").click(function() {
      $("div.media embed").attr({src: "assets/media/mediaplayer.swf?file=assets/media/pescatore.videos.homerpalooza.flv"});
      $("div.media div").html("Homerpalooza");
	  $("#pescatoreVideos li").removeClass("active");
	  $(this).addClass("active");
    });

    $("#pescatoreVideos114").click(function() {
      $("div.media embed").attr({src: "assets/media/mediaplayer.swf?file=assets/media/pescatore.videos.puddies.flv"});
      $("div.media div").html("Puddiiieeessss");
	  $("#pescatoreVideos li").removeClass("active");
	  $(this).addClass("active");
    });
*/

  
}); 

// -------------------- end $(document).ready -----------------------

function positionActiveIcon(activeMenuItemId) {
  log.debug("positionActiveIcon: " + activeMenuItemId);
  if(activeMenuItemId == "mainMenuNavItem65") {
    $("#tabPescatoreOn").css({position: "absolute", left: posnTabVivaLeft, top: posnTabVivaTop});
  } else if(activeMenuItemId == "mainMenuNavItem66") {
    $("#tabPescatoreOn").css({position: "absolute", left: posnTabRegimeLeft, top: posnTabRegimeTop});
  } else if(activeMenuItemId == "mainMenuNavItem67") {
    $("#tabBlueHandOn").css({position: "absolute", left: posnTabBluHandLeft, top: posnTabBluHandTop });
  }  else if(activeMenuItemId == "mainMenuNavItem76") {
    $("#tabPescatoreOn").css({position: "absolute", left: posnTabBlogLeft, top: posnTabBlogTop});
  }  else if(activeMenuItemId == "mainMenuNavItem102") {
    $("#tabPescatoreOn").css({position: "absolute", left: posnTabMediaLeft, top: posnTabMediaTop});
  }  else if(activeMenuItemId == "mainMenuNavItem97") {
    $("#tabPescatoreOn").css({position: "absolute", left: posnTabAdventuresLeft, top: posnTabAdventuresTop});
  }  else if(activeMenuItemId == "mainMenuNavItem116") {
    $("#tabPescatoreOn").css({position: "absolute", left: posnTabHelfLeft, top: posnTabHelfTop});
  } 
}

function positionMouseOverIcon(mouseOverMenuItemId) {
  log.debug("positionMouseOverIcon: " + mouseOverMenuItemId);
  var position = $(mouseOverMenuItemId).position();
  log.debug("left: " + position);
  if(mouseOverMenuItemId == "mainMenuNavItem65") {
    $("#tabPescatoreOver").css({position: "absolute", left: posnTabVivaLeft, top: posnTabVivaTop});
  } else if(mouseOverMenuItemId == "mainMenuNavItem66") {
    $("#tabPescatoreOver").css({position: "absolute", left: posnTabRegimeLeft, top: posnTabRegimeTop});
  } else if(mouseOverMenuItemId == "mainMenuNavItem67") {
    $("#tabBlueHandOver").css({position: "absolute", left: posnTabBluHandLeft, top: posnTabBluHandTop});
  } else if(mouseOverMenuItemId == "mainMenuNavItem76") {
    $("#tabPescatoreOver").css({position: "absolute", left: posnTabBlogLeft, top: posnTabBlogTop});
  } else if(mouseOverMenuItemId == "mainMenuNavItem102") {
    $("#tabPescatoreOver").css({position: "absolute", left: posnTabMediaLeft, top: posnTabMediaTop});
  } else if(mouseOverMenuItemId == "mainMenuNavItem97") {
    $("#tabPescatoreOver").css({position: "absolute", left: posnTabAdventuresLeft, top: posnTabAdventuresTop});
  } else if(mouseOverMenuItemId == "mainMenuNavItem116") {
    $("#tabPescatoreOver").css({position: "absolute", left: posnTabHelfLeft, top: posnTabHelfTop});
  }
}

function setLoginPanelRowLeft() {
  log.debug('left before:' + $(".loginPanelRow").css("left"));
  // need to do this because changing to/from "display:block" in the generated codes "webLoginShowForm()" function resets the style coordinates
  $(".loginPanelRow").css({left: "0px"});
  log.debug('left after:' + $(".loginPanelRow").css("left"));
}

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
    });
    return vars;
}

function setEmailAddress () {

  var link = "Pescatore Fan Club";
  var tag1 = "mail";
  var tag2 = "to:";
  var email1 = "pescatore";
  var email2 = "vivapes";
  var email3 = "catore.com";
  var emailAddress = "<a h" + "ref=" + tag1 + tag2 + email1 + "@" + email2 + email3 + ">" + link + "</a>";
 
  if(document.getElementById("pescatoreEmail")) {
    log.debug(document.getElementById('pescatoreEmail') + "," + emailAddress);
    document.getElementById("pescatoreEmail").innerHTML  = emailAddress;
  } else {
    log.debug("no pescatoreEmail div to set");
  }
}
 




