function setVideo (id) {
    var flashPlayer = document.getElementById("player");
    flashPlayer.setVideoData(id);
}
(function($) {
var uid = 0;
$.getUID = function() {
    uid++;
    return 'jQ-uid-'+uid;
};
$.fn.getUID = function() {
    if(!this.length) {
        return 0;
    }
    var fst = this.first(), id = fst.attr('id');
    if(!id) {
        id = $.getUID();
        fst.attr('id', id);
    }
    return id;
};
$.fn.autoscroll = function() {
jQuery('html,body').animate(
{
scrollLeft: this.offset().left,
scrollTop: this.offset().top
},
500
);
return this;
};
})(jQuery);

window.EasyBuildUrl=function()
{
    var args = arguments;
    var line_str="";
    $.each (args,function(k,v)
    {
        line_str+=v+"/";
    })
    return '/'+(options.lang ? options.lang+'/' : '')+line_str;
}

function tt1xr(itm, cacher)
{
    var t=setTimeout(function()
    {
        $(itm).val(cacher);
        $(itm).removeAttr('disabled');
        clearTimeout(t);

    },3000)  
}

$(document).ready(function()
{
    
    
$('input[type=submit]').click(function()
{
    var cacher=$(this).val();
    tt1xr(this, cacher);

    if (cacher.length>0)
    {
        $(this).val($._('sending_data'));
    }
    
//    $(this).click();
    
    
    var st=setTimeout(function()
    {
        $(this).attr('disabled','disabled');
        clearTimeout(st);

    },300);  
    
});


 
              var newScript = document.createElement("script");
                newScript.type = 'text/javascript';       
                newScript.src = options.static_url+'/lib/orpus/'+options.lang+'.js';             
                document.body.appendChild(newScript); 
 
 $("div").first().append('<div style="display: none;visibility:hidden;"><a href="http://orphus.ru" id="orphus" target="_blank"> <img alt="Система Orphus" src="'+options.static_url+'/images/orphus_ru.gif" border="0" width="125" height="115" /> </a></div>');

php.beforeSend = function (){
//console.log(        $('link[rel="shortcut icon"]')   );
//    $('link[rel="shortcut icon"]').attr('href','/favicon.gif');
    $('#loading').slideDown('fast');
};
php.complete = function (){
    $('#loading').slideUp('slow');
};

php.on_success = function (a,b,c,d){
    php.success(a,b,c,d);
    php.complete(a,b,c,d);
    $('#loading').slideUp('slow');
};


$.ajaxSetup({
           beforeSend: function(){
               return php.beforeSend();
           },
           // Handle the success event
           success: function(data, textStatus){
               return php.success(data, textStatus);
           },
           // Handle the error event
           error: function (xmlEr, typeEr, except) {
               return php.error(xmlEr, typeEr, except);
           },
           // Handle the complete event
           complete: function (XMLHttpRequest, textStatus) {
               return php.complete(XMLHttpRequest, textStatus);
           }

 });


//$(".tabs_list").tabs({
//    ajaxOptions: 
//    {
//        error: function(xhr, status, index, anchor) {
//            $(anchor.hash).html("Cannot load.");
//        }
//    }
//});
//$("#tabs").tabs({
//    ajaxOptions: 
//    {
//        error: function(xhr, status, index, anchor) {
//            $(anchor.hash).html("Cannot load.");
//        }
//    }
//}).tabs("rotate", 5000, true);





    $("#tabs").tabs({ fx: { } }).tabs('rotate', 5000);
    $('#tabs').mouseover(function(){
            $(this).tabs('rotate', 0, false);
        },function(){
            $(this).tabs({ fx: { } }).tabs('rotate', 5000); 
        }
    );
    
$("#tabs").mouseout(function(){
    $(this).tabs({ fx: { } }).tabs('rotate', 5000); 
});




$("#top_menu .parent").mouseover(function(){
	$(this).addClass('active');
	$(this).children('.level_1').addClass('item1-active');
});

$("#top_menu .parent").mouseout(function(){
	$(this).removeClass('active');
	$(this).children('.level_1').removeClass('item1-active');
});


$("#search input[name=q]").focus(function()
{
    $(this).val('');
})

$(".header_auth input[name=data\\[login\\]]").focus(function()
{
    $(this).val('');
})

if ($(document).width()>1024)
{
    $(document).UItoTop({ easingType: 'easeOutQuart',text: '' , containerID: 'toTop_'+options.lang});
}

if($.browser.msie && $.browser.version=="6.0") 
{
    jQuery.fx.off = true;
}


$(".header_auth").submit(function()
{
        $.php(profile_top_login_url,$(this).formToArray(true));
        return false;
});
$(".header_auth_submit").click(function()
{
    if ($(".header_auth input[name=data\\[login\\]]").val() &&  
    $(".header_auth input[name=data\\[pass\\]]").val())
    {
        $(".header_auth").submit();
        return false;
    }
    else
    {
        return true;
    }
});


$('.auth_form').live('submit', function() {
    $.php(profile_login_url,$(this).formToArray(true));
    return false;
});

//$("#quick_auth").dialog({
//    autoOpen: false,
//    title: $._('auth_required'),
//    width: 550,
//    modal: true,
//    close: function() {
//    }
//});



        

 if (typeof(VK) !== 'undefined' )
 {
     if (!options.user_id)
     {

         VK.Observer.subscribe('auth.login', function(response) {
             $.php(profile_login_vk_url,{ajax_remote_auth: true});
        });
        
      FB.Event.subscribe('auth.sessionChange', function(response) {
        $.php(profile_login_fb_url,{ajax_remote_auth: true});
      });
     }




 if ($("#vk_login").length)
{
    VK.UI.button('vk_login');
}
if ($("#vk_overall_login").length)
{
    VK.UI.button('vk_overall_login');
}  

window.VkLogin=function() {

VK.init({
  apiId: vk_auth_app_id,
  nameTransportPath: "/xd_receiver.htm"
});

    VK.Auth.login(
    null,
    VK.access.WIKI
    );
//var timeoutId = setTimeout(function()
//{
//    VK.Auth.login(
//    null,
//    VK.access.WIKI
//    );
//    clearTimeout(timeoutId)
//}, 5000)


}



window.FBLogin=function() {
FB.init({appId: fb_auth_app_id, status: false, cookie: true, xfbml: true});   


FB.login(function(response) {
  if (response.session) {
    // user successfully logged in
  } else {
    // user cancelled login
  }
});

}








}

window.ReAttachPrettyPhoto=function()
{
//    $("a[rel^='prettyPhoto']").detach();
$('.pp_overlay').remove();
$('.pp_pic_holder').remove();
    $("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook',modal: true});
}
 if (typeof($.prettyPhoto) !== 'undefined' )
 {

            ReAttachPrettyPhoto();
            


 }


 $(".set_video").click(function()
 {
     var id=$(this).attr('rel');
     set_video(id);
 });
 

window.DoRedirect=function(its)
{

        document.location=$(its).attr('href');
 

}

//$(".exit").click(function()
//{

//VK.Auth.logout(
//$(this).attr('href')
//);  
//})
}); // end ready

var ErrorHandler = function(msg, url, line) {
alert(msg+': '+url+': '+line);
};
//window.onerror = ErrorHandler;


window.auth_required=function() {
    $.prettyPhoto.open('#quick_auth');
//$("#quick_auth").dialog('open'); 

}

window.set_video=function(id) {
    var flashPlayer = document.getElementById("player");
    if (!flashPlayer) return false;
    flashPlayer.setVideoData(id);  
}

$(window).load(function(){
       $(".centered img").imgCenter({
            parentSteps: 1,
            scaleToFit:false
       });
    });

