﻿$(document).ready(function() {
    /******************************************************************
    * Making on state hovering over images
    ******************************************************************/

    $(".button").hover(
        function() {
            var imagePath = $(this).attr("src");
            $(this).attr("src", imagePath.replace("_up.jpg", "_ov.jpg"));
        },
	    function() {
	        var imagePath = $(this).attr("src");
	        $(this).attr("src", imagePath.replace("_ov.jpg", "_up.jpg"));
	    }
    );

    //    $("#tooltip_icon_suppression").hover(
    //        function() {
    //             if ($("#tooltip_icon_suppression").length == 0) {
    //            ToggleDisplay('tooltip1','tooltip_icon_suppression', 'inline');}
    //        },
    //	    function() {
    //	        if ($("#tooltip_icon_suppression").length == 0) {
    //	        ToggleDisplay('tooltip1','tooltip_icon_suppression', 'inline');}
    //	    }
    //    );

    $("#tooltip_icon_suppression").hover(
        function() {
            $("#tooltip").show();
        }
    );

    $("#tooltip1").hover(
        function() {
            $(this).show();
        },
	    function() {
	        $(this).hide();
	    }
    );

    $(".table_left").hover(
        function() {
            //$("#tooltip1").show();
            if (!$("#tooltip").is(":visible")) {
                //ToggleDisplay('tooltip1', 'tooltip_icon_suppression', 'inline');
                $("#tooltip1").show();
            }
        },
	    function() {
	        //$("#tooltip1").hide();
	        if (!$("#tooltip").is(":visible")) {
	            //ToggleDisplay('tooltip1', 'tooltip_icon_suppression', 'inline');
	            $("#tooltip1").hide();
	        }
	    }
    );

    $(".table_right").hover(
        function() {
            if (!$("#tooltip").is(":visible")) {
                //ToggleDisplay('tooltip1', 'tooltip_icon_suppression', 'inline');
                $("#tooltip1").show();
            }
            //$("#tooltip1").show();
        },
	    function() {
	        if (!$("#tooltip").is(":visible")) {
	            //ToggleDisplay('tooltip1', 'tooltip_icon_suppression', 'inline');
	            $("#tooltip1").hide();
	        }
	        //$("#tooltip1").hide();
	    }
    );

    $("#closeTooltip").click(
        function() {
            $("#tooltip1").hide();
        }
    );

    $(".persistence_container").hover(
        function() {
            if (!$("#tooltip").is(":visible")) {
                $("#tooltip1").show();
            }
        },
	    function() {
	        if (!$("#tooltip").is(":visible")) {
	            $("#tooltip1").hide();
	        }
	    }
    );

    $(".tooltipHover").hover(
        function() {
            $("#tooltip1").show();
        },
	    function() {
	        $("#tooltip1").hide();
	    }
    );

    $("#ctl00_cphMainContent_lnkPDF").hover(
        function() {
            ToggleDisplay('tooltipPdf', 'ctl00_cphMainContent_lnkPDF', 'block');
        },
        function() {
            ToggleDisplay('tooltipPdf', 'ctl00_cphMainContent_lnkPDF', 'block');
        }
    );

});
        


	function showYear() {
	    $('#ctl00_cphMainContent_year_drop_down1_ddlYear').show();
	}

	function hideYear() {
	    $('#ctl00_cphMainContent_year_drop_down1_ddlYear').hide();
	}


        function PrintPreview() {
            var disp_setting = "toolbar=yes,location=no,directories=yes,menubar=yes,";
            disp_setting += "scrollbars=yes,width=850, height=600, left=100, top=25";
            var mainContent = document.getElementById("maincontent").innerHTML;

            var docprint = window.open("", "", disp_setting);
            docprint.document.open();
            docprint.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
            docprint.document.write('<html xmlns="http://www.w3.org/1999/xhtml">');
            docprint.document.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />');
            docprint.document.write('<html><head><title>University of California: StatFinder</title>');
            docprint.document.write('<link href="../css/print2.css" rel="stylesheet" type="text/css" />');
            docprint.document.write('</head><body>');
            docprint.document.write('<div id="maincontent">');
            docprint.document.write(mainContent);
            docprint.document.write('</div></body></html>');
            docprint.document.close();
            docprint.focus();

            //docprint.document.write('</head><body onLoad="self.print()">');
        }

        function ViewTables(destination) {
            var size = 203;

            if (destination.indexOf("atpCode") >= 0 && destination.indexOf("atpCode=&") == -1) {

                size = 340;

                if (destination.indexOf("atpCode1") > 0 && destination.indexOf("atpCode1=&") == -1) {
                    
                    size = 480;

                    if (destination.indexOf("atpCode2") > 0 && destination.indexOf("atpCode2=&") == -1) {
                        
                        size = 630;

                        if (destination.indexOf("atpCode3") > 0) {

                            if(destination.length > destination.indexOf("atpCode3=") + 9)
                            {
                                size = 770;
                            }
                        }
                    }
                }
            }

            if (destination.indexOf("CompareGPA") > 0) {
                size = size + 160;
            }
            
            
            window.open(destination, "", "toolbar=no,menubar=no,scrollbars=yes,width=" + size + ",height=300,resizable=yes,left=100,top=25");

        }

        function FindPos(obj) {
            var curleft = curtop = 0;
            var lastLeft = lastTop = 0;
            if (obj != null && obj.offsetParent) {
                curleft = obj.offsetLeft;
                curtop = obj.offsetTop;
                while (obj = obj.offsetParent) {
                    if (obj.style.visibility != 'hidden' && obj.style.display != 'none') {
                        curleft += obj.offsetLeft;
                        curtop += obj.offsetTop;
                        if (obj.offsetLeft > 0) lastLeft = obj.offsetLeft;
                    }
                }
                //subtract last item to get rid of centering
                curleft -= lastLeft;
                
            }
            return [curleft, curtop];
        }

        function ToggleDisplay(displayElementId, relativeElementId, displayStyle) {
            //alert('Hi- ' + displayElementId + ' Style- ' + document.getElementById(displayElementId).style.display);
            if (document.getElementById(displayElementId).style.display == 'none') {
                // set display style
                if (displayStyle === undefined) {
                    displayStyle = 'block';
                }
                document.getElementById(displayElementId).style.display = displayStyle;
                //alert('Hi- ' + displayStyle);
                 
                //set location 
                if (relativeElementId === undefined) {
                    //do nothing with locating element
                }
                else {
                    document.getElementById(displayElementId).style.top = FindPos(document.getElementById(relativeElementId))[1] + 'px';
                    //FindPos(document.getElementById(relativeElementId))[0] + 'px';
                         //+ document.getElementById(relativeElementId).offsetHeight;
                    document.getElementById(displayElementId).style.left = FindPos(document.getElementById(relativeElementId))[0] + 'px'; 
                    //FindPos(document.getElementById(relativeElementId))[1] + 'px';
                         //+ document.getElementById(relativeElementId).offsetWidth;
                         //alert('Top- ' + FindPos(document.getElementById(relativeElementId))[0] + '\n' + 'Left- ' + FindPos(document.getElementById(relativeElementId))[1]);
                }

            }
            else {
                document.getElementById(displayElementId).style.display = 'none';
            }
        
        }

