$(document).ready(function(){
	
	$('.video-item a').livequery('mouseover',function(event){
		prog = $(this).attr("prog");
		$("#item-img-"+prog).animate({opacity: 1}, 200 );
	});
	
	$('.video-item a').livequery('mouseout',function(event){
		prog = $(this).attr("prog");
		$("#item-img-"+prog).animate({opacity: 0.5}, 200 );
	});
	
	$('#comment_submit').livequery('click',function(event){
		comment_submit();
	});	
	
	
	$("#player-blanket").click(function(){
		/*
		$(this).animate({opacity: 0}, 300, function(){
			$(this).css('display','none');
			player.sendEvent("PLAY","true");
		});
		*/
		$(this).slideUp(300, function(){
			$(this).css('display','none');
			player.sendEvent("PLAY","true");
		});
	});
	
	pagemem1 = $('#listing').html();
	$('#pagemem1').html(pagemem1);	
	
	$('#scroll-meta').jScrollPane({
		scrollbarWidth:12,
		wheelSpeed:50
	});
	
})





var player = null;
function playerReady(thePlayer) {
	player = document.getElementById('mp1');
	addListeners();
}

function addListeners() {
	if (player) { 
		player.addModelListener("TIME", "stateListener");
		player.addModelListener("STATE", "stateListener2");
	} else {
		setTimeout("addListeners()",100);
	}
}

function stateListener(obj) {
	//videoPos = obj.position;
	videoPos = obj.position;
	//if(videoPos == 0 || videoPos == 1 || videoPos == 2){ ads_pause_video() }


}

function stateListener2(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	currentState = obj.newstate;

}



function page_next(a){

	$("#listing_slide_buffer_container").css('display','block');
	$("#listing_slide_buffer").css('display','block');
	$("#listing_slide_buffer2").css('display','block');

	ori = $("#listing").html();

	ori_arr = ori.split('<div class="invi">anchor-1</div>');

	ori_first	= ori_arr[0];
	ori_second	= ori_arr[1];
	ori_third	= ori_arr[2];

	page_listing_from_cookie = $('#pagemem'+a).html();
	
	if(page_listing_from_cookie){
	
		msg = page_listing_from_cookie;
	
		msg_arr = msg.split('<div class="invi">anchor-1</div>');
	
		msg_first	= msg_arr[0];
		msg_second	= msg_arr[1];
		msg_third	= msg_arr[2];
	
		$("#listing").html(msg_first+'<div class="invi">anchor-1</div>'+ori_second+'<div class="invi">anchor-1</div>'+msg_third);
	
		$("#listing_slide_buffer").html(msg_second);
	
		$("#listing_slide_buffer2").html(ori_second);
	
		$("#listing_slide_buffer2").animate({marginLeft:-677,}, 500);

		$("#listing_slide_buffer").animate({marginLeft:0,}, 500, function(){
		
			$("#listing").html(msg);
			$("#listing_slide_buffer").html('');
			$("#listing_slide_buffer").css('margin-left',677);
		
			$("#listing_slide_buffer2").html('');
			$("#listing_slide_buffer2").css('margin-left',0);
		
			$("#listing_slide_buffer_container").css('display','none');
			$("#listing_slide_buffer").css('display','none');
			$("#listing_slide_buffer2").css('display','none');
		
		});
	
	}else{
	
		$.ajax({
			type: "GET",
			url: '/a/listing_page/'+a,
			success: function(msg){

				msg_arr = msg.split('<div class="invi">anchor-1</div>');
			
				msg_first	= msg_arr[0];
				msg_second	= msg_arr[1];
				msg_third	= msg_arr[2];
			
				$("#listing").html(msg_first+'<div class="invi">anchor-1</div>'+ori_second+'<div class="invi">anchor-1</div>'+msg_third);
			
				$("#listing_slide_buffer").html(msg_second);
			
				$("#listing_slide_buffer2").html(ori_second);
			
				$("#listing_slide_buffer2").animate({marginLeft:-677,}, 500);
		
				$("#listing_slide_buffer").animate({marginLeft:0,}, 500, function(){
				
					$("#listing").html(msg);
					$("#listing_slide_buffer").html('');
					$("#listing_slide_buffer").css('margin-left',677);
				
					$("#listing_slide_buffer2").html('');
					$("#listing_slide_buffer2").css('margin-left',0);
				
					$("#listing_slide_buffer_container").css('display','none');
					$("#listing_slide_buffer").css('display','none');
					$("#listing_slide_buffer2").css('display','none');
				
				});
				
				$('#pagemem'+a).html(msg);
				
			}
		});
	
	}

}


function page_prev(a){

	$("#listing_slide_buffer_container").css('display','block');
	$("#listing_slide_buffer").css('display','block');
	$("#listing_slide_buffer2").css('display','block');

	ori = $("#listing").html();

	ori_arr = ori.split('<div class="invi">anchor-1</div>');

	ori_first	= ori_arr[0];
	ori_second	= ori_arr[1];
	ori_third	= ori_arr[2];

	page_listing_from_cookie = $('#pagemem'+a).html();
	
	if(page_listing_from_cookie){
	
		msg = page_listing_from_cookie;
	
		msg_arr = msg.split('<div class="invi">anchor-1</div>');
			
		msg_first	= msg_arr[0];
		msg_second	= msg_arr[1];
		msg_third	= msg_arr[2];
	
		$("#listing_slide_buffer").css('margin-left',-677);
	
		$("#listing").html(msg_first+'<div class="invi">anchor-1</div>'+ori_second+'<div class="invi">anchor-1</div>'+msg_third);
	
		$("#listing_slide_buffer").html(msg_second);
	
		$("#listing_slide_buffer2").html(ori_second);
	
		$("#listing_slide_buffer2").animate({marginLeft:677,}, 500);

		$("#listing_slide_buffer").animate({marginLeft:0,}, 500, function(){
		
			$("#listing").html(msg);
			$("#listing_slide_buffer").html('');
			$("#listing_slide_buffer").css('margin-left',677);
		
			$("#listing_slide_buffer2").html('');
			$("#listing_slide_buffer2").css('margin-left',0);
		
			$("#listing_slide_buffer_container").css('display','none');
			$("#listing_slide_buffer").css('display','none');
			$("#listing_slide_buffer2").css('display','none');			
		
		});
	
	}else{
	
		$.ajax({
			type: "GET",
			url: '/a/listing_page/'+a,
			success: function(msg){

				msg_arr = msg.split('<div class="invi">anchor-1</div>');
			
				msg_first	= msg_arr[0];
				msg_second	= msg_arr[1];
				msg_third	= msg_arr[2];
			
				$("#listing_slide_buffer").css('margin-left',-677);
			
				$("#listing").html(msg_first+'<div class="invi">anchor-1</div>'+ori_second+'<div class="invi">anchor-1</div>'+msg_third);
			
				$("#listing_slide_buffer").html(msg_second);
			
				$("#listing_slide_buffer2").html(ori_second);
			
				$("#listing_slide_buffer2").animate({marginLeft:677,}, 500);
		
				$("#listing_slide_buffer").animate({marginLeft:0,}, 500, function(){
				
					$("#listing").html(msg);
					$("#listing_slide_buffer").html('');
					$("#listing_slide_buffer").css('margin-left',677);
				
					$("#listing_slide_buffer2").html('');
					$("#listing_slide_buffer2").css('margin-left',0);
				
					$("#listing_slide_buffer_container").css('display','none');
					$("#listing_slide_buffer").css('display','none');
					$("#listing_slide_buffer2").css('display','none');			
				
				});
				
				$('#pagemem'+a).html(msg);
			}
		});

	}
	
}


function comment_submit(){

	comment_name	= $('#comment_name').val();
	comment_email	= $('#comment_email').val();
	comment_text	= $('#comment_text').val();
	comment_vid		= $('#comment_vid').val();

	continue_submit = true;
	
	if(comment_name == '' || comment_name == 'Your Name'){ continue_submit = false; }
	if(comment_email == '' || comment_email == 'Your E-mail'){ continue_submit = false; }
	if(comment_text == '' || comment_text == 'Write your comments!'){ continue_submit = false; }
	
	if(continue_submit){
		$.ajax({
			type: 'POST',
			url: '/a/comment_submit/',
			data: 'name='+comment_name+'&email='+comment_email+'&text='+comment_text+'&vid='+comment_vid,
			success: function(msg){
			
				if(msg == '200'){
					$('#comments-form').html('<div class="comment-head">Your Comments</div><div class="clear" style="border-top:1px solid #272727; width:315px;"></div><div class="comment-thanks"><br />Thank you. Your comment have been submited.</div>');
				}
				
				
			}
		});
	}
	
}







function SetCookie(name, value){
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	//var path = (argc > 3) ? argv[3] : null;
	var path = '/';
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	//((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((expires == null) ? "" : ("; expires=Thu, 31-Dec-09 00:00:01 GMT")) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function GetCookie(sName){
	var docCookie = document.cookie
	if(docCookie.length>0){
		var begin = docCookie.indexOf(sName+'=')
		if(begin!=-1){
			end=docCookie.indexOf(';', begin)
			if(end==-1)end=docCookie.length
			return unescape(docCookie.substring(begin+sName.length+1, end))
		}
	}
	//a cookie with the requested name does not exist
	return null
}

function DelCookie(name) {
	document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
}

function global_onclick(){

	//q20();

}