//$.noConflict();
//var $ = jQuery.noConflict();


var loginUrl = '';

var winHeight = jQuery(window).height();
var winWidth = jQuery(window).width();

var closeId = '';

function docLoad() {
	if ($(".tabs li:first") != null) {
	$(".tabs li").hover(function() { $(this).css("background", "#353e45");},function() { $(this).css("background", "none");})
	$(".tabs li a").click(function() {
		if ($(this).attr("class") == 'bl2') { $("#bl2 .tab_content").append(obj) } else {$("#bl2 .tab_content object").remove()}
		$(".tabs li a").css("background", "none");
		$(".grad").css("display", "none");
		$(this).css("background", "#353e45");
		$("#"+$(this).attr("class")).css("display", "block");
	})
	}
	function framePos(id) {  
		closeId="iframe";
		$("#bg").after('<div id="iframe" class="border iframe" style="display: none"><img id="close" onclick="closeLayer()" src="/files/planetedurable/img/close.gif" alt="Fermer" title="Fermer" style="cursor:pointer; position: absolute; top: 0px; right: 0px;margin: 2px 2px 0px 0px"/></div>');
		$("#bg").css({height: $("body").innerHeight(), width: $("body").innerWidth()});
	//	$("#bg").css({height: $(".chat_content").innerHeight()+1, width: $(".chat_content").innerWidth()+2});
		$("#close").after(frame[id]);  
		$("#iframe iframe:first").load(function() {    
			var ifrSrc = $(this).attr("src");      
			$("#iframe").css({margin: "0px auto", marginTop: (winHeight - $(this).attr("height"))/2-50, left: (winWidth - $("#iframe iframe").attr("width"))/2, width: $("#iframe iframe").attr("width"), position: "fixed", zIndex: 900, top: "0px"});
			if (navigator.userAgent.indexOf ("MSIE 6") != -1)  $("#iframe").css("position", "absolute");
			//$(this).css("display", "block");
			if ($("#bg").css("display") == "none") $("#bg").show("fast", function(){$("#iframe").show("slow")});
			$("#close").click(function($) { closeLayer(); })	
		})         
	}
	if ($("#alert")) $("#alert").click(function() {framePos('alert')});
	if ($("#alert1")) $("#alert1").click(function() {framePos('alert')});
	if ($("#question")) $("#question").click(function() {framePos('question')});
	if ($("#question1")) $("#question1").click(function() {framePos('question')});
	if ($("#tell")) $("#tell").click(function() {framePos('tell')});
	if ($("#votelist")) $("#votelist").click(function() {framePos('vote')});
//	$("#writevideo").click(function() {framePos('writevideo'); $("#writev").attr("src", chatlink + "?cmd=ask")})
	if ($("#writevideo")) $("#writevideo").click(function() {
		closeId = 'writevideolayer';
		$("#bg").css({height: $("body").innerHeight(), width: $("body").innerWidth()});
//		$("#bg").css({height: $(".chat_content").innerHeight()+1, width: $(".chat_content").innerWidth()+2});
		$("#bg").after("<div id='writevideolayer' class='border padding10 bg' style='display: none'></div>");   
		$("#writevideolayer").load("/chat/planetedurable/french/s_" + techsess + "?cmd=ask", function(){
			$("#writevideolayer").prepend('<img id="close" class="right" onclick="closeLayer()" src="/files/planetedurable/img/close.gif" alt="Fermer" title="Fermer" style="cursor:pointer; margin: -8px -8px 0px 0px"/><div>' + $("#aboutVideo").html() + '</div>');
			$("#writevideolayer").css({width: "320px", margin: '0px auto', marginTop: 100, left: (winWidth - 320)/2, textAlign: 'justify', position: "fixed", zIndex:900, top: "0px"});
			if (navigator.userAgent.indexOf ("MSIE 6") != -1)  $("#wideolayer").css("position", "absolute");
			$("#bg").show("fast", function() {$("#writevideolayer").show("slow")});
			$("#close").click(function($) { closeLayer(); })	
		})
	})

	if ($("#login")) $("#login").click(function() { //loginContent() 
	      //  alert("!");
		closeId = "f";
		$("#bg").css({height: $("body").innerHeight(), width: $("body").innerWidth()});
//		$("#bg").css({height: $(".chat_content").innerHeight()+1, width: $(".chat_content").innerWidth()+2});
		$("#bg").after("<div id='f' class='border padding10 bg' style='display: none'>" + $("#fr").html() + "</div>");
		$("#f").prepend('<img id="close" class="right" onclick="closeLayer()" src="/files/planetedurable/img/close.gif" alt="Fermer" title="Fermer" style="cursor:pointer; margin: -8px -8px 0px 0px"/>');
		$("#f").css({width: '320px', margin: '0px auto', marginTop: 100, left: (winWidth - 320)/2, position: "fixed", zIndex: 900, top: "0px"});
		if (navigator.userAgent.indexOf ("MSIE 6") != -1)  $("#f").css("position", "absolute");
		$("#bg").show("fast", function() {$("#f").show("slow")});
		$("#close").click(function($) { closeLayer(); })	

	})
	if ($("#fr .chat_cell_error_msg") && $("#fr .chat_cell_error_msg").length > 0) { loginContent() }
	function showDiv(id) { 
		closeId = id + "full"; 
		$("#bg").css({height: $("body").innerHeight(), width: $("body").innerWidth()});
//		$("#bg").css({height: $(".chat_content").innerHeight()+1, width: $(".chat_content").innerWidth()+2});
		$("#bg").after("<div id='" + id + "full' class='border padding10 bg' style='display: none'>" + $("#" + id + "f").html() + "</div>");    
		$("#" + id + "full").prepend('<img id="close" class="right" onclick="closeLayer()" src="/files/planetedurable/img/close.gif" alt="Fermer" title="Fermer" style="cursor:pointer; margin: -8px -8px 0px 0px"/>');
		$("#" + id + "full").css({width: '500px', margin: '0px auto', marginTop: 100, left: (winWidth - 500)/2, textAlign: 'justify', position: "fixed", zIndex: 900, top: "0px"});
		if (navigator.userAgent.indexOf ("MSIE 6") != -1)  $("#" + id + "full").css("position", "absolute");
		$("#bg").show("fast", function() {$("#" + id + "full").show("slow")});
		$("#close").click(function($) { closeLayer(); })	
	}
	function showDivB(id) {  
		closeId = id + "full"; 
		$("#bg").css({height: $("body").innerHeight(), width: $("body").innerWidth()});
//		$("#bg").css({height: $(".chat_content").innerHeight()+1, width: $(".chat_content").innerWidth()+2});
		$("#bg").after("<div id='" + id + "full' class='border bg' style='display: none;'><div class='padding10'>" + $("#" + id + "f").html() + "</div></div>");    
		$("#" + id + "full").prepend('<img id="close" class="right" onclick="closeLayer()" src="/files/planetedurable/img/close.gif" alt="Fermer" title="Fermer" style="cursor:pointer; margin: 4px"/>');
		$("#" + id + "full").css({height: '450px', width: '500px', margin: '0px auto', marginTop: 100, left: (winWidth - 500)/2, textAlign: 'justify', lineHeight: "15px", position: "fixed", zIndex: 900, top: "0px"});
		$("#" + id + "full div").css({overflowX: 'hidden', overflowY: 'scroll', height: '412px', width: '480px', textAlign: 'justify', lineHeight: "15px"});
		if (navigator.userAgent.indexOf ("MSIE 6") != -1)  $("#" + id + "full").css("position", "absolute");
		$("#bg").show("fast", function() {$("#" + id + "full").show("slow")});
		$("#close").click(function($) { closeLayer(); })	
	}  
	if ($("#editorialzone")) $("#editorialzone").click(function() {  showDiv("editorialzone") })
	if ($("#guestinfo")) $("#guestinfo").click(function() {  showDiv("guestinfo") })
	if ($("#rules")) $("#rules").click(function() {  showDivB("rules") })
	if ($("#rules1")) $("#rules1").click(function() {  showDivB("rules") })
	if ($("#contact")) $("#contact").click(function() {  showDiv("contact") })
	if ($("#aboutus")) $("#aboutus").click(function() {  showDiv("aboutus") })
	if ($("#aboutchat")) $("#aboutchat").click(function() {  showDiv("aboutchat") })
	if ($("#conditions")) $("#conditions").click(function() {  showDivB("conditions") })
  

}

function videoLoad() {
	$(".web_cam").after(obj1);

}


function mItem(id) {
 $("#"+id).attr("class", "active") 
}

function closeLayer() {         
		$("#"+closeId).hide("slow", function(){$("#bg").hide("fast")});
		$("#close").remove();             
		$("#"+closeId).remove();
}


function loginContent() { 
		closeId = "f";
		$("#bg").css({height: $("body").innerHeight(), width: $("body").innerWidth()});
//		$("#bg").css({height: $(".chat_content").innerHeight()+1, width: $(".chat_content").innerWidth()+2});
		$("#bg").after("<div id='f' class='border padding10 bg' style='display: none'>" + $("#fr").html() + "</div>");
		$("#f").prepend('<img id="close" class="right" onclick="closeLayer()" src="/files/planetedurable/img/close.gif" alt="Fermer" title="Fermer" style="cursor:pointer; margin: -8px -8px 0px 0px"/>');
		$("#f").css({width: '320px', margin: '0px auto', marginTop: 100, left: (winWidth - 320)/2, position: "absolute", zIndex: 900, top: "0px"});
		$("#bg").show("fast", function() {$("#f").show("slow")});
		$("#close").click(function($) { closeLayer(); })	
}

function voteList() {
	var text = '';
	$(".thumb_img").attr({src:"/files/planetedurable/img/minus.gif", width: 18, height: 18});
	$(".thumb_img").css({margin: "0px 5px 0px 0px"});
	$(".thumb_up_img").attr({src:"/files/planetedurable/img/plus.gif", width: 18, height: 18});
	$(".chat_vote_buttons").each(function() {
		text = $(this).html().replace("&nbsp;","");
		$(this).html(text);
	})
	$(".chat_number").each(function() {
		text = $(this).html()+".";
		$(this).html(text);
	})
}

function voteLast() {
	$(".thumb_img").attr({src:"/files/planetedurable/img/minus.gif", width: 18, height: 18});
	$(".thumb_img").css({margin: "5px 0px"});
	$(".thumb_up_img").attr({src:"/files/planetedurable/img/plus.gif", width: 18, height: 18});
	$(".chat_vote_buttons").each(function() {
		var text = $(this).html().replace("&nbsp;","");
		$(this).html(text);
	})
	$(".chat_number").each(function() {
		var text = $(this).html()+".";
		$(this).html(text);
	})
} 


function defComingList() {  
	$(".comlist").css("display", "none");
	var width = 0;
	$(".pastChatTable td").removeAttr("width");
	$(".leftPad table").attr("class", "coming");
	$(".leftPad table").removeAttr("width");
	$(".leftPad td").attr("class", "coming_chat border grad1");
	$(".defcomlist").css("display", "block");
	$(".coming_chat").each(function() {  
		if($.trim($(this).html().replace("&nbsp;","").replace(" ", "")) == '') $(this).remove();
	})
	if ($(".defcomlist:first").html()) {
	/*	$(".defcomlist").each(function(index) {  
			width = width + 166;
		})*/
		width = 166*$(".defcomlist").length;
	}
	if (width > 0) {
	$(".coming").attr("width", width);
	$(".coming").attr("align", "left");
	if ($(".defcomlist").length > 4) {
		$(".coming").removeAttr("width");
		$(".coming").css("margin", "0px auto");
	}		
	$(".coming_chat").after("<td width='6px'>&nbsp;</td>");
	$(".coming_chat").before("<td width='6px'>&nbsp;</td>");
	if ($(".coming_chat").length > 5) {
		$(".leftPad tr").each(function(index) {if (index > 1) $(this).css({display: "none"})})
	}
	}

}

function videoContent() {  
//jQuery(document).ready(function($) {
	$(".video_cell").css("text-align", "center");
	$(".video_cell").attr("width", "310px");
	$("#VideoFrame").attr("width", "310px");
	$("#VideoFrame").attr("height", "233px");
//})
}

function videoChatContent() {  
	$(".video_cell").css("text-align", "center");
	$(".video_cell").attr("width", "490px");
	$("#VideoFrame").attr("width", "490px");
	$("#VideoFrame").attr("height", "367px");
}

var url = '';

function loadPoll() {  
	$.ajax({
		url: forumpollurl,
		dataType: "html",
		scriptCharset: "ISO-8859-1",
		beforeSend: function(xhr) {
		xhr.setRequestHeader("Accept-Charset","ISO-8859-1");
		xhr.setRequestHeader("Content-type","text/html; charset=ISO-8859-1");
		},
		success: function(data) { //alert(data);
		$("#forumpollurl").html(data);
		$("#forumpollurl form").attr("action",'javascript:void(0)');
		$("#forumpollurl .chat_cell").each(function(index) {
			if (index%2 == 0) {
				$(this).parent().before('<tr class="chat_row"><td class="chat_cell">' + $(this).html() + '</td></tr>');
				$(this).remove();
			}		
			if (index%2 == 1) {
				$(this).css({paddingBottom: "10px"});
			}	
		})
		$("#forumpollurl select").each(function() {
			$(this).css({width: "250px", position: "relative", zIndex: "0"});
		})
		$("#forumpollurl form").submit(function(){subForm()});
		if ($("#forumpollurl .chat_button")) {
			$("#forumpollurl .chat_cell").removeAttr("width");
			$("#forumpollurl .chat_button").css({background: "transparent url(/files/planetedurable/img/send.gif) no-repeat scroll left center", height: "31px", paddingLeft: "40px", border: "0px", color: "#ffffff"});			
			$("#forumpollurl .chat_button").attr("value", "Envoyer");
		} 
		quizzLink();  
		}
	});



/*	$("#forumpollurl").load(forumpollurl,function() {
	//	url = $("#forumpollurl form").attr("action"); 
		url = forumpollurl;      alert($("#forumpollurl").html().indexOf("’"));
	//	$("#forumpollurl").html($("#forumpollurl").html().replace("’", "'"));
		$("#forumpollurl form").attr("action",'javascript:void(0)');
		$("#forumpollurl .chat_cell").each(function(index) {
			if (index%2 == 0) {
				$(this).parent().before('<tr class="chat_row"><td class="chat_cell">' + $(this).html() + '</td></tr>');
				$(this).remove();
			}		
			if (index%2 == 1) {
				$(this).css({paddingBottom: "10px"});
			}	
		})
		$("#forumpollurl select").each(function() {
			$(this).css({width: "250px", position: "relative", zIndex: "0"});
		})
		$("#forumpollurl form").submit(function(){subForm()});
		if ($("#forumpollurl .chat_button")) {
			$("#forumpollurl .chat_cell").removeAttr("width");
			$("#forumpollurl .chat_button").css({background: "transparent url(/files/planetedurable/img/send.gif) no-repeat scroll left center", height: "31px", paddingLeft: "40px", border: "0px", color: "#ffffff"});			
			$("#forumpollurl .chat_button").attr("value", "Envoyer");
		} 
		quizzLink();  
	})   */
}

function subForm() {
//	alert("!");
	$.ajax({
		type: "POST",
		url: url,
		data: $("#forumpollurl form").serializeArray(),
		dataType: "html",
		success: function(data) {  //alert(data);
			$("#forumpollurl").html(data);
			quizzLink();
		}
	});
//	$.get(url+'&'+$("#forumpollurl form").serialize(),function(data) {  $("#forumpollurl").html(data); quizzLink();});

	return false;
}

function quizzLink() {
	if ($("#forumpollurl .msg").html() != '') $("#forumpollurl .msg").after("<a class='vote left' id='quizzlink' onclick='quizzAnswers()'>" + answerslink + "</a>");	
}

function quizzAnswers() {
		closeId = 'quizzanswersblock';
		$("#bg").css({height: $("body").innerHeight(), width: $("body").innerWidth()});
//		$("#bg").css({height: $(".chat_content").innerHeight()+1, width: $(".chat_content").innerWidth()+2});
		$("#bg").after("<div id='quizzanswersblock' class='border padding10 bg' style='display: none'>" + $("#quizzanswers").html() + "</div>");    
		$("#quizzanswersblock").prepend('<img id="close" class="right" onclick="closeLayer()" src="/files/planetedurable/img/close.gif" alt="Fermer" title="Fermer" style="cursor:pointer; margin: -8px -8px 0px 0px"/>');
		$("#quizzanswersblock").css({width: '500px', margin: '0px auto', marginTop: 100, textAlign: 'justify', position: "fixed", zIndex: 900, left: (winWidth-500)/2, top: "0px"});
		if (navigator.userAgent.indexOf ("MSIE 6") != -1)  $("#quizzanswersblock").css("position", "absolute");
		$("#bg").show("fast", function() {$("#quizzanswersblock").show("slow")});
		$("#close").click(function($) { closeLayer(); })	
}       
