﻿/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

$(window).load(function (evt) {
    /**********************************************/
    $("#langSelected,#langSelected+div").click(function () {
        if ($("#langSelected+div").hasClass("show")) {
            $("#langOption").show();
            $("#langSelected+div").attr("class", "hide");
            $("#langSelect").addClass("hover");
        }
        else {
            $("#langOption").hide();
            $("#langSelected+div").attr("class", "show");
            $("#langSelect").removeClass("hover");
        }
    });
    $("#langOption .cCon .CM a").hover(function () {
        $(this).toggleClass("hover");
    }, function () {
        $(this).toggleClass("hover");
    });


    $("#weather").hover(function () {
        $("#weatherNext").show();
    }, function () {
        $("#weatherNext").hide();
    });
    $("#time").hover(function () {
        $("#timecont").show();
    }, function () {
        $("#timecont").hide();
    });


    //天气
    if (UseWeatherModule.toLocaleLowerCase() == "true")
        getWeather();
    gettime();
    if (QuickReservation.toLocaleLowerCase() == "true") {
        $("#quickReserveShowBtn").click(function () {
            if ($(this).hasClass("show")) {
                $(this).attr("class", "hide");
                //$(this).addClass("openhover");
                $("#Reservation+div.options").hide();
            }
            else {
                $(this).attr("class", "show");
                $("#Reservation+div.options").show();
                $(this).addClass("openhover");
            }
        });
        formatReservBtn();
    }
    /**********************************************/

    $("ul.slideimgs").each(function () { slideshowInit(this); });

    $("div#SNSLinks li#twitter>a").unbind("click").click(function () {
        return false;
    });

    // We should always store the landing page
    var landing = $.cookie("landing", { 'path': '/' });
    if (!landing) {
        if (document.referrer.indexOf(window.location.hostname) != -1)
            $.cookie("landing", document.referrer, { 'path': '/' })
        else
            $.cookie("landing", window.location.href, { 'path': '/' })
    }
    // Prefill the promocode input if the user has a promocode
    var promo = $.cookie("promocode");
    if (promo) $("#quickForm input[name='PromotionalCode']").val(promo);
});


//获取天气代码
function getWeather() {
    if (window.weather_city == "" && typeof (window.weatherLocation) == "undefined")
        return;

    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://www.google.com/jsapi?callback=getWOEId";
    document.body.appendChild(script);
}

var woeId = null;
function getWOEId() {
    var weatherLocation = '';
    if (typeof (window.weatherLocation) != "undefined") {
        weatherLocation = window.weatherLocation;
    }
    var weather = $("#weatherNext .cCon .CM");
    $.ajax({
        type: "get",
        url: "/Controls/getYahooWeather.ashx",
        dataType: "json",
        data: {
            action: 'GetWOEId',
            city: weather_city,
            location: weatherLocation
        },
        async: true,
        beforeSend: function() {
            weather.attr("style", "height:93px;line-height:93px;text-align:center;").html(note_loading);
        },
        success: function(data, textStatus) {
            var returnData = data;
            if (returnData.Msg == "OK") {
                woeId = returnData.ReturnVal;
                window.google.load("feeds", "1", { "callback": getWeatherXml });
            } else {
                $("#weatherNext .cCon .CM").html(window.invalidWeather);
            };
        }
    });
}

function getWeatherXml() {
    if (woeId != null) {
        var weatherUrl = "http://weather.yahooapis.com/forecastrss?w=" + woeId + "&u=" + weather_u;
        var feed = new google.feeds.Feed(weatherUrl);
        feed.load(ParseShortWeatherResponse);
    }
}

function ParseShortWeatherResponse(result) {
    if (!result.error) {
        var urlPrefix = "*http://weather.yahoo.com/forecast/";
        var starIndex = result.feed.link.indexOf(urlPrefix);
        if (starIndex == -1) {
            $("#weatherNext .cCon .CM").html(window.invalidWeather);
        } else {
            var zipCode = result.feed.link.substring(starIndex + urlPrefix.length).replace(".html", ".xml");
            var weatherXmlUrl = "http://xml.weather.yahoo.com/forecastrss/" + zipCode;
            var feed = new google.feeds.Feed(weatherXmlUrl);
            feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
            feed.load(ParseLongWeatherResponse);
        }
    } else {
        $("#weatherNext .cCon .CM").html(result.error);
    }
}

function ParseLongWeatherResponse(result) {
    if (!result.error) {
        setWeather(result.xmlDocument, weather_u, weather_city);
    }
    else {
        $("#weatherNext .cCon .CM").html(result.error);
    }
}

function setWeather(xmlDocument, u, city) {
    if (u == "f")
        u = "°F";
    else
        u = "°C";
    var weatherPannel = $("#weatherNext .cCon .CM");
    weatherPannel.html('');
    weatherPannel.removeAttr('style');
    var current_condition = google.feeds.getElementsByTagNameNS(xmlDocument, 'http://xml.weather.yahoo.com/ns/rss/1.0', 'condition')[0];
    var current_temp = current_condition.getAttribute("temp") + u;
    var forecast = google.feeds.getElementsByTagNameNS(xmlDocument, 'http://xml.weather.yahoo.com/ns/rss/1.0', 'forecast');
    var forecast_today = forecast[0];
    var today_h_l = temperature_High + ': ' + forecast_today.getAttribute("high") + u + '<br />' + temperature_Low + ': ' + forecast_today.getAttribute("low") + u;
    var current_code = current_condition.getAttribute("code");
    var astronomy = google.feeds.getElementsByTagNameNS(xmlDocument, 'http://xml.weather.yahoo.com/ns/rss/1.0', 'astronomy')[0];
    var current_time_str = current_condition.getAttribute("date");
    var current_time = new Date(current_time_str);
    var today_sunrise = Date.parse(current_time.toDateString() + ' ' + astronomy.getAttribute("sunrise"));
    var today_sunset = Date.parse(current_time.toDateString() + ' ' + astronomy.getAttribute("sunset"));
    var current_day_night = (current_time.getTime() > today_sunrise && current_time.getTime() < today_sunset) ? "d" : "n";
    if (current_code == '3200') {
        current_code = '44';
    }
    var todayImg = 'http://l.yimg.com/a/i/us/nws/weather/gr/' + current_code + current_day_night + '.png';
    $("#weatherNow span").text(current_temp);
    var todayObj = $("<div id='todayMark'><img src='" + todayImg + "'></div><div id='todayTemp'><span></span><p><br></p><strong></strong> </div>");
    todayObj.find("span").html(current_temp);
    todayObj.find("p").html(today_h_l);
    todayObj.find("strong").html(city);
    weatherPannel.append(todayObj);

    // Get 5 day forecast
    var now = new Date();
    var days = Date.dayNames;
    var nextdays = $("<div id='Nextdays'><b></b><b></b><b></b><b></b></div>");
    var b = nextdays.find("b");
    for (var i = 1; i < forecast.length; i++) {
        var forecast_code = forecast[i].getAttribute("code");
        var forecast_style = 'background-position: -' + parseInt(forecast_code, 10) * 61 + 'px -0px; width: 61px; height: 34px';
        b.eq(i - 1).attr("style", forecast_style);
        b.eq(i - 1).text(days[(now.getDay() + i) % 7]);
    }
    weatherPannel.append(nextdays);

}

//设置时间
function gettime() {
    var lanID = 1;
    $.ajax({
        type: "post",
        url: "/ajax/TimeZoneHelper.ashx",
        dataType: "json",
        data: { ran: Math.random(), LanguageID: lanID },
        async: true,
        beforeSend: function() {
        },
        success: function(data, textStatus) {
            var returnData = data;
            if (returnData.Msg == "OK") {
                var times = new Array();
                times = eval(returnData.times);
                var UseTimeZone = returnData.UseTimeZone;                                
                if (UseTimeZone) {
                    $("#time").show();
                    $("#time").attr("basetime", times[3] + ":" + times[2] + ":" + times[1]);
                    $("#time2").attr("basetime", times[3] + ":" + times[2] + ":" + times[1]);
                    $("#time,#time2").BaseClock();
                    new Clock1('localtime', 65).init(times);                    
                }
                else {
                    $("#time").hide();
                }
                if (UseWeatherModule.toLocaleLowerCase() == "false" && !UseTimeZone) {
                    $("#time").siblings("div.line").hide();
                }
            }
            else {
                $("#time").hide();
                if (UseWeatherModule.toLocaleLowerCase() == "false") {
                    $("#time").siblings("div.line").hide();
                }
            }

        }
    });
}


function formatReservBtn() {
    $('#reserBtn').click(function() {
        var parm = "";
        var tUrl = "/" + $(this).attr("hl") + "/reservations";
        var d1 = $("#date1").val();
        var d2 = $("#date2").val();
        parm += "segmentid=" + $(this).attr("segmentid");
        parm += "&check_in=" + d1;
        parm += "&check_out=" + d2;
        parm += "&numberofnights=" + getDays(d1, d2, "-");
        parm += "&numberofrooms=" + $("#quickForm select[name='numberofrooms']").find('option:selected').val();
        parm += "&promotioncode=" + $("#quickForm input[name='PromotionalCode']").val();
        if (undefined != $("input[name='promotioncode']").val() && "undefined" != $("input[name='promotioncode']").val())
            parm += "&promotioncode=" + $("input[name='promotioncode']").val();
        parm = parm.replace(/=undefined/g, "=");
        tUrl += "?" + parm;
        $(this).attr("href", tUrl);
        $("#quickReserveShowBtn").click();
    });
}
function getDays(first, second, sign) {
    fArray = first.split(sign);
    sArray = second.split(sign);
    var fDate = new Date(fArray[0], fArray[1], fArray[2]);
    var sDate = new Date(sArray[0], sArray[1], sArray[2]);

    var t = Math.abs(fDate.getTime() - sDate.getTime());
    var days = t / (1000 * 60 * 60 * 24);
    if (isNaN(days))
        days = 0;
    return days;
}

function PannelScroll(Scrollobj, Offset, minH) {
    var headerH = $("#header").height();
    var footerH = $("#footer").height();
    if ($.browser.msie && $.browser.version == "7.0")
        Offset = Offset + 21;
    var windowH = $(window).height();
    var PH = windowH - Offset - headerH - footerH;
    if (PH < minH)
        PH = minH;
    $(Scrollobj).height(PH);
    $(Scrollobj).jScrollPane({ showArrows: true, hideFocus: true });
    $(window).resize(function() {
        windowH = $(window).height();
        PH = windowH - Offset - headerH - footerH;
        if (PH < minH)
            PH = minH;
        $(Scrollobj).height(PH);
        //try {
        $(Scrollobj).data('jsp').reinitialise();
        //} catch (e) { }
        //$(Scrollobj).jScrollPane();
    });

}

//Istimer = window.setInterval(PackageTimer, 500);

//for slideshow
function slideshowInit(obj) {
    var liImgs = $("li", $(obj));
    liImgs.each(function() {// new reg img.replace(/(\.[0-9]+x[0-9]+|)\.([a-zA-Z]*?(\?[^\$]*?|))$/gi, ".160x80.$2")
        $(this).find("img").attr("org", $(this).find("img").attr("src").replace(/\.[0-9]+x[0-9]+\.([a-zA-Z]*?(\?[^\$]*?|))$/ig, "").replace(/\.[0-9]+x[0-9]+\.[a-zA-Z]*?\?/ig, "?"));
    });
    if (liImgs.length > 0) {
        try { $(obj).siblings("span.preImg1,span.nextImg1").remove(); } catch (e) { }
        var currImgSrc = "";
        try {
            if (liImgs.find("img:visible").length > 0)
                currImgSrc = liImgs.find("img:visible").attr("src");
            else
                currImgSrc = liImgs.find("img:eq(0)").attr("src");
        }
        catch (e) { }
        $(obj).parent().append("<span class='bigImg btnPage' step='0' org='" + currImgSrc.replace(/\.[0-9]+x[0-9]+\.([a-zA-Z]*?(\?[^\$]*?|))$/ig, "").replace(/\.[0-9]+x[0-9]+\.[a-zA-Z]*?\?/ig, "?") + "'></span><span class='preImg1 btnPage' step='-1'></span><span class='nextImg1 btnPage' step='1'></span>");
        $(obj).parent().append("<div class='ad-navigator-wrapper' org='" + currImgSrc.replace(/\.[0-9]+x[0-9]+\.([a-zA-Z]*?(\?[^\$]*?|))$/ig, "").replace(/\.[0-9]+x[0-9]+\.[a-zA-Z]*?\?/ig, "?") + "'></div>");
        var pnimgs = $(obj).siblings("span.preImg1,span.nextImg1");
        $(obj).parent().die();
        $(obj).parent().unbind();      
        $(obj).parent().hover(function() { pnSHide($(obj));}, function() { pnimgs.hide(); $(obj).siblings("span.bigImg").hide(); });
        pnimgs.css("cursor", "hand").click(function() {
            var currIndex = liImgs.index($(obj).find("li:visible"));
            currIndex += parseInt($(this).attr("step"));
            if (currIndex < 0) currIndex = 0;
            if (currIndex > (liImgs.length - 1)) currIndex = liImgs.length - 1;
            liImgs.eq(currIndex).fadeIn().siblings("li").hide();
            $(obj).siblings("span.bigImg").attr("org", liImgs.eq(currIndex).find("img").attr("org"));
            pnSHide(obj);
        });

    } else
        $(obj).siblings("span.bigImg,span.preImg1,span.nextImg1").remove();
    $(obj).siblings("span.bigImg").mouseover(function() { fullSlideShow($(this)); });
}
//check next prev icon
function pnSHide(obj) {
    var liImgs = $("li", $(obj));
    var currobj = $("li:visible", $(obj));
    var currIndex = 0;
    try {
        currIndex = liImgs.index(currobj);
    } catch (e) { currIndex = 0; }
    if (currIndex <= 0)
        $(obj).siblings("span.preImg1").hide();
    else
        $(obj).siblings("span.preImg1").show();
    if (currIndex >= (liImgs.length - 1))
        $(obj).siblings("span.nextImg1").hide();
    else
        $(obj).siblings("span.nextImg1").show();
    $(obj).siblings("span.bigImg").show();
}

function fullSlideShow(obj) {
    $.fn.fancybox.Items = [];
    var bigImg = $(obj);
    bigImg.siblings("ul.slideimgs").find("li").each(function() {
        $(this).find("img").fancybox({ 'frameWidth': 700, 'frameHeight': 585 }, true);
        $(this).find("img").unbind("click");
    });
    bigImg.add(bigImg.siblings(".ad-navigator-wrapper:eq(0)")).fancybox({ 'frameWidth': 700, 'frameHeight': 585 }, true);


}


//翻页
function PromotionsPaging(pagesize) {
    var count = $(".movableList ul:visible li:visible").length;
    var pcount = Math.floor(count / pagesize);
    if (count % pagesize > 0 && count > pagesize)
        pcount++;
    if (pcount == 0)
        pcount = 1;
    $(".listsbox .freeControl").empty();
    for (var i = 0; i < pcount; i++) {
        $(".listsbox .freeControl").append("<a href='#" + i + "'></a>");
    }
    var fcA = $(".listsbox .freeControl a");
    var obj = $(".listsbox .movableList");
    fcA.click(function() {
        var curIndex = fcA.index($(this)[0]);
        var left = curIndex * $(".movableList").width();
        fcA.removeClass("curr");
        $(this).addClass("curr");
        obj.animate({ "scrollLeft": left }, 250, function() {
            if (curIndex == 0) { $(".listsbox .preNextControl a.prePage").addClass("disabled"); } else { $(".listsbox .preNextControl a.prePage").removeClass("disabled"); }
            if (curIndex + 1 >= pcount) { $(".listsbox .preNextControl a.nextPage").addClass("disabled"); } else { $(".listsbox .preNextControl a.nextPage").removeClass("disabled"); }
            if (curIndex > 0 && curIndex + 1 < pcount) { $(".listsbox .preNextControl a.prePage,.listsbox .preNextControl a.nextPage").removeClass("disabled"); }
        });
        return false;
    });
    
    $(".listsbox .preNextControl a.prePage,.listsbox .preNextControl a.nextPage").click(function() {
        if ($(this).hasClass("disabled")) { return false; }
        var curIndex = fcA.index($(".listsbox .freeControl a[class='curr']"));
        if ($(this).hasClass("prePage")) {
            fcA.eq(curIndex - 1).click();
        }
        else {
            fcA.eq(curIndex + 1).click();
        }
        return false;
    });

    var allList = $(".movableList ul:visible li a");
    var curObj = $(".movableList ul:visible li a.procurr");
    var aIndex = allList.index(curObj[0]) + 1;
    apcount = Math.floor(aIndex / pagesize);
    if (aIndex > pagesize && aIndex % pagesize > 0)
        apcount++;
    apcount = apcount - 1 < 0 ? 0 : apcount - 1;
    fcA.removeClass("curr");
    fcA.eq(apcount).addClass("curr");

    var left1 = apcount * $(".movableList").width();
    obj.scrollLeft(left1);
    if (apcount == 0) { $(".listsbox .preNextControl a.prePage").addClass("disabled"); } else { $(".listsbox .preNextControl a.prePage").removeClass("disabled"); }
    if (apcount + 1 >= pcount) { $(".listsbox .preNextControl a.nextPage").addClass("disabled"); } else { $(".listsbox .preNextControl a.nextPage").removeClass("disabled"); }
    if (apcount > 0 && apcount + 1 < pcount) { $(".listsbox .preNextControl a.prePage,.listsbox .preNextControl a.nextPage").removeClass("disabled"); }
}


function mapPaging(pagesize) {
    var count = $(".movableList ul:visible li:visible").length;
    var pcount = Math.floor(count / pagesize);
    if (count % pagesize > 0 && count > pagesize)
        pcount++;
    if (pcount == 0)
        pcount = 1;
    $(".listsbox .freeControl").empty();
    for (var i = 0; i < pcount; i++) {
        $(".listsbox .freeControl").append("<a href='#" + i + "'></a>");
    }
    var fcA = $(".listsbox .freeControl a");
    fcA.click(function() {
        var curIndex = fcA.index($(this)[0]);
        var obj = $(".listsbox .movableList");
        var left = curIndex * $(".movableList").width();
        fcA.removeClass("curr");
        $(this).addClass("curr");
        obj.animate({ "scrollLeft": left }, 250, function() {
            if (curIndex == 0) { $(".listsbox .preNextControl a.prePage").addClass("disabled"); } else { $(".listsbox .preNextControl a.prePage").removeClass("disabled"); }
            if (curIndex + 1 >= pcount) { $(".listsbox .preNextControl a.nextPage").addClass("disabled"); } else { $(".listsbox .preNextControl a.nextPage").removeClass("disabled"); }
            if (curIndex > 0 && curIndex + 1 < pcount) { $(".listsbox .preNextControl a.prePage,.listsbox .preNextControl a.nextPage").removeClass("disabled"); }
        });
        return false;
    });
    fcA.eq(0).click();
    $(".listsbox .preNextControl a.prePage,.listsbox .preNextControl a.nextPage").click(function() {
        if ($(this).hasClass("disabled")) { return false; }
        var curIndex = fcA.index($(".listsbox .freeControl a[class='curr']"));
        if ($(this).hasClass("prePage")) {
            fcA.eq(curIndex - 1).click();
        }
        else {
            fcA.eq(curIndex + 1).click();
        }
        return false;
    });

}



function RoomPaging(pagesize) {
    var count = $(".movableList dl:visible dd:visible").length;
    var pcount = Math.floor(count / pagesize);
    if (count % pagesize > 0 && count > pagesize)
        pcount++;
    if (pcount == 0)
        pcount = 1;
    $(".listsbox .freeControl").empty();
    for (var i = 0; i < pcount; i++) {
        $(".listsbox .freeControl").append("<a href='#" + i + "'></a>");
    }
    var fcA = $(".listsbox .freeControl a");
    var obj = $(".listsbox .movableList");
    fcA.click(function() {
        var curIndex = fcA.index($(this)[0]);        
        var left = ($(".movableList dl dd:eq(0)").width() + 17) * curIndex * pagesize;
        fcA.removeClass("curr");
        $(this).addClass("curr");
        obj.animate({ "scrollLeft": left }, 250, function() {
            if (curIndex == 0) { $(".listsbox .preNextControl a.prePage").addClass("disabled"); } else { $(".listsbox .preNextControl a.prePage").removeClass("disabled"); }
            if (curIndex + 1 >= pcount) { $(".listsbox .preNextControl a.nextPage").addClass("disabled"); } else { $(".listsbox .preNextControl a.nextPage").removeClass("disabled"); }
            if (curIndex > 0 && curIndex + 1 < pcount) { $(".listsbox .preNextControl a.prePage,.listsbox .preNextControl a.nextPage").removeClass("disabled"); }
        });
        return false;
    });
    
    $(".listsbox .preNextControl a.prePage,.listsbox .preNextControl a.nextPage").click(function() {
        if ($(this).hasClass("disabled")) { return false; }
        var curIndex = fcA.index($(".listsbox .freeControl a[class='curr']"));
        if ($(this).hasClass("prePage")) {
            fcA.eq(curIndex - 1).click();
        }
        else {
            fcA.eq(curIndex + 1).click();
        }
        return false;
    });


    var allList = $(".movableList dl:visible dd");
    var curObj = $(".movableList dl:visible dd.curr");       
    var aIndex = allList.index(curObj[0]) + 1;
    apcount = Math.floor(aIndex / pagesize);
    if (aIndex > pagesize && aIndex % pagesize > 0)
        apcount++;
    apcount = apcount - 1 < 0 ? 0 : apcount - 1;
    fcA.removeClass("curr");
    fcA.eq(apcount).addClass("curr");

    var left1 = apcount * ($(".movableList dl dd:eq(0)").width() + 17) * pagesize;
    obj.scrollLeft(left1);
    if (apcount == 0) { $(".listsbox .preNextControl a.prePage").addClass("disabled"); } else { $(".listsbox .preNextControl a.prePage").removeClass("disabled"); }
    if (apcount + 1 >= pcount) { $(".listsbox .preNextControl a.nextPage").addClass("disabled"); } else { $(".listsbox .preNextControl a.nextPage").removeClass("disabled"); }
    if (apcount > 0 && apcount + 1 < pcount) { $(".listsbox .preNextControl a.prePage,.listsbox .preNextControl a.nextPage").removeClass("disabled"); }


}

//photo翻页
function PhotoPaging(pagesize) {
    var count = $(".movableList ul li").length;
    
    var pcount = Math.floor(count / pagesize);
    if (count % pagesize > 0 && count > pagesize)
        pcount++;
    if (pcount == 0)
        pcount = 1;
    $(".listsbox .freeControl").empty();
    for (var i = 0; i < pcount; i++) {
        $(".listsbox .freeControl").append("<a href='#" + i + "'></a>");
    }
    var fcA = $(".listsbox .freeControl a");
    fcA.click(function() {
        var curIndex = fcA.index($(this)[0]);
        var obj = $(".movableList");

        var left = (obj.find("ul li").width() + 5) * curIndex * pagesize;
        if (curIndex > 0)
            left += 124;


        fcA.removeClass("curr");
        $(this).addClass("curr");
        obj.animate({ "scrollLeft": left }, 250, function() {
            if (curIndex == 0) { $(".listsbox .preNextControl a.prePage").addClass("disabled"); } else { $(".listsbox .preNextControl a.prePage").removeClass("disabled"); }
            if (curIndex + 1 >= pcount) { $(".listsbox .preNextControl a.nextPage").addClass("disabled"); } else { $(".listsbox .preNextControl a.nextPage").removeClass("disabled"); }
            if (curIndex > 0 && curIndex + 1 < pcount) { $(".listsbox .preNextControl a.prePage,.listsbox .preNextControl a.nextPage").removeClass("disabled"); }
        });
        return false;
    });
    fcA.eq(0).click();
    $(".listsbox .preNextControl a.prePage,.listsbox .preNextControl a.nextPage").click(function() {
        if ($(this).hasClass("disabled")) { return false; }
        var curIndex = fcA.index($(".listsbox .freeControl a[class='curr']"));
        if ($(this).hasClass("prePage")) {
            fcA.eq(curIndex - 1).click();
        }
        else {
            fcA.eq(curIndex + 1).click();
        }
        return false;
    });

    var allList = $(".movableList ul li");
    var curObj = $(".movableList ul li.pselect");    
    var aIndex = allList.index(curObj[0]) + 1;
    apcount = Math.floor(aIndex / pagesize);
    if (aIndex > pagesize  && aIndex % pagesize  > 0)
        apcount++;
    fcA.eq(apcount - 1 < 0 ? 0 : apcount - 1).click();
    
    
    
}
