﻿/// <reference path="../extjs_intellisense.js" />
var pubcateId=0;
var uin;
if(document.location.href.indexOf("&cateId")>0)
{
    pubcateId=parseInt(document.location.href.split('&cateId=')[1],10);
}
function getPost(myurl){
	$.ajax({
		type: "GET", 
		url: myurl,
		success: function(htmlData){
			$("#posts").html(htmlData);
	    }
	})
}

var globalSpaceWebRoot = ".";

/*
参数: 页索引从1开始
	  pageNoVal, 要切换到的页
	  pageCount: 总页数
	  pageIndex: 当前显示的页索引	  
*/
function pagedPost(pageNoVal, pageCount, pageIndex)
{
	var curPage = 0;
	//如果有#等字符，要进行过滤处理
	var url = document.location.href;
	
    var idx = url.lastIndexOf("#");
    if(idx!=-1){
        url = url.substring(0, idx);
    }

	switch(pageNoVal)
	{
		case -4: curPage = 1; break;	//第一页
		case -3: curPage = Math.floor((pageIndex-1)/9) * 9; break;	//上一个十页
		case -2: curPage = (Math.floor(pageIndex/9)+1)*9+1; break;		//下一个十页
		case -1: curPage = pageCount; break;				//最后一页
		default: curPage = pageNoVal;
	}
	
	if(url.lastIndexOf("&pi=")!=-1){
	    var re = /pi=(\d+)/g;
	    url = url.replace(re, "pi="+curPage);
	}
	else 
	    url = url + "&pi="+curPage;	
    if(pubcateId!=0 && url.indexOf("&cateId")<0)
    {
        url+="&cateId="+pubcateId;
    }
    else
    {
       if(url.indexOf("&cateId")>0)
       {
        var tempcateId=url.split('&cateId=')[1];
        if(parseInt(tempcateId,10) !=pubcateId)
        {
         url=url.split('&cateId=')[0]+"&cateId="+pubcateId;
        }
       }
    }
	document.location.href = url;
}
//小图的的处理
function autoSize(obj,maxw,maxh)
{

// MAX_WIDTH=160;
// MAX_HEIGHT=120;
// IMG_MARGIN=4;
// if(maxh){MAX_HEIGHT=maxh}
// if(maxw){MAX_WIDTH=maxw}
// var tImg=new Image();
// tImg.onload=function(){
// var w=this.width;
// var h=this.height;
// if(w<MAX_WIDTH && h<MAX_HEIGHT){
// obj.width=w;
// obj.height=h;
// //obj.style.marginLeft=IMG_MARGIN+(MAX_WIDTH-w)/2+'px';
// //obj.style.marginTop=IMG_MARGIN+(MAX_HEIGHT-h)/2+'px'; 
// }
// else
// {
// if(w>h) {
// obj.width=MAX_WIDTH;obj.height=MAX_WIDTH*h/w;
// }
// else{
// obj.height=MAX_HEIGHT;obj.width=MAX_HEIGHT*w/h;
// }
// }
// }
//tImg.src=obj.src;
}
function changeCategory(uin, cateId){
    pubcateId=cateId;
    //alert(pubcateId);
    if (globalSpaceWebRoot == "." && $("#globalSpaceWebRoot")) {
        globalSpaceWebRoot = $("#globalSpaceWebRoot").val();
    }
    AjaxBegin();
	$.ajax({
		type: "get",		
		url: "/"+globalSpaceWebRoot+"/album.aspx?uin="+uin+"&action=changeCate&cateId="+cateId,
		success: function(htmlData){
		    AjaxEnd();
		    //alert(htmlData);
			$("#posts").html(htmlData); 
			if($("#hidtotalCount").length>0 && $("#pwd").length==0){
                var html = paging($("#hidtotalCount").val(), 1, "jsPageFull", 0);
                $("#jsFull").html(html);
            }
            else {
                $("#jsFull").html("");
                $("#pager").hide();
            }           
		}
	})
}
function showAlbum() {    
        AjaxBegin();
        if (globalSpaceWebRoot == "." && $("#globalSpaceWebRoot")) {
            globalSpaceWebRoot = $("#globalSpaceWebRoot").val();
        }
	    $.ajax({
		    type: "post",		
		    url: "/"+globalSpaceWebRoot+"/album.aspx?uin="+uin+"&action=confrim&cateId="+pubcateId,
		    data:"pwd="+$("#pwd").val(),
		    success: function(htmlData){
		        AjaxEnd();
			    $("#posts").html(htmlData); 
			    if($("#hidtotalCount").length>0){
                    var html = paging($("#hidtotalCount").val(), 1, "jsPageFull", 0);
                    $("#jsFull").html(html);
                }
                else {
                    $("#jsFull").html("");
                    $("#pager").hide();
                }
                
		    }
	    })
}
function imagesload(obj,widthpx,heightpx)
{
if ( obj.width > widthpx || obj.height > heightpx ) 
     { 
          if ( obj.width > obj.height) 
                  { 
            obj.height = obj.height*(widthpx/obj.width); 
            obj.width = widthpx; 
          } else 
                  { 
            obj.width = obj.width*(heightpx/obj.height); 
            obj.height = heightpx; 
          } 
        } 

}
//相片的效果
//幻灯片播放
function getHost(){
 return "http://"+window.location.host;
}
function powerpoint(myalbum){
    //alert(uin);
    //var boxAlert = jBox.iframe(getHost()+"/powerpointalbum.html?albumid="+myalbum+"&uin="+uin,"幻灯片播放相片",880,780,0,0);
    window.open(getHost()+"/gallery.html?albumid="+myalbum+"&uin="+uin);

}
this.imagePreview = function(){
	xOffset = 10;
	yOffset = 30;
	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		var mainsrc=this.childNodes[0].src.replace("small","main");
		$("body").append("<p id='preview'><img src='"+ mainsrc +"' onload='autoSize(this,350,300)' alt='相片预览' />"+ c +"</p>");								 
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};
//翻页
function jsPageFull(pageNo){  
        if (globalSpaceWebRoot == "." && $("#globalSpaceWebRoot")) {
            globalSpaceWebRoot = $("#globalSpaceWebRoot").val();
        }      
        var url = "/"+globalSpaceWebRoot+"/album.aspx?uin="+uin+"&action=paging&pi="+pageNo+"&cateId="+pubcateId;
        var param = {};
        var arr=$.ajax({            
            "type": "POST",
            "url": url,
            async: false,
            "data": param            
            }).responseText;
        $("#posts").html(arr); 
        var html = paging($("#hidtotalCount").val(), pageNo, "jsPageFull", 0);
        $("#jsFull").html(html);
        
}
$(document).ready(function() {
    var url = document.location.href;
    var urls = url.split('/');
    uin = urls[3];
    if ($("#hidtotalCount").length > 0 && parseInt($("#hidtotalCount").val(), 10) > 0) {
        var firstpaging = paging($("#hidtotalCount").val(), 1, "jsPageFull", 0);
        $("#jsFull").html(firstpaging);
    }
    if ($("#pwd").length > 0) {
        $("#pager").hide();
    }
    //隐藏播放
    $(".albumList").find('.tar').hide();
    //imagePreview();
});