﻿var curNavSection = "";
var curSubNavSection = "";
var cConcept = "";

$(document).ready(function() {
$("#list table tr:even").addClass("even");
	
});

var stopHomePageAnimation = true;
var homePageAnimationHandle = "";
var curAnimationFrame = 5;
var animating = false;

function cycleHomePageAnimation() {

    curAnimationFrame++;
    if (curAnimationFrame == 7) {
        curAnimationFrame = 1;
    }
    homePageAnimationHandle = setTimeout(function() {

        stopHomePageAnimation = false;


        clickHomeNav(curAnimationFrame);

    }, 5000);
}

function clickHomeNav(srcNum) {
    $("#prod1").removeClass('cat1on');
    $("#prod2").removeClass('cat2on');
    $("#prod3").removeClass('cat3on');
    $("#prod4").removeClass('cat4on');
    $("#prod" + srcNum).addClass('cat' + srcNum + 'on');
    $("#prodArea1").hide();
    $("#prodArea2").hide();
    $("#prodArea3").hide();
    $("#prodArea4").hide();
    $("#prodArea5").hide();
    $("#prodArea6").hide();
    $("#prodArea" + srcNum).fadeIn("fast");
    if (stopHomePageAnimation) {
        clearTimeout(homePageAnimationHandle);
    }
    else {
        cycleHomePageAnimation();
    }
    stopHomePageAnimation = true;
}


$(document).ready(function() {


    //Initialization code in here.
    cycleHomePageAnimation();

    $(".imgH").mouseover(function() {
        $(this).stop();
        $(this).animate({ opacity: 0.7 }, "slow");
    });

    $(".imgH").mouseout(function() {
        $(this).stop();
        $(this).animate({ opacity: 1 }, "slow");
    });

    $(".ui-fade-rollover").each(function() {
        if ($(this).attr("effect_loaded") == "true") return;
        $(this).attr("effect_loaded", "true");
        if ($(this).attr("alt") != null && curNavSection != "" && $(this).attr("alt") == curNavSection) {
            $(this).attr("src", $(this).attr("src").replace("_off", "_over"));
        }

        if ($(this).attr("alt") != null && curSubNavSection != "" && $(this).attr("alt").indexOf(curSubNavSection) != -1) {
            $(this).attr("src", $(this).attr("src").replace("_off", "_on"));
        }

        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);
        });


        //Rough Product Area Clicker
        $("#prod1").click(function() {
            clickHomeNav(1);
            //$("#prodArea1").show();
        });

        $("#prod2").click(function() {
            clickHomeNav(2);
        });

        $("#prod3").click(function() {
            clickHomeNav(3);
        });

        $("#prod4").click(function() {
            clickHomeNav(4);
        });


        //Image Hover Disinfectants	
        $(".paHover1").hover(
      function() {
          $(this).stop();
          $(this).animate({ width: "139px", height: "172px" }, "fast");
      },
      function() {
          $(this).stop();
          $(this).animate({ width: "132px", height: "163px" }, "fast");
      }
   	);

      $(".paHover1b").hover(
      function() {
          $(this).stop();
          $(this).animate({ width: "91px", height: "172px" }, "fast");
      },
      function() {
          $(this).stop();
          $(this).animate({ width: "86px", height: "163px" }, "fast");
      }
   	);



        //Image Hover Floor	
        $(".paHover2").hover(
      function() {
          $(this).stop();
          $(this).animate({ width: "140px", height: "214px" }, "fast");
      },
      function() {
          $(this).stop();
          $(this).animate({ width: "130px", height: "199px" }, "fast");
      }
   	);



        //Image Hover multi-purpose		
        $(".paHover3").hover(
      function() {
          $(this).stop();
          $(this).animate({ width: "200px", height: "240px" }, "fast");
      },
      function() {
          $(this).stop();
          $(this).animate({ width: "190px", height: "228px" }, "fast");
      }
   	);



        //Image Hover Degreaser Left	
        $(".paHover4").hover(
      function() {
          $(this).stop();
          $(this).animate({ width: "158px", height: "252px" }, "fast");
      },
      function() {
          $(this).stop();
          $(this).animate({ width: "148px", height: "236px" }, "fast");
      }
   	);



        //Image Hover Degreaser Right		
        $(".paHover4b").hover(
      function() {
          $(this).stop();
          $(this).animate({ width: "230px", height: "252px" }, "fast");
      },
      function() {
          $(this).stop();
          $(this).animate({ width: "220px", height: "241px" }, "fast");
      }
   	);



        //Disinfectants Hover



    });

    loadScroller();
    loadProductFeaturesSelector();
    loadPopinHandlers();
});


function loadPopinHandlers() {
    $(".popin").click(function() {
        var parms = getPopinParameters($(this));
        if (parms.length == 3) {
            showPopin($(this).attr("href"), parms[0], parms[1], parms[2]);
        }
        return false;
    });
}

function showAllPathogens(obj) {
    $(".hidden_pathogen").show();
    $(".show_pathogens_button").hide();
}

function getPopinParameters(obj) {

    var classList = $(obj).attr("class").split(" ");
    for (var i = 0; i < classList.length; i++) {
        if (classList[i].indexOf("popin_dim_") == 0) {
            var val = classList[i].replace("popin_dim_", "");
            return (val.split("x"));
        }
    }
    return ("0x0x0").split("x");
}

function loadProductFeaturesSelector() {
    $(".prd_features_tab").click(function() {
        $(".prd_features_tab").each(function() {
            $(this).attr("src", $(this).attr("src").replace("_over", "_off"));
            $("#" + $(this).attr("rel")).hide();

        });
        $(this).attr("src", $(this).attr("src").replace("_off", "_over"));
        $("#" + $(this).attr("rel")).show();
        return false;
    });


    $(".ask_prd_features_tab").click(function() {

        $(this).parents(".info_tabs").find(".ask_prd_features_tab").each(function() {
            $(this).attr("src", $(this).attr("src").replace("_over", "_off"));
            $(this).parents(".info_tabs").find("." + $(this).attr("rel")).hide();
        });
        $(this).attr("src", $(this).attr("src").replace("_off", "_over"));
        $(this).parents(".info_tabs").find("." + $(this).attr("rel")).show();

    });
    
}

function loadScroller() {
    $("#productBar li").hover(
		function() {
		    $(this).find("span").attr({
		        "style": 'display:inline'
		    });
		    $(this).find("span").animate({ opacity: 1, top: "110" }, { queue: false, duration: 400 });
		},
		function() {
		    $(this).find("span").animate({ opacity: 0, top: "100" }, { queue: false, duration: 400 }, "linear",
				function() {
				    $(this).find("span").attr({ "style": 'display:none' });
				}
			);
		});
}



//FancyPlayer
function preview(swfFile, dur) {
    $.fancybox('<p>Loading video...</p>', {
        'autoDimensions': false,
        'width': 640,
        'height': 360,
        'transitionIn': 'none',
        'transitionOut': 'none',

        'onComplete': function() {
        player = $f("fancybox-inner", { src: "/video/flowplayer-3.2.2.swf", wmode: 'opaque' }, {

                play: { opacity: 0 },

                clip: {
                    autoPlay: true,
                    url: '/video/' + swfFile,
                    onStart: function(clip) {
                        var wrap = jQuery(this.getParent());
                        var clipwidth = clip.metaData.width;
                        var clipheight = clip.metaData.height;
                        var pos = $.fn.fancybox.getViewport();
                        $("#fancy_outer").css({ width: clipwidth + 20, height: clipheight + 20 });
                        $("#fancy_outer").css('left', ((clipwidth + 36) > pos[0] ? pos[2] : pos[2] + Math.round((pos[0] - clipwidth - 36) / 2)));
                        $("#fancy_outer").css('top', ((clipheight + 50) > pos[1] ? pos[3] : pos[3] + Math.round((pos[1] - clipheight - 50) / 2)));
                        $("#fancy_right, #fancy_left").css({ height: clipheight - 60, bottom: '70px' });

                    },
                    onFinish: function() {
                        $('#fancybox-close').trigger('click');
                    }
                }
            });


            player.load();


        }
    });
}



