$(function() {

    function reset_active_filter() {
        $("#filter_nav ul li a").removeClass("active");
        $(".list_content").fadeOut(100);
        // return false;
    }


    $('#btn_sort_genre').click(function() {
        reset_active_filter();
        $("#filter_content").slideDown("slow");
        $('#filter_content').animate({ height: '100px' }, 100, function() { });
        $(this).addClass("active");
        $("#list_genre").fadeIn(700);
        return false;
    });


    $('#btn_sort_type').click(function() {
        reset_active_filter();
        $('#filter_content').animate({ height: '120px' }, 100, function() { });
        $("#filter_content").slideDown("slow");
        $(this).addClass("active");
        $("#list_type").fadeIn(700);
        return false;
    });
    
    
    $('#btn_sort_studio').click(function() {
        reset_active_filter();
        $('#filter_content').animate({ height: '60px' }, 100, function() { });
        $("#filter_content").slideDown("slow");
        $(this).addClass("active");
        $("#list_studio").fadeIn(700);
        return false;
    });


    $('#btn_sort_alphabet').click(function() {
        reset_active_filter();
        $('#filter_content').animate({ height: '40px' }, 100, function() { });
        $("#filter_content").slideDown("slow");
        $(this).addClass("active");
        $("#list_alphabet").fadeIn(700);
        return false;
    });



    $('#filter_content_close a').click(function() {
        reset_active_filter();
        $("#filter_content").slideUp("slow");
        $(this).removeClass("active");
        return false;
    });



    if ($("body").hasClass('home')) {

        $("#li-banner").sp_Li_Slider({
            animation: "Regular-Exception",		
            transitions: 'Fade',
            auto_play: true,
            repeat: true,
            modalMode: 'off',
            goToSlideOnStart: 1,
            timer: 'none',
            pauseOnMouseOver: true,
            tooltip: 'none',
            tooltipSize: 20,
            shuffle: false,
            delay: 2000,
            trans_period: 800,
            vert_sections: 10,
            sqr_sections_Y: 4,
            active_links: true,
            buttons_show: true,
            play_pause_show: false,
            next_prev_show: true,
            auto_hide: false,
            buttons_show_time: 2000,
            buttons_show_delay: 500,
            buttons_hide_time: 2000,
            buttons_hide_delay: 500
        });

    }

    /*
    if ($("body").hasClass('home')) {
        if ($("#fancybox-bg-n").hasClass('fancybox-bg')) {
            $("#wrapper").hide();
            $("body.home").css("background-image","none");
        }
    }
    */


    if ($("#product_single").hasClass('product_detail')) {
        $("#product_gallery").tabs();
    }




    //add IE6 notification to body pages
    if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
        var ie6Text = '<div id="upgrade_browser"><div class="content"><p><span id="alert">ขออภัย</span><br /> คุณกำลังใช้เบราเซอร์รุ่นที่เก่ากว่า Internet Explorer 7 กรุณาติดตั้งเบราเซอร์รุ่นใหม่เพื่อเข้าเว็บนี้อีกครั้ง</p><br /><p><strong>ดาวน์โหลด</strong></p>\
            <ul>\
                <li><a href="http://www.mozilla.com/en-US/firefox/new/" title="Download Firefox" target="_blank"><img src="/img/browser_firefox.jpg" alt="" /></a></li>\
                <li><a href="http://www.google.com/chrome/" title="Download Google Chrome" target="_blank"><img src="/img/browser_chrome.jpg" alt="" /></a></li>\
                <li><a href="http://windows.microsoft.com/th-TH/internet-explorer/products/ie/home" title="Download Internet Explorer" target="_blank"><img src="/img/browser_ie.jpg" alt="" /></a></li>\
            </ul>\
            </div></div>';
        $("body").append(ie6Text);

    }




    // Search Input Swap
    $(".search_holder input").focus(function() {
        $(this).parent().addClass('active');
    });

    $(".search_holder input").focusout(function() {
        $(this).parent().removeClass('active');
    });




    $("#watch_trailer").fancybox({
        'width': 640,
        'height': 350,
        'autoScale': true,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe',
        'scrolling': 'no',
        'overlayColor': '#000',
        'centerOnScroll': 'true',
        'overlayOpacity': '0.85'
    });

    $("#theatreTrailer").fancybox({
        'width': '640px',
        'height': '350px',
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe',
        'scrolling': 'no',
        'overlayColor': '#000',
        'centerOnScroll': 'true',
        'overlayOpacity': '0.9'
    });

    

});




function validate() {
    document.getElementById('invalid').style.display = 'none';
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = document.getElementById('email').value;
    if (reg.test(address) == false) {
        setTimeout("showinvalid()", 100);
        return false;
    } else {

    if (document.getElementById('nonmember').checked) {
        document.location.href = '/register/' + document.getElementById('email').value;
    } 
    else { document.location.href = '/subscriber/' + document.getElementById('email').value; }
    }
}
function showinvalid()
{ document.getElementById('invalid').style.display = 'block'; }

function submitonEnter(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode == "13") {
        __doPostBack('ctl00_LinkTextBox', '');
    }
}

function Employees_Populated(sender, e) {
    var employees = sender.get_completionList().childNodes;
    for (var i = 0; i < employees.length; i++) {
        var getallvalue = employees[i]._value.split("**");

        // IMG DIV
        var div = document.createElement("DIV");
        //div.innerHTML = "<div style='clear:both;height:60px;'><a style='float:left;' href='/movie/" + getallvalue[2] + "'><img style = 'margin-top:5px;padding-left:10px;padding-right:10px;height:50px;width:50px' src = '" + getallvalue[1] + "' /></a><span style='height:50px;font-weight:bold;'>" + getallvalue[3] + "</span><br/>วางจำหน่าย: " + getallvalue[0] + "</div>";
        div.innerHTML = "<div class=\"quick_search_row\"><div class=\"thumbnail\"><img src = \"" + getallvalue[1] + "\" /></div><div class=\"detail\"><h5>" + getallvalue[3] + "</h5><p>วางจำหน่าย: " + getallvalue[0] + "</p></div></div>";
        employees[i].appendChild(div);
    }
}
function OnEmployeeSelected(source, eventArgs) {
    var idx = source._selectIndex;
    var employees = source.get_completionList().childNodes;
    var getallvalue = employees[idx]._value.split("**");
    document.location.href = '/movie/' + getallvalue[2];
    var value = employees[idx]._value;
    var text = employees[idx].firstChild.nodeValue;
    source.get_element().value = _text;
}


