﻿//SynPortal所用的Javascript代码

// ************** Jquery Functions **********************************

/* the next line is an example of how you can override default options globally (currently commented out) ... */

// $.fn.cluetip.defaults.tracking = true;
// $.fn.cluetip.defaults.width = 'auto';
$(document).ready(function() {

    //得到本js文件的路径
    var sSiteRoot = new String();

    if (document.getElementById("cluetipcss").href.indexOf("jquery.cluetip.css") > 0) {
        sSiteRoot = document.getElementById("cluetipcss").href.substring(0, document.getElementById("cluetipcss").href.indexOf("jquery.cluetip.css"));
    }

    //	$('input[type=checkbox],input[type=radio]').prettyCheckboxes();


    // jTip theme

    //示例：<a class="jtlc" href="#" rel="p.p1">?</a> 把<p class="p1">hint content</p>的内容显示为提示信息
    //
    //读取本地数据，自动隐藏，用于提示帮助信息
    $('a.jtlc').cluetip({
        local: true,
        hideLocal: true,
        cluetipClass: 'jtip',
        arrows: true,
        dropShadow: false,
        sticky: true,
        mouseOutClose: true,
        hoverIntent: false,
        activation: 'hover',
        width: '480px',
        closePosition: 'title',
        closeText: '<img src="' + sSiteRoot + 'images/cross.png" alt="close" />'
    });


    //读取本地数据，手动隐藏，用于提示帮助信息
    $('a.jtl').cluetip({
        local: true,
        hideLocal: true,
        cluetipClass: 'jtip',
        arrows: true,
        dropShadow: false,
        sticky: true,
        mouseOutClose: false,
        hoverIntent: false,
        activation: 'hover',
        width: '480px',
        closePosition: 'title',
        closeText: '<img src="' + sSiteRoot + 'images/cross.png" alt="close" />'
    });


    //显示短的信息
    //示例：<asp:Label ID="LeftPaneHint" runat="server" CssClass="jt" ToolTip="提示|左侧面板的CSS样式为LeftPane。如不需要此面板，可设定样式{width: 0px;}。"><abbr class="NormalRed">?</abbr></asp:Label>
    $('span.jt').cluetip({
        splitTitle: '|',
        arrows: true,
        mouseOutClose: true,
        dropShadow: false,
        cluetipClass: 'jtip'
    });

    $('a.jt').cluetip({
        splitTitle: '|',
        arrows: true,
        mouseOutClose: true,
        dropShadow: false,
        cluetipClass: 'jtip',
        width: '360px'
    });

    //读取外部文件：<a class="jtajax" href="ajax5.htm" rel="ajax5.htm">jTip Style clueTip</a>
    $('a.jtajax').cluetip({
        cluetipClass: 'jtip',
        arrows: true,
        dropShadow: false,
        sticky: true,
        mouseOutClose: true,
        ajaxCache: false,
        width: '360px',
        closePosition: 'title',
        closeText: '<img src="' + sSiteRoot + 'images/cross.png" alt="close" />'
    });


    $('span.jtajax').cluetip({
        cluetipClass: 'jtip',
        arrows: true,
        dropShadow: false,
        sticky: true,
        mouseOutClose: true,
        ajaxCache: false,
        width: '360px',
        closePosition: 'title',
        closeText: '<img src="' + sSiteRoot + 'images/cross.png" alt="close" />'
    });


    //Jquery Accordion
    $('ul.accordion').accordion();

    /*  Simple Image Viewer  */
    $("#gallery_output img").not(":first").hide();

    $("#gallery_nav a").click(function() {
        $('#gallery_nav a').removeClass('gallery_nav_active');
        if ($("#" + this.rel).is(":hidden")) {
            $("#gallery_output img").slideUp();
            $("#" + this.rel).slideDown();
            $(this).addClass('gallery_nav_active');
        }
    });


});

// ************** SynPortal Functions **********************************
//从URL中解析出来指定name的参数的值


function gup(url, name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(url);
    if (results == null) return "";
    else return results[1];
}

//得到屏幕的X,Y坐标，用于图像的点击放大

function getOffset(evt) {
    var target = evt.target;
    if (target.offsetLeft == undefined) {
        target = target.parentNode;
    }
    var pageCoord = getPageCoord(target);
    var eventCoord =
  {
      x: window.pageXOffset + evt.clientX,
      y: window.pageYOffset + evt.clientY
  };
    var offset =
  {
      offsetX: eventCoord.x - pageCoord.x,
      offsetY: eventCoord.y - pageCoord.y
  };
    return offset;
}

function getPageCoord(element) {
    var coord = { x: 0, y: 0 };
    while (element) {
        coord.x += element.offsetLeft;
        coord.y += element.offsetTop;
        element = element.offsetParent;
    }
    return coord;
}

function getX(evt) {
    var msg = "";
    if (evt.offsetX == undefined) {
        var evtOffsets = getOffset(evt);
        return evtOffsets.offsetX;
    }
    else {
        return evt.offsetX;

    }
}

function getY(evt) {
    var msg = "";
    if (evt.offsetX == undefined) {
        var evtOffsets = getOffset(evt);
        return evtOffsets.offsetY;
    }
    else {
        return evt.offsetY;
    }
}


//实现Hint的功能，用于“友情链接”和“推荐品牌”模块
/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX = 12 //Customize x offset of tooltip
var offsetfromcursorY = 10 //Customize y offset of tooltip

var offsetdivfrompointerX = 10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY = 14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

var rootdomain = "http://" + window.location.hostname + "/"

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<div id="dhtmlpopup" onmouseup="hidesynpopup()"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="' + rootdomain + 'images/arrowhint.gif">') //write out pointer image

var ie = document.all
var ns6 = document.getElementById && !document.all
var enabletip = false
var enablepopup = false


if (ie || ns6)
    var tipobj = document.all ? document.all["dhtmltooltip"] : document.getElementById ? document.getElementById("dhtmltooltip") : ""
var popupobj = document.all ? document.all["dhtmlpopup"] : document.getElementById ? document.getElementById("dhtmlpopup") : ""
var pointerobj = document.all ? document.all["dhtmlpointer"] : document.getElementById ? document.getElementById("dhtmlpointer") : ""

function ietruebody() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function syntip(thetext, thewidth, thecolor) {
    if (ns6 || ie) {
        if (typeof thewidth != "undefined") tipobj.style.width = thewidth + "px"
        if (typeof thecolor != "undefined" && thecolor != "") tipobj.style.backgroundColor = thecolor
        tipobj.innerHTML = thetext
        enabletip = true
        return false
    }
}

function synpopup(element, thetext, thecolor) {
    var coord = { x: 0, y: 0 };
    while (element) {
        coord.x += element.offsetLeft;
        coord.y += element.offsetTop;
        element = element.offsetParent;
    }
    //Find out how close the mouse is to the corner of the window
    var winwidth = ie && !window.opera ? ietruebody().clientWidth : window.innerWidth - 20

    if (ns6 || ie) {
        /* the popup is 250px by 250px*/
        if (coord.x - 50 > 0) {
            popupobj.style.left = (coord.x - 50) + "px"
        }
        else if (winwidth - coord.x + 50 < 200) {
            popupobj.style.left = (winwidth - 200) + "px"
        }
        else popupobj.style.left = "0px"
        popupobj.style.top = (coord.y - 80) + "px"
        popupobj.innerHTML = thetext
        popupobj.style.visibility = "visible"
        enablepopup = true;
        return false
    }
}

function positiontip(e) {
    if (enabletip) {
        var nondefaultpos = false
        var curX = (ns6) ? e.pageX : event.clientX + ietruebody().scrollLeft;
        var curY = (ns6) ? e.pageY : event.clientY + ietruebody().scrollTop;
        //Find out how close the mouse is to the corner of the window
        var winwidth = ie && !window.opera ? ietruebody().clientWidth : window.innerWidth - 20
        var winheight = ie && !window.opera ? ietruebody().clientHeight : window.innerHeight - 20

        var rightedge = ie && !window.opera ? winwidth - event.clientX - offsetfromcursorX : winwidth - e.clientX - offsetfromcursorX
        var bottomedge = ie && !window.opera ? winheight - event.clientY - offsetfromcursorY : winheight - e.clientY - offsetfromcursorY

        var leftedge = (offsetfromcursorX < 0) ? offsetfromcursorX * (-1) : -1000

        //if the horizontal distance isn't enough to accomodate the width of the context menu
        if (rightedge < tipobj.offsetWidth) {
            //move the horizontal position of the menu to the left by it's width
            tipobj.style.left = curX - tipobj.offsetWidth + "px"
            nondefaultpos = true
        }
        else if (curX < leftedge)
            tipobj.style.left = "5px"
        else {
            //position the horizontal position of the menu where the mouse is positioned
            tipobj.style.left = curX + offsetfromcursorX - offsetdivfrompointerX + "px"
            pointerobj.style.left = curX + offsetfromcursorX + "px"
        }

        //same concept with the vertical position
        if (bottomedge < tipobj.offsetHeight) {
            tipobj.style.top = curY - tipobj.offsetHeight - offsetfromcursorY + "px"
            nondefaultpos = true
        }
        else {
            tipobj.style.top = curY + offsetfromcursorY + offsetdivfrompointerY + "px"
            pointerobj.style.top = curY + offsetfromcursorY + "px"
        }
        tipobj.style.visibility = "visible"
        if (!nondefaultpos)
            pointerobj.style.visibility = "visible"
        else
            pointerobj.style.visibility = "hidden"
    }
    else if (enablepopup) {

    }
}

function hidesyntip() {
    if (ns6 || ie) {
        enabletip = false
        tipobj.style.visibility = "hidden"
        pointerobj.style.visibility = "hidden"
        tipobj.style.left = "-1000px"
        tipobj.style.backgroundColor = ''
        tipobj.style.width = ''
    }
}

function hidesynpopup() {
    if (ns6 || ie) {
        enablepopup = false
        popupobj.style.visibility = "hidden"
        popupobj.style.left = "-1000px"
        popupobj.style.backgroundColor = ''
        popupobj.style.width = ''

    }
}

document.onmousemove = positiontip






