﻿
/*加入我的最愛---------------begin*/
var myurl;
var mytitle;
myurl = 'http://www.merica.com.tw';
mytitle = "美加留學網";
function favority() {
    if (navigator.appName != "Netscape") {
        window.external.AddFavorite(myurl, mytitle);
    } else {
        window.location = myurl;
    }
}


/*TOP滑到頂端---------------begin*/
$(document).ready(function () {
    $('.goTop').click(function (e) {
        e.stopPropagation();
        $('html, body').animate({ scrollTop: 0 }, 300);
        return false;
    });
});
/*TOP滑到頂端---------------end*/



//光棒------------------------------------------begin
//首頁區塊
$(function () {
    //當滑鼠滑入時將div的class換成divOver
    $('.divbox').hover(function () {
        $(this).addClass('divOver');
    }, function () {
        //滑開時移除divOver樣式
        $(this).removeClass('divOver');
    }
		);
});
//光棒------------------------------------------end


//學校分享-首頁選單------------------------------------------begin
$(function () {
    // 預設標題區塊 .abgne_tip_gallery_block .caption 的 top
    var _titleHeight = 25;
    $('.abgne_tip_gallery_block').each(function () {
        // 先取得區塊的高及標題區塊等資料
        var $this = $(this),
				_height = $this.height(),
				$caption = $('.caption', $this),
				_captionHeight = $caption.outerHeight(true),
				_speed = 200;

        // 當滑鼠移動到區塊上時
        $this.hover(function () {
            // 讓 $caption 往上移動
            $caption.stop().animate({
                top: _height - _captionHeight
            }, _speed);
        }, function () {
            // 讓 $caption 移回原位
            $caption.stop().animate({
                top: _height - _titleHeight
            }, _speed);
        });
    });
});
//學校分享-首頁選單------------------------------------------begin

//主選單------------------------------------------begin
$(function () {
    // 幫 #menu li 加上 hover 事件
    $('#menu>li').hover(function () {
        // 先找到 li 中的子選單
        var _this = $(this),
			_subnav = _this.children('ul');

        // 變更目前母選項的背景顏色
        // 同時滑入子選單(如果有的話)
        _this.css('backgroundColor', '#666666');
        _subnav.stop(true, true).slideDown(300);
    }, function () {
        // 變更目前母選項的背景顏色
        // 同時滑出子選單(如果有的話)
        // 也可以把整句拆成上面的寫法
        $(this).css('backgroundColor', '').children('ul').stop(true, true).slideUp(300);
    });

    // 取消超連結的虛線框
    $('a').focus(function () {
        this.blur();
    });
});
//主選單------------------------------------------end



//底部選單------------------------------------------begin
$(document).ready(function () {

    //Adjust panel height

    $.fn.adjustPanel = function () {

        $(this).find("ul, .subpanel").css({ 'height': 'auto' }); //Reset subpanel and ul height


        var windowHeight = $(window).height(); //Get the height of the browser viewport

        var panelsub = $(this).find(".subpanel").height(); //Get the height of subpanel	

        var panelAdjust = windowHeight - 100; //Viewport height - 100px (Sets max height of subpanel)

        var ulAdjust = panelAdjust - 25; //Calculate ul size after adjusting sub-panel (27px is the height of the base panel)



        if (panelsub >= panelAdjust) {	 //If subpanel is taller than max height...

            $(this).find(".subpanel").css({ 'height': panelAdjust }); //Adjust subpanel to max height

            $(this).find("ul").css({ 'height': ulAdjust }); //Adjust subpanel ul to new size
        }

        else if (panelsub < panelAdjust) { //If subpanel is smaller than max height...

            $(this).find("ul").css({ 'height': 'auto' }); //Set subpanel ul to auto (default size)
        }
    };



    //Execute function on load

    $("#chatpanel").adjustPanel(); //Run the adjustPanel function on #chatpanel

    $("#alertpanel").adjustPanel(); //Run the adjustPanel function on #alertpanel



    //Each time the viewport is adjusted/resized, execute the function

    $(window).resize(function () {

        $("#chatpanel").adjustPanel();

        $("#alertpanel").adjustPanel();
    });



    //Click event on Chat Panel + Alert Panel	

    $("#chatpanel a:first, #alertpanel a:first").click(function () { //If clicked on the first link of #chatpanel and #alertpanel...

        if ($(this).next(".subpanel").is(':visible')) { //If subpanel is already active...

            $(this).next(".subpanel").hide(); //Hide active subpanel

            $("#footpanel li a").removeClass('active'); //Remove active class on the subpanel trigger
        }

        else { //if subpanel is not active...

            $(".subpanel").hide(); //Hide all subpanels

            $(this).next(".subpanel").toggle(); //Toggle the subpanel to make active

            $("#footpanel li a").removeClass('active'); //Remove active class on all subpanel trigger

            $(this).toggleClass('active'); //Toggle the active class on the subpanel trigger

        }

        return false; //Prevent browser jump to link anchor
    });



    //Click event outside of subpanel

    $(document).click(function () { //Click anywhere and...

        $(".subpanel").hide(); //hide subpanel

        $("#footpanel li a").removeClass('active'); //remove active class on subpanel trigger

    });

    $('.subpanel ul').click(function (e) {

        e.stopPropagation(); //Prevents the subpanel ul from closing on click
    });


    //Delete icons on Alert Panel

    $("#alertpanel li").hover(function () {

        $(this).find("a.delete").css({ 'visibility': 'visible' }); //Show delete icon on hover

    }, function () {

        $(this).find("a.delete").css({ 'visibility': 'hidden' }); //Hide delete icon on hover out

    });
});
//底部選單------------------------------------------end




//主選單------------------------------------------begin
$(function () {
    // 幫 #menu li 加上 hover 事件
    $('#menu>li').hover(function () {
        // 先找到 li 中的子選單
        var _this = $(this),
			_subnav = _this.children('ul');

        // 變更目前母選項的背景顏色
        // 同時滑入子選單(如果有的話)
        _this.css('backgroundColor', '#666666');
        _subnav.stop(true, true).slideDown(300);
    }, function () {
        // 變更目前母選項的背景顏色
        // 同時滑出子選單(如果有的話)
        // 也可以把整句拆成上面的寫法
        $(this).css('backgroundColor', '').children('ul').stop(true, true).slideUp(300);
    });

    // 取消超連結的虛線框
    $('a').focus(function () {
        this.blur();
    });
});
//主選單------------------------------------------end





//工具產生------------------------------------------begin
function CurrentOptions(value, text) {
    this.value = value;
    this.text = text;
}

catsArray = new Array();
var catsIndex = -1;
var itemsIndex;
var childItemsIndex;

function NewCategory() {
    catsIndex++;
    catsArray[catsIndex] = new Array();
    itemsIndex = -1;
}

function MenuBuild(value, text) {
    itemsIndex++;
    catsArray[catsIndex][itemsIndex] = new Array();
    catsArray[catsIndex][itemsIndex].value = value;
    catsArray[catsIndex][itemsIndex].text = text;
    subItemsIndex = 0;
}

function SubMenuBuild(value, text) {
    catsArray[catsIndex][itemsIndex][subItemsIndex] = new Array();
    catsArray[catsIndex][itemsIndex][subItemsIndex].value = value;
    catsArray[catsIndex][itemsIndex][subItemsIndex].text = text;
    subItemsIndex++;
}

function ChildMenuBuild(value, text) {
    catsArray[catsIndex][itemsIndex][subItemsIndex] = new CurrentOptions(value, text);
    ChildItemsIndex++;
}

function updateDepartments(formName, optSelected) {
    for (i = formName["select_b"].options.length - 1; i > 0; i--) {
        formName["select_b"].options[i] = null;
    }
    if (catsIndex >= optSelected) {
        for (i = 0; i < catsArray[optSelected].length; i++) {
            formName["select_b"].options[i] = new Option(catsArray[optSelected][i].text, catsArray[optSelected][i].value);
        }
    }
    //formName["select_b"].options[ i ] = new Option("所有次類別","");
    formName["select_b"].options[0].selected = true;
    updateUsers(formName, 0);
}

function updateUsers(formName, optSelected) {
    var i;
    optFromRelate = formName["select_a"].selectedIndex;
    if (optFromRelate < 0) {
        optFromRelate = 0;
    }
    for (i = formName["select_c"].options.length - 1; i > 0; i--) {
        formName["select_c"].options[i] = null;                // null out in reverse order (bug workarnd) 
    }
    if (catsIndex >= optFromRelate) {
        if (catsArray[optFromRelate].length > optSelected) {
            for (i = 0; i < catsArray[optFromRelate][optSelected].length; i++) {
                formName["select_c"].options[i] = new Option(catsArray[optFromRelate][optSelected][i].text, catsArray[optFromRelate][optSelected][i].value);
            }
        }
    }
    //formName["select_c"].options[ i ] = new Option("所有子類別","");
    formName["select_c"].options[0].selected = true;
} 


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
//工具產生------------------------------------------end







