
(function ($) {	 
$.fn.LinkBump = function() {
	$(this).addClass("bump_up")

	$(this).mouseup(function(){
	    $(this).toggleClass("bump_down");
	});
				
	$(this).mousedown(function(){
	    $(this).toggleClass("bump_down");
	});

	$(this).mouseout(function(){
	    $(this).removeClass("bump_down");
	});
};
})(jQuery);

(function ($) {	 
$.fn.ImageBump = function() {
	$(this).addClass("img_bump_up")

	$(this).mouseup(function(){
	    $(this).toggleClass("img_bump_down");
	});
				
	$(this).mousedown(function(){
	    $(this).toggleClass("img_bump_down");
	});

	$(this).mouseout(function(){
	    $(this).removeClass("img_bump_down");
	});
};
})(jQuery);

function changeNav(currentdiv)
{
	$('ul#main_nav li a.selected').removeClass('selected');
	$('ul#main_nav li.li_selected').removeClass('li_selected');
	$(currentdiv).removeClass('selected');
	$(currentdiv).parent().addClass('li_selected');
	$(currentdiv).parent().next().addClass('li_selected');
	$(currentdiv).addClass('selected');
}

function changeSubnav(currentdiv)
{
	$('ul#subnav li a.selected').removeClass('selected');
	$(currentdiv).addClass('selected');
}

function changeLeftnav(currentdiv)
{
	$('ul#article_leftnavigation li a.selected').removeClass('selected');
	$(currentdiv).addClass('selected');
}

function pop_howworksvideo() {
    leftPos = 0
    topPos = 0
    if (screen) {
    leftPos3 = (screen.width / 2) - 209
    topPos3 = (screen.height / 2) - 209
    }
    //window.open( 'pop-how-works-video.html', 'myWindow3', 'status=1,height=418,width=418,resizable=no,toolbar=no,location=no,scrollbars=no,left='+leftPos3+',top='+topPos3)
    window.open( '/pop-how-works-video.html', 'myWindow3', 'status=1,height=418,width=418,resizable=no,toolbar=no,location=no,scrollbars=yes,left='+leftPos3+',top='+topPos3)
}

function pop_stevedalevideo() {
    leftPos = 0
    topPos = 0
    if (screen) {
    leftPos3 = (screen.width / 2) - 209
    topPos3 = (screen.height / 2) - 209
    }
    //window.open( 'pop-how-works-video.html', 'myWindow3', 'status=1,height=418,width=418,resizable=no,toolbar=no,location=no,scrollbars=no,left='+leftPos3+',top='+topPos3)
    window.open( '/steve-dale-video.html', 'myWindow3', 'status=1,height=450,width=442,resizable=no,toolbar=no,location=no,scrollbars=yes,left='+leftPos3+',top='+topPos3)
}

function errorpop_empty(){
    $("#pop_error_empty").show();
}

function errorpop_exists(){
    $("#pop_error_exists").show();
}

$(document).ready(function(){	

    $('input[type=text]').bind('click focus', function() {
        if($(this).val() == "Email Address" || $(this).val() == "Enter your email address" )
        {
            $(this).val("");
        }
    });

	$("li#nav_login a").click(function() {
		$("#login_box").toggle();
		$(this).toggleClass("selected");
	});
	
	$(".recievealerts").click(function() {
		$("#recieve_box_signupform").toggle();
	});
	
	$(".inform a, .informbutton a, .closebutton a").click(function(){ 
	  $(".yellowinfo, .yellowinfoemail").hide();
      if($.browser.msie && $.browser.version=="6.0")
      {
	    $("select").css("visibility", "visible");
	  }
	  if($(this).attr("class"))
	  {
        $("#" + ($(this).attr("class"))).toggle(); 
        if($.browser.msie && $.browser.version=="6.0" && $(this).parent().attr("class") == "informbutton")
        {
          $("select").css("visibility", "hidden");
        }
      }
    }); 
	
	$(".blackerror_closelink").click(function(){ 
	  $("#pop_error_empty, #pop_error_exists").hide();
    }); 

	var pathinfo = window.location.pathname;
    pathinfo = pathinfo.toLowerCase();

    if((pathinfo.indexOf('index') !=-1) || (pathinfo.length == 1))
    {changeNav('#nav_home a');}
    else if(pathinfo.indexOf('services') !=-1 || 
            pathinfo.indexOf('lost-pet-database') !=-1 || 
            pathinfo.indexOf('lost-pet-hotline') !=-1 || 
            (pathinfo.indexOf('lost-pet-alert') !=-1 && pathinfo.indexOf('lost-pet-alert-signup') == -1) || 
            pathinfo.indexOf('pet-health-insurance') !=-1 || 
            pathinfo.indexOf('pet-emergency') !=-1 || 
            pathinfo.indexOf('pet-transport') !=-1)
    {changeNav('#nav_services a');}
    else if(pathinfo.indexOf('how-pet-microchipping-works') !=-1 || 
            pathinfo.indexOf('pet-recovery-process') !=-1 || 
            pathinfo.indexOf('microchipping-facts') !=-1 )
    {changeNav('#nav_microchip a');}
    else if(pathinfo.indexOf('petrescuers') !=-1 || 
            pathinfo.indexOf('microchipping-tell-a-friend') !=-1 || 
            pathinfo.indexOf('pet-parent-newsletter-signup') !=-1 || 
            pathinfo.indexOf('lost-dog-cat-resources') !=-1 || 
            pathinfo.indexOf('lost-pet-alert-signup') != -1 ||
            
            pathinfo.indexOf('find-a-lost-dog') !=-1 ||
            pathinfo.indexOf('how-to-find-a-lost-cat-using-personality-clues') !=-1 ||
            pathinfo.indexOf('outdoor-cats-getting-lost') !=-1 ||
            pathinfo.indexOf('top-five-ways-outdoor-cats-become-lost') !=-1 ||
            pathinfo.indexOf('lost-cat-experiment') !=-1 ||
            pathinfo.indexOf('stolen-pet-what-to-do') !=-1 ||
            pathinfo.indexOf('your-rights-when-losing-a-pet') !=-1 ||
            pathinfo.indexOf('found-pet-tips') !=-1 ||
            pathinfo.indexOf('tethering-dogs') !=-1 ||
            pathinfo.indexOf('find-a-lost-dog-using-personality-clues') !=-1 )
    {changeNav('#nav_petrescuers a');}
    else if(pathinfo.indexOf('found-pet-stories') !=-1)
    {changeNav('#nav_stories a');}
    else if(pathinfo.indexOf('faq') !=-1)
    {changeNav('#nav_faqs a');}
    
    if(pathinfo.indexOf('petrescuers') !=-1)
    {changeSubnav('#subnav_rescuers');}
    else if(pathinfo.indexOf('lost-pet-alert-signup') !=-1)
    {changeSubnav('#subnav_alerts');}
    else if(pathinfo.indexOf('pet-parent-newsletter-signup') !=-1)
    {changeSubnav('#subnav_signup');}
    else if(pathinfo.indexOf('lost-dog-cat-resources') !=-1 ||
    (pathinfo.indexOf('find-a-lost-dog') !=-1 && pathinfo.indexOf('find-a-lost-dog-using-personality-clues') ==-1)  ||
    pathinfo.indexOf('how-to-find-a-lost-cat-using-personality-clues') !=-1  ||
    pathinfo.indexOf('outdoor-cats-getting-lost') !=-1  ||
    pathinfo.indexOf('top-five-ways-outdoor-cats-become-lost') !=-1  ||
    pathinfo.indexOf('lost-cat-experiment') !=-1  ||
    pathinfo.indexOf('stolen-pet-what-to-do') !=-1  ||
    pathinfo.indexOf('your-rights-when-losing-a-pet') !=-1  ||
    pathinfo.indexOf('tethering-dogs') !=-1  ||
    pathinfo.indexOf('found-pet-tips') !=-1 ||
    pathinfo.indexOf('find-a-lost-dog-using-personality-clues') !=-1 )
    {changeSubnav('#subnav_training');}
    else if(pathinfo.indexOf('microchipping-tell-a-friend') !=-1)
    {changeSubnav('#subnav_tell');}

    if(pathinfo.indexOf('how-pet-microchipping-works') !=-1)
    {changeSubnav('#subnav_yourpet');}
    else if(pathinfo.indexOf('pet-recovery-process') !=-1)
    {changeSubnav('#subnav_process');}
    else if(pathinfo.indexOf('microchipping-facts') !=-1)
    {changeSubnav('#subnav_facts');}
    
    if(pathinfo.indexOf('found-pet-stories') !=-1)
    {changeSubnav('#subnav_found');}
    else if(pathinfo.indexOf('share-your-story') !=-1)
    {changeSubnav('#subnav_share');}
    else if(pathinfo.indexOf('share-your-video') !=-1)
    {changeSubnav('#subnav_video');}
    
    if(pathinfo.indexOf('find-a-lost-dog-using-personality-clues') !=-1)
    {changeLeftnav('#personalitycluesdog');}
    else if(pathinfo.indexOf('tethering-dogs') !=-1)
    {changeLeftnav('#tetheringyourdog');}
    else if(pathinfo.indexOf('find-a-lost-dog') !=-1)
    {changeLeftnav('#findinglostdog');}
    
    if(pathinfo.indexOf('lost-cat-experiment') !=-1)
    {changeLeftnav('#catgonewild');}
    else if(pathinfo.indexOf('top-five-ways-outdoor-cats-become-lost') !=-1)
    {changeLeftnav('#outdoorcatsgetlost');}
    else if(pathinfo.indexOf('outdoor-cats-getting-lost') !=-1)
    {changeLeftnav('#outdoorcatsaccess');}
    else if(pathinfo.indexOf('how-to-find-a-lost-cat-using-personality-clues') !=-1)
    {changeLeftnav('#personalitycluescat');}
    
    if(pathinfo.indexOf('stolen-pet-what-to-do') !=-1)
    {changeLeftnav('#petwasstolen');}
    else if(pathinfo.indexOf('your-rights-when-losing-a-pet') !=-1)
    {changeLeftnav('#lostpetrights');}
    else if(pathinfo.indexOf('found-pet-tips') !=-1)
    {changeLeftnav('#findapet');}
    
    $(".bumpbutton").LinkBump();
    $(".bumpimage").ImageBump();
    $(".blueButton").LinkBump();
    $(".blueButton200").LinkBump();
    
    $("#emergency_link").click(function(){
        $("#popups_veil").show();
        $("#popups_medemergency").show();
        
        if($.browser.msie && $.browser.version=="6.0")
        {
            $("#popups_veil").height($(document).height());
            $("#popups_veil").width($(document).width());
            $("select").css("visibility", "hidden");
        }
    });
    
    $("#report_link").click(function(){
        $("#popups_veil").show();
        $("#popups_reportfound").show(); 
        
        if($.browser.msie && $.browser.version=="6.0")
        {
            $("#popups_veil").height($(document).height());
            $("#popups_veil").width($(document).width());
            $("select").css("visibility", "hidden");
        }
    });
    
    $(".toppopupclosebutton").click(function(){
        $("#popups_veil").hide();
        $("#popups_reportfound").hide();
        $("#popups_medemergency").hide();  
        if($.browser.msie && $.browser.version=="6.0")
        {
            $("select").css("visibility", "visible");
        }
    });
    
    $("#EmailNewsletterSignupButton").click(function(event)
    {
        //validate form
        var emailBox = document.getElementById("EmailAddressField");
        if ($("#EmailAddressField").val() == "")
        {
            errorpop_empty();
            event.preventDefault();
        }
        else if ($("#EmailAddressField").val() == "Email Address" || $("#EmailAddressField").val() == "Enter your email address")
        {
            errorpop_empty();
            event.preventDefault();
        }
        else if (emailBox.value.search(/^[a-zA-Z]+([_\.-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+([\.-]?[a-zA-Z0-9]+)*(\.[a-zA-Z]{2,4})+$/) == -1)
        {
            errorpop_empty();
            event.preventDefault();
        }
        else
        {
            $("#EmailNewsletterSignupButton").attr("disabled", "disabled");
            $("#EmailNewsletterSignupButton").css("opacity", "0.4");
            $("#EmailNewsletterSignupButton").css("filter", "alpha(opacity = 40)");
            $("#form1").submit();
        }
    });
    
});
