function fix_ie_z_index()
{
    var zIndex = 1000;
    
    $('div').each(function(){
       $(this).css('zIndex', zIndex);
       zIndex -= 10;
    });
}

function change_page(offset, per_page)
{
    var current_uri = $('input[name=current_uri]').val();
    var page = offset / per_page + 1;
    var url = current_uri + 'trang-' + page;

    location.href = url;
    return;
}

function auto_schroll()
{
    if ($('.customers')) $(function() {
	$(".customers").jCarouselLite({
		vertical: true,
		hoverPause: true,
		visible: 3,
		auto:500,
		speed:1000
	});
    });
}

function enable_simple_wysiwyg(selector)
{
    tinyMCE.init({
        mode : "textareas",
        editor_selector : selector,
        theme : "advanced",
        invalid_elements : "div,script,abbr,acronym,address,applet,area,bdo,big,blockquote,button,caption,cite,code,col,colgroup,dd,del,dfn,iframe,input,ins,isindex,kbd,label,legend,map,menu,noscript,object,optgroup,option,param,textarea,var,ruby,samp,select,rtc,a,h1,h2,h3,h4,h5,font,span,img,table,tr,th,td,hr",
        height: "300px",
        plugins : "paste",
        paste_auto_cleanup_on_paste : true,
        theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        //theme_advanced_path_location : "bottom",
        entity_encoding : "raw",
        language : 'en',
        theme_advanced_buttons1_add : ""
    });
}

function enable_advanced_wysiwyg(selector)
{
    tinyMCE.init({
        mode : "textareas",
        editor_selector : selector,
        theme : "advanced",
        invalid_elements : "div,script,abbr,acronym,address,applet,area,bdo,big,blockquote,button,caption,cite,code,col,colgroup,dd,del,dfn,iframe,input,ins,isindex,kbd,label,legend,map,menu,noscript,object,optgroup,option,param,textarea,var,ruby,samp,select,rtc,span,hr",
        width: "100px",
        height: "300px",
        plugins : "paste,inlinepopups,contextmenu,table,heading,preview",
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,h1,h2,h3,|,justifyleft,justifycenter,justifyright,bullist,numlist,|,image,table",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        //theme_advanced_path_location : "bottom",
        entity_encoding : "raw",
        language : 'en',
        theme_advanced_buttons1_add : "forecolor,backcolor,separator,link,unlink,pasteword, preview",
        plugin_preview_width : "640",
        plugin_preview_height : "480",
        convert_urls : false
    });
}

function insert_news_image(image)
{
    image = '<img src="' + image + '" />';
    tinyMCE.execCommand('mceInsertContent', false, image);
}

function change_images_page(offset, per_page)
{
    var current_uri = $('input[name=current_uri]').val();
    var page = offset / per_page + 1;
    var url = current_uri + 'trang-' + page;

    $.ajax(
    {
        type:   'post',
        url:    url,
        data:   {
            'is-ajax'           : 1,
            'offset'            : offset,
            'per_page'          : per_page
        },
        success: function(responseText) {
            if ($('#images_list'))
                $('#images_list').html(responseText);
        }
    });
}

function submit_news(id, action)
{
    if (action=='xoa-tin')
        if ( !confirm('Bạn có thực sự muốn xóa tin này không?'))
            return;

    $('input[name=news_id]').val(id);
    $('#news').attr('action', '/admin/news/'+action);
    $('#news').submit();
}

function show_image(target, src)
{
    if ($('#' + target))
        $('#' + target).attr('src', src);
}

$(document).ready(function()
{
    // add banner functionalities
    if ($('.gallery1').length > 0) $('.gallery1').gallery();
    auto_schroll();
});
