/*

ACTIONS ELEMENTS

Created by VL
www.FXOPEN.com

*/

var flag=0;
var DragTop=0;
var DragTopFlag=0;
var accordionID =1;
var key = '';
var keyW = [];
var d=new Date();
var timez = d.getTime + 1000000;
var setNum ='fxTabS1N1';
var element,wiki,wiki_slide1,wiki_slide2,c,el,fx_select,ThisSelect,ThisSelect2,ThisSelect3,ThisSelect4,fl,f,loc,linum,moveFlag,last_ht2;
var is_ie6 =document.all && (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1);
var is_ie8 =getInternetExplorerVersion();

$(document).ready(function(){ 

    el = $(".fx_select_value");
    for (var i = 0; i < el.length; i++) {
        el[i].style.opacity = '0';
        el[i].style.width = 500 + 'px';
    }

//set width table
    fx_select = $(".fx_select");
    ScrollPane = $(".scroll-pane");
    

//input text
    var elInput = $(".fx_inp_text_center");
    for (var i = 0; i < elInput.length; i++) {
        elInput[i].style.width = elInput[i].offsetWidth -10 +'px';
    }
    $(".fx_inp_text_left,.fx_inp_text_right").css({ display: 'block' });
           
//select  
    if (!is_ie6){
        $(".scroll-pane").jScrollPane({showArrows:true, scrollbarWidth: 15});
    }
    
    var s1=0,s2=10;
    
    var Select = $(".fx_select_value");
    var SelectContainer = $(".jScrollPaneContainer");
    var SelectTBLtop = $(".fx_select_value_tbl_top");
    var SelectTBLbottom = $(".fx_select_value_tbl_bottom");
    var SelectTBLtCenter = $(".fx_select_value_tbl_top_center");
    var SelectTBLbCenter = $(".fx_select_value_tbl_bottom_center");
    var SelectTBLscroll = $(".scroll_tbl");
    var SelectScroll = $(".scroll");
   
    if(!is_ie6){
        for (var i = 0; i < Select.length; i++) {
            if(SelectContainer[i].offsetHeight > 179){
                s1 = -1;
                s2 = 11;
            }else{
                s1 = 1;
                s2 = 10;
            }
            
            SelectTBLtop[i].style.width = fx_select[i].offsetWidth + s1 + 'px';
            SelectTBLbottom[i].style.width = fx_select[i].offsetWidth + s1 + 'px';
            SelectTBLtCenter[i].style.width = fx_select[i].offsetWidth - s2 + 'px';
            SelectTBLbCenter[i].style.width = fx_select[i].offsetWidth - s2 + 'px';
            
            if(SelectContainer[i].offsetHeight > 179){
                 SelectContainer[i].className = (SelectContainer[i].className + " " + "fix_border");
                 SelectContainer[i].style.width = fx_select[i].offsetWidth - 2 + 'px';
                 SelectTBLscroll[i].style.width = fx_select[i].offsetWidth - 12 + 'px';
            }else{
                SelectContainer[i].style.width = fx_select[i].offsetWidth -1 + 'px';
                SelectTBLscroll[i].style.width = fx_select[i].offsetWidth + 'px';
                ScrollPane[i].style.width = fx_select[i].offsetWidth + 'px';
            }
                      
        }
    }else{
        for (var i = 0; i < Select.length; i++) {
            if(SelectTBLscroll[i].offsetHeight>179){
                SelectScroll[i].style.overflowY = 'scroll';
                SelectScroll[i].style.height = 180 + 'px';
                SelectScroll[i].style.height = 180 + 'px';
                SelectScroll[i].className = (SelectScroll[i].className + " " + "no_border");
                SelectTBLscroll[i].style.width = fx_select[i].offsetWidth - 18 + 'px';
            }
            
            SelectTBLscroll[i].style.width = fx_select[i].offsetWidth + 'px';
            SelectTBLtop[i].style.width = fx_select[i].offsetWidth + 'px';
            SelectTBLbottom[i].style.width = fx_select[i].offsetWidth + 'px';
            SelectTBLtCenter[i].style.width = fx_select[i].offsetWidth - 10 + 'px';
            SelectTBLbCenter[i].style.width = fx_select[i].offsetWidth - 10 + 'px';
        }
    }
    
    for (var i = 0; i < el.length; i++) {
        el[i].style.display = 'none';
        el[i].style.width = 'auto';
        el[i].style.visibility = 'visible';
    }
    
    setDefaulWiki();
    //wiki
        $(".fx_wiki_s").click(function(){
            if($(this).find("input").focus()){
                flag=1;
                setDefaulWiki();
                $(".fx_select").css({zIndex: ''});
                selectValueNone();
                
                wiki = $(this).find(".fx_wiki")
                wiki.css({display: 'block'});
                if($(this).hasClass("fx_wiki_s_anti")){
                    wiki_slide1 = 96; 
                    wiki_slide2 = 77; 
                }else{
                    wiki_slide1 = 150;
                    wiki_slide2 = 12;
                }
                wiki.animate({top: -wiki.height()+wiki_slide1},1,function(){
                    wiki.animate({opacity: 1, top: -wiki.height()-wiki_slide2-25},250,function(){
                        wiki.animate({top: -wiki.height()-wiki_slide2},200);
                    });    
                });
            }
        });
    
    //click select    
    $(".fx_select").click(function(){
        for (var i = 0; i < el.length; i++) {
            el[i].style.opacity = '1';
        }
        $(".fx_select").css({zIndex: 1});
        $(this).css({zIndex: 20});
        
        //key word
        ThisSelect = null;
        ThisSelect = $(this);
        ThisSelect2 = ThisSelect.find("td p span");
        ThisSelect3 = ThisSelect.find("td p");
        
        var i=0;
        var Ptext;
        keyW = [];
        key='';
        f=null;
        
        if(flag!= 2){
            flag=1;
            moveFlag=1;
            setDefaulWiki();
            element = $(this).find('em');
            selectValueNone();
            $(this).find(".fx_select_value").css({display: 'block'});
        }  
        
        ThisSelect4 = ThisSelect.find(".scroll_tbl").height();
        
        for (var i = 0; i < ThisSelect2.length; i++) {
            Ptext = ThisSelect2[i].innerHTML;
            if(is_ie6){
                if(ThisSelect4>179){
                    ThisSelect3[i].style.width = ThisSelect.width() - 18 + 'px';
                    ThisSelect3[i].style.Left = -1 + 'px';
                }else{
                    ThisSelect3[i].style.width = ThisSelect.width() - 2 + 'px';
                }
            }
            keyW[i] = Ptext.toUpperCase();
        }   
        
    });

    $().click(function(){
        if(flag==0){
            selectValueNone();
            setDefaulWiki();
        }else{
            flag=0;
            moveFlag=1;
        }
    });
        
    $(".fx_select p").click(function(){
        flag=2;
        var textSpan = $(this).find("span")
         if(textSpan.text() != "-"){
        if(textSpan.width() > $(this).width()){
          var colCh = $(this).width()/(textSpan.width() / textSpan.text().length) -6;
          element.text(textSpan.text().substring(0,colCh)+'...');  
        }else{
            element.text(textSpan.text());
        }
        selectValueNone();
       }
    });
       
    //hover 
    $(".fx_select_value p").mouseover(function(){
        //move text
        if($(this).find("span").text() != "-"){
        moveFlag=0;
        var ht1 =$(this).width();
        var ht2 =$(this).find("span").width();
        last_ht2 = ht2;
        if(ht1 < ht2+8){
            $(this).addClass('fx_select_value_p_activeMove');
            if(locationS==0){
                moveSelectSpan($(this).find("span"),ht1,ht2);
            }else{
                moveSelectSpanLeft($(this).find("span"),ht1,ht2);
            }
        }
        $(this).addClass('fx_select_value_p_active');
      }
    });
    $(".fx_select_value p").mouseout(function(){
        $(this).removeClass('fx_select_value_p_active');
        $(this).removeClass('fx_select_value_p_activeMove');
        moveFlag=1;
        last_ht2 = -1;
    });
    
    
    $(".fx_select_value p span").mouseout(function(){
        moveFlag=1;
    });
    
    
     //
     $().keydown(function(event)
        {      
            if(ThisSelect != null){
            if(ThisSelect.find(".fx_select_value").css("display") !="none"){
                var d=new Date();
                var notime =d.getTime() - timez;
                timez=d.getTime();
                if(notime>1000){
                    notime = 0;
                }

                if(event.keyCode == 27){key='';}else{
                if(notime==0){key='';}
                key +=String.fromCharCode(event.keyCode).toUpperCase();
                var clm=flg=0;
                
                if((!is_ie6)&&(ThisSelect!=null)){
                
                //search
                    var allH = ThisSelect.find(".scroll_tbl").height();
                    var j=0;
                    while((j<keyW.length)&&(flg!=1)){
                        var keyWw = keyW[j].toUpperCase();
                        if(keyWw.lastIndexOf(key,0) == 0){
        
                            if(j==0){clm=0;}
                            if((j>0)&&(j <= 40)){clm =j*22.08 + (j/10);}
                            if((j>40)&&(j <= 150)){clm =j*22.6026 + (j/10);}
                            if((j>150)&&(j <= 200)){clm =j*22.0862944 + (j/10);}
                            if(j>200){clm =j*22.5 + (j/10);}
                            
                            if(clm > ThisSelect.find(".scroll_tbl").height()-180){
                                clm = ThisSelect.find(".scroll_tbl").height() - 180;
                            }    
                            ThisSelect.find(".scroll-pane").css({top: -clm});    
                            DragTop = clm/(allH/160);
                            DragTopFlag =0;
                            ThisSelect.find(".jScrollPaneDrag").css({top: (DragTop)});      
                            ThisSelect.find("td p").removeClass("fx_select_value_p_active");
                            ThisSelect3[j].className = (ThisSelect3[j].className + " " + "fx_select_value_p_active");
                            
                            flg=1;
                        }
                        j++;
                    }
                }else{
                        if(ThisSelect!=null){
                                    var j=0;
                                    while((j<keyW.length)&&(flg!=1)){
                                    var keyWw = keyW[j].toUpperCase();
                                    if(keyWw.lastIndexOf(key,0) == 0){
                                        ThisSelect2[j].className = (ThisSelect2[j].className + " " + "fx_select_value_p_active");
                                        if(f){
                                            ThisSelect2[f].className = "";
                                        }
                                        f=j;
                                        clm =j*23;
                                        ThisSelect.find(".scroll").scrollTo({top:clm},0);
                                        flg=1;
                                    }
                                    j++;
                                    }
                            }
                    }
                }
            }
            }
    });

//table ie
    $(".pamm_b3_tbl td").css({backgroundPositionY: 'top'});
    
//fx_tabs
    linum = $("#fx_tabs_s1_menu").find("a");
    loc = window.location.hash;
    loc = loc.substring(9,loc.length);
    
    if(loc){
        $(".fx_tabs_s1_container").css({display: 'none'});
        $("#fxTabS1N"+loc).css({display: 'block'});
        $('html,body').animate({scrollTop: 0},500);
    }else{
        loc=1;
    }

    if(linum.length > 1){
    	setMapTabsNum(loc);
    }else{
        //hide navigation
        $(".b_line_s7 .fx_span_left,.b_line_s7 .fx_span_right").addClass("no_display");
    }

//hover menu 
    if (is_ie6){
        $(".navigation li").mouseover(function(){
            $(this).css({backgroundPositionY: 'bottom'});
        });
            
        $(".navigation li").mouseout(function(){
            $(".navigation li").css({backgroundPositionY: 'top'});
        });
    }
    
    //smb mouse events
    
    $(".fx_smbClick").mouseover(function(){
        $(this).addClass('fx_smb_active_s1');
    }).mouseout(function(){
        $(this).removeClass('fx_smb_active_s1');
        $(this).removeClass('fx_smb_active_s2');
    }).mouseup(function(){
        $(this).removeClass('fx_smb_active_s2');
        $(this).addClass('fx_smb_active_s1');
    }).mousedown(function(){
        $(this).removeClass('fx_smb_active_s1');
        $(this).addClass('fx_smb_active_s2');
    });
    
    
    if(is_ie8>0){
        $("body").addClass("body_ie");
    }
    
    //fx_slideV
    $(".fx_slideV_title a").click(function(){
        slideV_content = $(this).parent().next(".fx_slideV_content");
            
        if(!$(this).hasClass("active")){
            $(this).addClass("active");
            slideV_content.slideDown("100");
        }else{
            $(this).removeClass("active");
            slideV_content.slideUp("50");
        }
        
        return false;
    });
    
    //is Float validation
    
    var fl = 0; 
    $('.isfloat').live('keypress',function(e){

        if($(this).val().indexOf(".") < 0){
            fl = 0;
        }else{
            fl++;
        }
        
        if($(this).val() == ""){
            fl = 0;
        }
        
        if(e.which == 46 && fl == 0){
            fl++;
        }else{
            return (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) ? false : true;
        }
    });

    //panel_followus
    $("#followusIco a").mouseover(function () {
        $(this).animate({ right: -136 }, 200);
        $(this).addClass("followus_ico_active");
    }).mouseout(function () {
        $(this).animate({ right: 0 }, 250);
        $(this).removeClass("followus_ico_active");
    });

    if (is_ie6) {
        fh = $("#followusIco").height();
        h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
        scrollH = document.documentElement.scrollTop;
        hI = (h + fh + 50) / 2 + scrollH;
        $("#followusIco").css({ top: hI });

        $(window).scroll(function () {
            h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
            scrollH = document.documentElement.scrollTop;
            hI = (h + fh + 50) / 2 + scrollH;
            $("#followusIco").css({ top: hI });
        });
    } 
    
});

function moveSelectSpan(moveSpanN,ht1,ht2){
    $("#no_use").animate({opacity: 0},800,function(){
        if(last_ht2==ht2){
            moveSpanN.animate({left: -(19+ht2-ht1)},3500).animate({left: 0},3500,function(){
                if(moveFlag==0){
                    moveSpanN = $(".fx_select_value_p_activeMove span");
                    moveSelectSpan(moveSpanN,ht1,ht2);
                }
            });
        }
    });
}

function moveSelectSpanLeft(moveSpanN,ht1,ht2){
    $("#no_use").animate({opacity: 0},800,function(){
        if(last_ht2==ht2){
            moveSpanN.animate({right: -(19+ht2-ht1)},3500).animate({right: 0},3500,function(){
                if(moveFlag==0){
                    moveSpanN = $(".fx_select_value_p_activeMove span");
                    moveSelectSpanLeft(moveSpanN,ht1,ht2);
                }
            });
        }
    });
}

function setDefaulWiki(){
    var elWiki = $(".fx_wiki");
    for (var i = 0; i < elWiki.length; i++) {
        elWiki[i].style.top = elWiki[i].offsetHeight - 10 + 'px';
        elWiki[i].style.display = 'none';
        elWiki[i].style.opacity = '0';
    }

    selectValueNone();
}

function selectValueNone(){
    for (var i = 0; i < el.length; i++) {
        el[i].style.display = 'none';
    }
}

//fx_tabs_s1
function fx_tabs_s1(num){
    if(num!=setNum){
        $(".fx_tabs_s1_container").css({display: 'none'});
        $("#"+num).css({display: 'block'});
        setNum =num;
        setMapTabsNum(num.substring(8,num.length));
    }
}

function setMapTabsNum(loc){
    
    if(!is_ie6){
        $(window).scrollTo("334",500);
    }else{
        $(window).scrollTo("422",500);
    }
    
    loc = parseInt(loc);
    aText1 =$("#fx_tabs_textBack").val();
    aText2 =$("#fx_tabs_textNext").val();
    
    
    if((loc<linum.length)&&(loc>1)){
        $("#fx_tabs_s1_menu a").removeClass("fx_tabs_menu_active");
        linum[loc-1].className = (linum[loc-1].className + " " + "fx_tabs_menu_active");
        $("#fx_tabs_back_title").text(linum[parseInt(loc)-2].innerHTML);
        $("#fx_tabs_next_title").text(linum[parseInt(loc)].innerHTML);
        $("#fx_tabs_s1_title").text(linum[parseInt(loc-1)].innerHTML);
        url = "fx_tabs_s1('fxTabS1N"+(loc-1)+"')";
        $("#fx_tabs_back").removeClass("no_display");
        $("#fx_tabs_back").removeClass("no_display").html("<a class=\"tshadow_s1\" href=\"#fxTabS1N"+(loc-1)+"\" onclick=\"fx_tabs_s1('fxTabS1N"+(loc-1)+"')\">"+aText1+"</a>");
        $("#fx_tabs_next").removeClass("no_display").html("<a class=\"tshadow_s1\" href=\"#fxTabS1N"+(loc+1)+"\" onclick=\"fx_tabs_s1('fxTabS1N"+(loc+1)+"')\">"+aText2+"</a>");
    }else{
        if((loc==linum.length)&&(linum.length!=1)){
            $("#fx_tabs_s1_menu a").removeClass("fx_tabs_menu_active");
            linum[loc-1].className = (linum[loc-1].className + " " + "fx_tabs_menu_active");
            $("#fx_tabs_back_title").text(linum[loc-2].innerHTML);
            $("#fx_tabs_next_title").text("");
            $("#fx_tabs_s1_title").text(linum[parseInt(loc-1)].innerHTML);
            $("#fx_tabs_back").removeClass("no_display");
            url = "fx_tabs_s1('fxTabS1N"+(loc-1)+"')";
            $("#fx_tabs_back").removeClass("no_display").html("<a class=\"tshadow_s1\" href=\"#fxTabS1N"+(loc-1)+"\" onclick=\"fx_tabs_s1('fxTabS1N"+(loc-1)+"')\">"+aText1+"</a>");
            $("#fx_tabs_next").addClass("no_display");
        }else{
            if(loc==1){
                $("#fx_tabs_s1_menu a").removeClass("fx_tabs_menu_active");
                linum[loc-1].className = (linum[loc-1].className + " " + "fx_tabs_menu_active");
                $("#fx_tabs_back_title").text("");
                $("#fx_tabs_back").addClass("no_display");
                $("#fx_tabs_s1_title").text(linum[parseInt(loc-1)].innerHTML);
                if(linum.length!=1){
                    $("#fx_tabs_next_title").text(linum[loc].innerHTML);
                    $("#fx_tabs_next").html("<a class=\"tshadow_s1\" href=\"#fxTabS1N"+(loc+1)+"\" onclick=\"fx_tabs_s1('fxTabS1N"+(loc+1)+"')\">"+aText2+"</a>");
                }else{
                    $("#fx_tabs_next_title").text("");
                }
            }
        }
    }
}

function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
    
}

function fx_cb_check(){
    var find_check = $(".fx_check_id").find("input[type='checkbox']");
    for(var i=0;i<find_check.length;i++){
        find_check[i].checked = true;
    }
}

function fx_cb_check_clear(){
    var find_check = $(".fx_check_id").find("input[type='checkbox']");
    for(var i=0;i<find_check.length;i++){
        find_check[i].checked = false;
    }
}


function __TypeLimit(elem, maxsize, msg) {
    if (elem.value.length >= maxsize) {
        if (msg) {
            alert(msg);
        }
    }
    if (elem.value.length >= maxsize) {
        elem.value = elem.value.substring(0, maxsize - 1);
        return false;
    }
    else {
        return true;
    }
}

//add event to element
function attachEvnt(elm, evType, fn, useCapture) {
    if (elm.addEventListener) {
        elm.addEventListener(evType, fn, useCapture);
        return true;
    }
    if (elm.attachEventListener) {
        elm.attachEventListener(evType, fn, useCapture);
        return true;
    }
    else if (elm.attachEvntListener) {
        elm.attachEvntListener(evType, fn, useCapture);
        return true;
    }
    else if (elm.attachEvent) {
        var r = elm.attachEvent('on' + evType, fn);
        return r;
    }
    else {
        elm['on' + evType] = fn;
    }
}

//video gallery
function fx_loadVideo_next(){
    fx_loadVideo($("#fx_video_next").val());
}

function fx_loadVideo_back(){
    fx_loadVideo($("#fx_video_back").val());
}

function fx_loadVideo(nid){
    if((parseInt(nid)-1 < parseInt($("#fx_video_size").val()))&&(nid != 0)){
        $("#fx_load_area a").css({display: "none"});
        flowplayer("player"+nid, "App_Js/flowplayer-3.2.2.swf");
        $("#player"+nid).css({display: "block"});
        $(".fx_video_p").text(parseInt(nid));
        $("#fx_video_next").val(parseInt(nid)+1);
        $("#fx_video_back").val(parseInt(nid)-1);
    }
}


