var Timerg, TimerGG;
function auth()
{
  $.ajax({
       type: "POST",
       //data: "l="+$("#login").val()+"&p="+$("#pass").val(),
       //url: site_url+"/main/ajax_authorization/",
       data: "urlPar=/main/ajax_authorization/&l="+$("#login").val()+"&p="+$("#pass").val(),
       url : "proxy.php",
       success: function(msg){
         //alert( msg );


	 $("#content").html(msg);
	  
//         var today = new Date();
//         var yr = today.getFullYear()+1;
//         document.cookie="regPhVd=yes; path=/;";
	  //document.location.reload(true);
	  document.location.href="index.html";
       }
     });
     return false;

}
/*get list photo by album id*/
function getPhoto(album, color_cheme)
{
    //$param = "url=/gallery/getPhotoByPortfolio/&album="+album+"&color_cheme="+color_cheme;
//alert(album);
     $.ajax({
       type: "POST",
       data: "urlPar=/main/getPhotoByPortfolio/&album="+album+"&color_cheme="+color_cheme,
       url : "proxy.php",
       //url: site_url+"/gallery/getPhotoByPortfolio/",
       success: function(msg){

           $("#content").html(msg);
           $("#home").removeClass("active");
           $("#conta").removeClass("active");
           $("#galler").removeClass("active");
           $("#port").addClass("active");
           //alert( msg );
       },
       beforeSend: function(){
            $("#content").html('<img src="./img/ajaxLoader.gif"/>').show("slow");
       }
     });
     return false;
}
function getClientGallery()
{

    if(getCookie("regPhVd") != null) {
        var color_scheme = $("#color_scheme").val();
        var serr = $("#userGallery").serialize();
        if(serr.length > 0)
            serr = "&"+serr;
     $.ajax({
       type: "POST",
       data: "urlPar=/gallery/clientGallery/&color_scheme="+color_scheme+serr,
       url : "proxy.php",
//     data: "color_scheme="+color_scheme+serr,
//     url: site_url+"/gallery/clientGallery/",
       success: function(msg){
           $("#content").html(msg);
         //alert( msg );
       },
       beforeSend: function(){
            $("#content").html('<img src="./img/ajaxLoader.gif"/>').show("slow");
       }
     });
    } else {
        alert("You are not authorized. Please login.");
    }
}
function chSort(sort_direction)
{

    if(sort_direction == "asc") {
       sort_direction = "desc";
    } else {
       sort_direction = "asc";
    }
    $("#direction").val(sort_direction);
    getClientGallery();
    return true;
}
function selectAllCli(obj_id)
        {


            $("input[id^='photo_sel_']").each(function (i) {
                if($("#"+obj_id).attr("checked")) {
                    $("#t-select-all").attr("checked","checked");
                    $("#b-select-all").attr("checked","checked");
                    this.checked = true;
                } else {
                    $("#t-select-all").attr("checked","");
                    $("#b-select-all").attr("checked","");
                    this.checked = false;
                }
                    //alert(this.name);
            });
        }



function changeSortData(obj_id) {
    $("#main_sort_hidden").val($("#"+obj_id+" option:selected").val());
    clearTimeout(Timerg);
    Timerg = setTimeout("getClientGallery()", 300);
}
function subGallery()
{
    //alert($("#t-select-all").attr("checked"));
    var is_select = false;
    $("input[id^='photo_sel_']").each(function (i) {
        if(this.checked == true)
            is_select = true;

    });
    if(getCookie("regPhVd") != null && is_select == true) {
        var serr = $("#userGallery").serialize();
        //alert(serr);
     $.ajax({
       type: "POST",
       data: "urlPar=/gallery/clientPlaceOrder/&"+serr,
       url : "proxy.php",

       //data: serr,
       //url: site_url+"/gallery/clientPlaceOrder/",
       success: function(msg){
         //$("#content").html(msg);
         //alert( msg );
         document.location.reload(true);
       }
     });
        
    } else {
        alert("You are not authorized. Please login. Or not selected photo.");
    }
    return false;
}
function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
function logout()
{
   if (getCookie('regPhVd')) {
        document.cookie="regPhVd=yes; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT";
        document.location.reload(true);
   }
}
function getRandIndexPhoto(id)
{
     $.ajax({
           type: "POST",
           data: "urlPar=/gallery/get4PublickPhoto/uid/"+id+"/",
           url : "proxy.php",
           success: function(msg){
             $(".photoes").html(msg);
           }
         });
}
$(document).ready(function(){
    //  проверка что пользователь был авторизироан и скрываем шаблон авторизации
     if(getCookie("regPhVd") != null) {
         $("#form_reg").css("display","none");
         $("#welcom").css("display","block");
         $("#wel_text").text("Welcome "+getCookie("regPhVd"));
     }


   $("li.pages ul li a").live("click", function(event){
       // отлавливаем нажатие ссылки на пагенаторе фотоальбомов. и получаем адресс нажатой ссылки в пагинаторе
       var link = $(this).attr('href');
       event.preventDefault();
       
       //alert(link);
       //return false;
       //  выполняем ajax запрос
       $.ajax({
            type: "POST",
            data: "urlPar=/"+link,
            url : "proxy.php",
   //         url: link,
            success: function(msg){
               // alert(msg);
                $("#content").html(msg);
            },
           beforeSend: function(){
                $("#content").html('<img src="./img/ajaxLoader.gif"/>').show("slow");
           }
       });

    });
});

//открываем диалоговое окно по просмотру фотографии
  $('a.nyroModal').live("click", function(e){
    e.preventDefault();
    $(this).nyroModalManual({bgColor: '#9b9ca0', padding: 0,   zIndexStart: 10000});
    return false;
  });

// отображаем диалоговое окно дря создания коментария
  $('a.edit-comments').live("click", function(e){
    e.preventDefault();
    // $(this) объект, по которому выполнили клик
    $(this).nyroModalManual({bgColor: '#9b9ca0', minWidth: 750, minHeight: 400, padding: 0, zIndexStart: 10000, modal: true});
    return false;
  });
   //$('a.edit-comments').nyroModal({bgColor: '#9b9ca0', minWidth: 750, minHeight: 400, padding: 0});

