/// <reference path="jquery.intellisense.js"/>

/*
Safenames scripts (utilizing jQuery 1.3.2)
Developed by Saforian
*/

/*
safenames custom code
*/

/*function toggleFade(id, option) {

    vis = $(id).css("customVis");

    if (vis == "visible" || option == 1) {
        $(id).fadeOut("normal");
        $(id).css("customVis", "hidden");
    } else {
        $(id).css("customVis", "visible");
        $(id).fadeIn("normal");
    }
}*/

/* ------- Initialize page ------- */
$(document).ready(function() {

    // Stripe table row colors
    $("table.data tr:nth-child(even)").not(".even").not(".odd").addClass("even");


    // Insert document icons
    $("a[href$=pdf]:not(:has(img))").append('<img class="icon" src="/images/icon_pdf.gif" width="14" height="14" alt=" (PDF)">');
    $("a[href$=doc]:not(:has(img)), a[href$=docx]:not(:has(img))").append('<img class="icon" src="/images/icon_word.gif" width="14" height="14" alt=" (Word Document)">');
    $("a[href$=xls]:not(:has(img)), a[href$=xlsx]:not(:has(img))").append('<img class="icon" src="/images/icon_excel.gif" width="14" height="14" alt=" (Excel Spreadsheet)">');
    $("a[href$=ppt]:not(:has(img)), a[href$=pptx]:not(:has(img))").append('<img class="icon" src="/images/icon_powerpoint.gif" width="14" height="14" alt=" (Powerpoint Presentation)">');


    // Column childs CSS3 fix
    $(".columns>.col:last-child").addClass("last-child");
    $(".columns>.col:first-child").addClass("first-child");
    $(".columns.three>.col:eq(1)").addClass("middle-child");


    // Main navigation fly out
    $("ul#navigation > li").hover(function() {
        $(this).children("ul:hidden").slideDown(150);
        $(this).addClass("hover"); // IE6 hover support
    }, function() {
        $(this).children("ul").slideUp(90);
        $(this).removeClass("hover");
    });


    // New sales rep contact popup -- doesn't appear if mouse quickly passes the div.
    $("#salescontact").hover(function() {
        var t = setTimeout(function() {
            $("#salescontact-popup").fadeIn("normal");
        }, 200);
        $(this).data('salesTimeout', t);
    }, function() {
        clearTimeout($(this).data('salesTimeout'));
        $("#salescontact-popup").fadeOut("normal");
    });


    // Homepage tab animation
    $("#hp_tab_container li a").hover(function() {
        $(this).animate({ "marginTop": "-38px" }, "fast");
    }, function() {
        $(this).animate({ "marginTop": "0" }, "fast");
    });


    // Clear search box
    $("input.cleardefault").focus(function() {
        if (this.value == this.defaultValue) {
            this.value = "";
            $("input.cleardefault").css("color", "black");
            $("input.cleardefault").css("font-style", "normal");
        }
    }).blur(function() {
        if (this.value == "") {
            this.value = this.defaultValue;
            $("input.cleardefault").css("color", "#dddddd");
            $("input.cleardefault").css("font-style", "italic");
        }
    });


    // IE6 only helper functions
    if (document.all && navigator.appName == "Microsoft Internet Explorer" && (navigator.userAgent.indexOf("MSIE 5.5") >= 0 || navigator.userAgent.indexOf("MSIE 6.") >= 0)) {

        // Homepage tabs hover support
        $("ul#hp_tab_container>li").hover(function() {
            $(this).addClass("hover");
        }, function() {
            $(this).removeClass("hover");
        });

        // PNG fix
        iepngfix();
    }

});



/* --- IE6 PNG fix --- */
function iepngfix() {

	// IE 5.5 and 6.0 PNG filter support (derived from youngpup.net)
	$("img[src$=png]").each(function(){
		var src = this.src;
		var div = document.createElement("div");

		// Set replacement div properties
		div.id = this.id;
		div.className = this.className;
		div.title = this.title || this.alt;
		div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizing='scale')";
		div.style.width = this.width + "px";
		div.style.height = this.height + "px";

		// Replace image with transparent div
		this.replaceNode(div);
	});
}
