/*
 * Image preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Aaron (http://icpark.com)
 * 
 *
 */
 
var t = n = 0, count = $("#play_list a").size();

this.slidedivicomment = function(){	
	//$("#divicomment > div.slidecontent").hide();			
	$("#divicomment > div:first > p:last").click(function() {
	//$("#divicomment > div.slidecontent").slideToggle("fast");
	$(this).parent().next("div").slideToggle("fast");
	$(this).toggleClass("slideactive"); 
	$(this).toggleClass("slideactive2");  
	});
};

this.slidedivfootmark = function(){	
	//$("#divfootmark > div.slidecontent").hide();			
	$("#divfootmark > div:first > p:last").click(function() {
	//$("#divicomment > div.slidecontent").slideToggle("fast");
	$(this).parent().next("div").slideToggle("fast");
	$(this).toggleClass("slideactive"); 
	$(this).toggleClass("slideactive2");  
	});
};

this.slidedivFriend = function(){	
	//$("#divFriend > div.slidecontent").hide();			
	$("#divFriend > div:first > p:last").click(function() {
	//$("#divicomment > div.slidecontent").slideToggle("fast");
	$(this).parent().next("div").slideToggle("fast");
	$(this).toggleClass("slideactive"); 
	$(this).toggleClass("slideactive2");  
	});
};

 
this.imagePreview = function(){	
	xOffset = 10;
	yOffset = 30;
		
	$("a.preview3").hover(function(e){
		var fsrc = $(this).attr("ref");//default face img
		
	var fdir = fsrc.substring(0,fsrc.lastIndexOf("/")+1);
	//alert(fdir);


	var b=fsrc.split("/"); 
	var c=b.slice(b.length-1, b.length).toString(String).split("."); 
	var fname = c.slice(0,1);


	var fext = fsrc.substring(fsrc.lastIndexOf('.') + 1);
	//alert(fext);

	var fsrclage = fdir + fname + "_b." + fext;
	//alert(fsrclage);

		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='preview'><img src='"+ fsrclage +"' alt='" + this.ref + "' />"+ 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.preview3").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

this.groupfuncbarhover = function(){
		$("#ulcpgroup li").hover(function(){
			if ($(this).find('p.groupfuncbar > a:first').is(":visible"))
				{	//$(this).addClass("bgbluethin");
					$(this).find('p.groupfuncbar').show();
				}
		},
       	function(){
			if ($(this).find('p.groupfuncbar > a:first').is(":visible"))
			{
				//$(this).removeClass("bgbluethin");
				$(this).find('p.groupfuncbar').hide();
			}
		});
	

	$("#ulmpgroup li").hover(function(){
		if ($(this).find('p.groupfuncbar > a:first').is(":visible"))
		{
			$(this).find('p.groupfuncbar').show();
		}
	},
       	function(){
		if ($(this).find('p.groupfuncbar > a:first').is(":visible"))
		{
			$(this).find('p.groupfuncbar').hide();
		}	
	});

	
	$("#uljpgroup li").hover(function(){
		if ($(this).find('p.groupfuncbar > a:first').is(":visible"))
		{
			$(this).find('p.groupfuncbar').show();
		}
	},
       	function(){
		if ($(this).find('p.groupfuncbar > a:first').is(":visible"))
		{
			$(this).find('p.groupfuncbar').hide();
		}	
	});

	$("#ulcfgroup li").hover(function(){
		if ($(this).find('p.groupfuncbar > a:first').is(":visible"))
		{
			$(this).find('p.groupfuncbar').show();
		}
	},
       	function(){
		if ($(this).find('p.groupfuncbar > a:first').is(":visible"))
		{
			$(this).find('p.groupfuncbar').hide();
		}	
	});

	$("#ulmfgroup li").hover(function(){
		if ($(this).find('p.groupfuncbar > a:first').is(":visible"))
		{
			$(this).find('p.groupfuncbar').show();
		}
	},
       	function(){
		if ($(this).find('p.groupfuncbar > a:first').is(":visible"))
		{
			$(this).find('p.groupfuncbar').hide();
		}	
	});

	$("#uljfgroup li").hover(function(){
		if ($(this).find('p.groupfuncbar > a:first').is(":visible"))
		{
			$(this).find('p.groupfuncbar').show();
		}
	},
       	function(){
		if ($(this).find('p.groupfuncbar > a:first').is(":visible"))
		{
			$(this).find('p.groupfuncbar').hide();
		}
	});
};

this.pageinit = function(){
	$("#opens li:odd").addClass("bggraythin");
	//$("#opens li:odd").css("border","#ddd 1px solid");
};

this.imgplay = function(){
	 var len  = $("#idNum > li").length;
	 var index = 0;
	 $("#idNum li").mouseover(function(){
		index  =   $("#idNum li").index(this);
		showImg(index);
	});	

	 $('#idTransformView').hover(function(){
			  if(MyTime){
				 clearInterval(MyTime);
			  }
	 },function(){
			  MyTime = setInterval(function(){
			    showImg(index)
				index++;
				if(index==len){index=0;}
			  } , 6000);
	 });

	 var MyTime = setInterval(function(){
		showImg(index)
		index++;
		if(index==len){index=0;}
	 } , 6000);
};

function showImg(i){
		$("#idSlider").stop(true,false).animate({top : -210*i},600);
		 $("#idNum li")
			.eq(i).addClass("on")
			.siblings().removeClass("on");
}

// starting the script on page load
$(document).ready(function(){
	pageinit();
	imgplay();
	//slidedivicomment();
	//slidedivfootmark();
	//slidedivFriend();
	imagePreview();
	//groupfuncbarhover();	//conflict the asp.net ajax.
});