﻿
//// script cho phần đối tác chạy
//var partner = document.getElementById("partner");
//var child = partner.getElementsByTagName("div");
//var n = 10;
//for (var i = 0; i < child.length ; i++) {
//    child[i].style.left = n + "px";
//    n = n + 230;
//}

//// di chuyen
//function dichuyen() {
//    for (var i = 0; i < child.length; i++) {
//        var x = parseInt(child[i].style.left);
//        x = x - 5;
//        if (x <= -180) { x = 180 * 1.3 * (child.length - 1); }
//        child[i].style.left = x + "px";
//    }
//    window.setTimeout("dichuyen()", 100);
//}
//dichuyen();
///////////////////////////////////////////////////////////////////////
//script cho pần slide
var $ = jQuery.noConflict();
$(function () {
    $('.flexslider').flexslider({
        animation: "fade"
    });
    
    //$('.right-gallery').flexslider({
    //    animation: "fade"
    //});
    
    $('.show_menu').click(function () {
        $('.menu').fadeIn();
        $('.show_menu').fadeOut();
        $('.hide_menu').fadeIn();
    });
    $('.hide_menu').click(function () {
        $('.menu').fadeOut();
        $('.show_menu').fadeIn();
        $('.hide_menu').fadeOut();
    });
});
$(document).ready(function () {
    //--Menu top
    $(".nav li").hover(function () {
        $(this).find('ul:first').css({ visibility: "visible", display: "none" }).show(200);
    }, function () {
        $(this).find('ul:first').css({ visibility: "hidden" });
    });
    //--Xem nhieu nhat
    $(".newsticker-jcarousellite").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        vertical: false,
        hoverPause: true,
        visible: 1,
        auto: 4000,
        speed: 500
    });
    $(".gioithieusach").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        vertical: true,
        hoverPause: true,
        visible: 1,
        auto: 4000,
        speed: 500
    });
    //--Xem nhieu nhat
    $("#partner").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        vertical: false,
        hoverPause: true,
        visible: 5,
        auto: 4000,
        speed: 500
    });
});
// === Search google
function URLEncode(clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;
    while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '') {
            output += match[1];
            x += match[1].length;
        } else {
            if (clearString[x] == ' ')
                output += '+';
            else {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }
            x++;
        }
    }
    return output;
}

function submitonenter(myfield, e) {
    var keycode;
    if (window.event)
        keycode = window.event.keyCode;
    else if (e)
        keycode = e.which;
    else
        return true;
    if (keycode == 13) {
        searchsite();
        return false;
    }
    else
        return true;
}
function searchsite() {
    document.location = document.getElementById('uRoot').value + 'search.aspx?siteurl=www.cssd.vn%2F&cx=010999634729748114865:a0qn8n8jh1o&cof=FORID%3A10&ie=utf-8&q=' + URLEncode(document.getElementById('q').value);
}

function cycleImages() {
    var $active = $('#cycler .active');
    var $next = ($active.next().length > 0) ? $active.next() : $('#cycler img:first');
    $next.css('z-index', 2);//move the next image up the pile
    $active.fadeOut(1500, function () {//fade out the top image
        $active.css('z-index', 1).show().removeClass('active');//reset the z-index and unhide the image
        $next.css('z-index', 3).addClass('active');//make the next image the top one
    });
}

$(document).ready(function () {
    // run every 4s
    setInterval('cycleImages()', 3000);
})
// Phan trang bai viet
function loadpage() {
    var loc = getParameter('page');
    var tag = document.getElementById('P' + loc);
    if (tag == null) {
        tag = document.getElementById('P1');
    }
    tag.style.display = 'block';
    tag = document.getElementById('N' + loc);
    if (tag == null) {
        tag = document.getElementById('N1');
    }
    tag.className = 'curpage';
}
function getParameter(name) {
    var loc = location + '';
    var pos = loc.indexOf('?');
    if (pos < 0) return '';
    loc = loc.substring(pos + 1);
    pos = loc.indexOf(name + '=');
    if (pos < 0) return '';
    loc = loc.substring(pos + name.length + 1);
    pos = loc.indexOf('&');
    if (pos >= 0) {
        loc = loc.substring(0, pos);
    }
    return loc;
}