    // JavaScript Document
// jquery ;
//cookies
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { 
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); 
        }
 
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                 if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
//cookies end
var  c_ar;
var  cf_ar=new Object();
var check_arr=new Object();
cf_ar.func=Array('3d','code','info');
cf_ar.but=Array();
cf_ar.tab=Array();
var host_id_div='1';

$(document).ready(function()
{
//profile wlpeUserProfileForm
$('#wlpeUserProfileForm').submit(function() {

var str=$(this).serializeArray();
$(this).load("http://3d-bank.com/index.php?id=115", str  );
return false;
});
 
$("#ContactForm").submit(function() { 
var str=$(this).serializeArray();
$(this).load("http://3d-bank.com/index.php?id=108", str  );//  { 'choices[]': ["Jon", "Susan"] }
return false;
});
var regStat=0;
$("#wlpeUserRegisterForm").submit(function() { 
if(regStat) return true;
var frm=$(this);
var str=$(this).serializeArray();
$('#wlpemsgreg').html('<img src="http://3d-bank.com/tpl_img/preloader.gif" > запрос...');

$('#wlpemsgreg').load("http://3d-bank.com/index.php?id=111", str , function(response, status, xhr) {
      if (status == "error") {
       $('#wlpemsgreg').html= "Не удалось подключится к серверу ";
       // $("#error").html(msg + xhr.status + " " + xhr.statusText);
     }
      if(response=='готово') {regStat=1; frm.submit(); }
      
   }); // 

return false;
}); 
//host_id_div

if($('#host_id_div').length && $('#host_id_div').html()!='') host_id_div=$('#host_id_div').html(); 
//catalog
if(( window.location.hash=='#bank_id' || ( window.location.search.search(/tag/) != -1)  || ( window.location.pathname.search(/tag/) != -1) ) && $('#hor_slide_id_hide').length==1 ) { $('#hor_slide_id').html($('#hor_slide_id_hide').html()); }

if(window.location.hash=='#bank_id' && $('#hor_slide_id_hide').length==1) { $('#hor_slide_id').html($('#hor_slide_id_hide').html()); }
if($('#hor_slide_id_hide').length==1)
$('#bank_id_div').click( function() {

window.location.hash='#bank_id';
 $('#hor_slide_id').html($('#hor_slide_id_hide').html());
//$.get('http://3d-bank.com/serv/tag_ajax', function(data) {
  
//});

    
   return false;
    }
);
// #open_win авторизация
zzz=500;
window_block=$('div.window_block');
//window_block.click(function(){to_front( window_block, $(this), zzz) ; });
window_block.each(function(){
$(this).find('a.close_window').click(function() {

 $(this).parents('div.window_block').hide();
 return false;
    })
}); 

$('a.open_win').click(function(){ 

cw=$(this).next(); //.css('z-index'
to_front( window_block, cw, zzz);
cw.fadeIn(100);
 return false;


    });
    

 
// #top

$('#footer_up > a').click(function(){
    $('html,body').animate({scrollTop: 0 },1000); return false;
    });
//$.cookie("check_arr",null); split
var tt=$.cookie("check_arr");
//  $('#admin_output').html(tt);

//check_arr=$.cookie("check_arr");
//c_ar=[$('#viget_3d_ID'),$('#viget_code_ID'),$('#viget_info_ID')];
for (var i=0;i < cf_ar.func.length; i++) {
 
   //панели виджета  
    cf_ar.tab[i]=$('#viget_'+cf_ar.func[i]+'_ID');
    
  //кнопки урпавления на виджете   
    cf_ar.but[i]=$('.vidget_but_'+cf_ar.func[i]);
    cf_ar.but[i].attr('alt',i);
   
    cf_ar.but[i].click(function() {
       
         vidget_block_view($(this).attr('alt'));
       });
    
    }
    
// управление на карточках моделей
$('div.obj_card > div > div').each(function() {
    var temp_root=$(this).parent().parent();
    //отметка 
    temp_root.hover(
      function () {
        $(this).addClass('obj_card_over');
        
      }, 
      function () {
        $(this).removeClass( 'obj_card_over' );
      }
      ).click(function() {
       // show_3d_vidget();
          vidjet_block($(this));
        
        }
           
      
      );
$(this).children('div.obj_but_3d,div.obj_but_code, div.obj_but_info, a.obj_but_edit').each(function() {
  //по наведению
     $(this).hover(function(event) {
       // show_3d_vidget();
     event.stopPropagation();
       
        
        },function(event) {
       // show_3d_vidget();
     event.stopPropagation();
       
        
        }
        ).click(function(event) {
     //по нажатию  
       // show_3d_vidget();
      
       event.stopPropagation();
       if(!$(this).hasClass( 'obj_but_edit' )) vidjet_block($(this));
       
              
       }); 

    });
    
   // отметка
   // obj_but_insert_off 
  $(this).children('div.obj_but_insert').click(function(event) {
   event.stopPropagation();
   if( $(this).hasClass('obj_but_insert_off')) {
    //   obj_card_select 
       temp_root.removeClass('obj_card_select');
       
        $(this).removeClass( 'obj_but_insert_off' );
         check_arr[temp_root.attr('o_id')]=0;
        
        }
      else { 
      //alert("dddd");
         temp_root.addClass('obj_card_select');
    
       $(this).addClass('obj_but_insert_off');
       check_arr[temp_root.attr('o_id')]=1;
       }
     

  
  });
  
  // hide
  //obj_but_show 
    $(this).children('div.obj_but_hide').click(function(event) {
   event.stopPropagation();
   if( $(this).hasClass('obj_but_show')) {
    //   obj_card_select 
   // obj_card_hidden 
        temp_root.next().hide();
        temp_root.show(100);
                       
      //  $(this).removeClass( 'obj_but_show' );
        }
      else { 
      //alert("dddd");
       temp_root.hide(100);
       temp_root.next().show();
       temp_root.removeClass('obj_card_hidden');
  //     $(this).addClass('obj_but_show');
       }
  
  });  
  //show
      temp_root.next().children('div.obj_but_show').click(function(event) {
       event.stopPropagation();
       temp_root.next().hide();
       temp_root.show(200);
        
  
  });  
  

});




})
// to front
function to_front(collect, front, zz) {
collect.each(function() { if($(this)!=front) 
$(this).hide(); });
//zzz++;
// для переключеня между окошками    front.css('z-index',zzz.toString());

}
$(window).unload(function() {
 var arr= [ 5, 17, 1777 ];
     $.cookie("check_arr", arr.join(','));
});

function a_show_href() {
//alert(check_arr);
    var hr='http://3d-bank.com/home?m_id=';
    for(var ia in check_arr) {
        if(check_arr[ia]) hr=hr+ia+',';
        }
   hr= hr.substr(0,(hr.length-1) );
   $('#admin_output').html(hr);
   var arr= [ 5, 17, 1777 ];

  //  $('#admin_output').html(arr.join(','));
///admin_output
}
function vidjet_block(cmodel) {
var func=0;
var model;
if(cmodel.hasClass('obj_card'))  model=cmodel; 
    else { if(cmodel.hasClass('obj_but_code'))func=1; else if(cmodel.hasClass('obj_but_info')) {  func=2; }

     model=cmodel.parent().parent().parent(); 
     }

var vg=$('#shader_light');
var vgi=$('#viget_3d_ID');
//var vdd=$('#o_id_media'); model.attr('u_id')
var m_u= '1_'+ model.attr('o_id'); // ; 
//alert(host_id);
  //alert('Handler  called.'+model.attr('title')+' - '+ model.attr('o_id'));
 var vdd=$('#o_id_media_cod');   
vgi.html('<object width="640" height="480" id="o_id_media_cod'+m_u+'"  classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" >'+
'<param name="movie" value="http://media.3d-bank.com/swf/viewer.swf?media=1_' + model.attr('o_id')+ '&startb=1'+model.attr('o_pr')+'">'+'</param>'+
'<param name="allowscriptaccess" value="always">'+
'</param>'+
'<embed src="http://media.3d-bank.com/swf/viewer.swf?media=1_' +model.attr('o_id')+ '&startb=1'+model.attr('o_pr')+'" type ="application/x-shockwave-flash" '+'allowscriptaccess="always" width="640" height="480">'+
'</embed></object>');


 m_u= host_id_div+'_' + model.attr('o_id');
 //host_id+ alert(m_u);
 $('#viget_info_ID >div> div.insert_div').html( model.attr('o_title')+'<br />'+
 model.children('div.introtext').html());
 /*if(host_id_div != 1)
 {*/
$('#viget_code_ID>div> div.insert_div_mode').html('<input type="radio" checked="checked" onclick="show_code_block(0);" name="btn_code" id="btn_code0" /><label for="btn_code0" onclick="show_code_block(0);">Вставка объекта</label>&nbsp;&nbsp;&nbsp;<input type="radio" onclick="show_code_block(1);" name="btn_code" id="btn_code1" /><label for="btn_code1" onclick="show_code_block(1);">Вставка кнопки</label>&nbsp;&nbsp;&nbsp;<input type="radio" onclick="show_code_block(2);" name="btn_code" id="btn_code2" /><label for="btn_code2" onclick="show_code_block(2);">Плейсхолдер</label>');
 var ins_txt = $('#viget_code_ID>div> div.insert_div_copy').html().replace(/js_media/g, m_u);
$('#viget_code_ID>div> div.insert_div').html(ins_txt);
/*} else {
$('#viget_code_ID>div> div.insert_div').html('<textarea  rows=8 cols="70">'+
'<object width="640" height="480" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="m'+m_u+'" >'+
     '<param name="movie" value="http://media.3d-bank.com/swf/viewer.swf?media='+ m_u +'">'+
     '</param>'+
     '<param name="allowscriptaccess" value="always">'+
     '</param>'+
      '<embed src="http://media.3d-bank.com/swf/viewer.swf?media='+ m_u+'" type="application/x-shockwave-flash" allowscriptaccess="always" width="640" height="480">'+
      '</embed>'+
      '</object>'+
      '</textarea>'   );
}*/
vg.show();
//vgi.show(2000);
vidget_block_view(func);
//$('.target').hide();

}
function vidget_block_view(func) {
//global c_ar;

for (var i=0;i < cf_ar.tab.length; i++) {
 //   alert(c_ar.length);
    if(i != func) 
        cf_ar.tab[i].hide()
        else 
        cf_ar.tab[i].show();
    
    }
var mp=-240+26*func;

//$('#v_connect_indikator').css('marginTop',mp+'px');
$('#v_connect_indikator').animate({marginTop:mp},300);


}
// end jquery


function hide_obj(obj_hide,obj_hidden) {
    document.getElementById(obj_hide).style.display ='none';
    document.getElementById(obj_hidden).style.display ='block';
    return false;
}
function show_obj(obj_hide,obj_hidden) {
    document.getElementById(obj_hide).style.display ='block';
    document.getElementById(obj_hidden).style.display ='none';
    return false;
}
function close_vidget() {
$('#shader_light').hide();
//   document.getElementById('shader_light').style.display='none';
    
//    viget_code_ID
}
function show_3d_vidget() {
    hide_div(to_hide);
    document.getElementById('v_connect_indikator').style.marginTop = '-240px';
    document.getElementById('viget_code_ID').style.display='none';
    document.getElementById('viget_info_ID').style.display='none';
    document.getElementById('shader_light').style.display='block';
    document.getElementById('viget_3d_ID').style.display='block';
};
function show_code_vidget() {
    hide_div(to_hide);
    document.getElementById('v_connect_indikator').style.marginTop = '-214px';
    document.getElementById('viget_3d_ID').style.display='none';
    document.getElementById('viget_info_ID').style.display='none';
    document.getElementById('shader_light').style.display='block';
    document.getElementById('viget_code_ID').style.display='block';
};
function show_info_vidget() {
    hide_div(to_hide);
    document.getElementById('v_connect_indikator').style.marginTop = '-188px';
    document.getElementById('viget_code_ID').style.display='none';
    document.getElementById('viget_3d_ID').style.display='none';
    document.getElementById('shader_light').style.display='block';
    document.getElementById('viget_info_ID').style.display='block';
};

function show_code_block(id)
{
   $('#viget_code_ID>div> div.insert_div>div.ins_code').attr('style', 'display:none;');
    document.getElementById('code_'+id).style.display='block';
    
}

function priv_pub_obj(obj_id) {
   var obj_text = $('#btn_'+obj_id).text();
   var obj_data;
   if(obj_text == ' [p] ') obj_data = 1; else obj_data = 0;
   $.get('http://3d-bank.com/serv/model_action', {'id': obj_id, 'action': 'public', 'data': obj_data}, function(response){
    if(response == 'fail'){
        return false;
    } else {
        var btn_text;
        var btn_title;
        if(obj_data == 0) 
        {
            btn_text = ' [p] '; 
            btn_title = 'Скрыть'
        } else {
            btn_text = ' [h] ';
            btn_title = 'Опубликовать';
        }
        $('#btn_'+obj_id).text(btn_text);
        $('#btn_'+obj_id).attr('title', btn_title);
       // alert('Статус объекта изменен'); 
        return true;
    }
   });
};
function getMoreTags(page, tags){
    if(typeof(tags) == 'undefined')
    {
        $.get('http://3d-bank.com/index.php', {'p': page, 'k': '1', id: '132'}, function(response){
             $('#hor_slide_id').html(response);
        });
    } else {
        $.get('http://3d-bank.com/index.php', {'p': page, 'k': '1', id: '132', 'tag': tags}, function(response){
             $('#hor_slide_id').html(response);
        });
    }
};

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
};
