/**
 * @author Nicolas-ZhaoZhaoXiaodong
 * email: zhaoxiaodong713@hotmail.com
 *
 * www.mrmodern.com Content Page UI(2009-4-1)
 * @requires jQuery v1.2.6
 * @requires jQuery Plugin - jquery.slide v.1.0.0
 * @requires content-page-ui.js
 */
//public method

//private method
(function($){
	$(function(){
		
		//home page kv
		$(".main-slide", ".home").slide({
			auto: true,
			speed: 2000
		});

		kvLoadingImg();
		//
		//channel home required sitting visible number
		/*$(".main-slide", ".channel-home").slide({
			speed: 2000,
			btnPrev: ".main-slide .prev",
			btnNext: ".main-slide .next",
			visible: 4
		});*/
		$(".main-slide", ".channel-home").slide1({
			auto: true,
			speed: 2000,
			btnPrev: ".main-slide .prev",
			btnNext: ".main-slide .next",
			visible: 4
		});	
		
		//slide
		var options = {
			btnNext: ".slide-next",
			btnPrev: ".slide-prev",
			speed: 800,
			visible: 3
		};
		try {
			$(".min-jCarousel:first").jCarouselLite(options);
			var load = [];
			$.each($(".home-tabs ul a"), function(i, n){
				load[i] = false;
				load[0] = true;
				$(n).click(function(){
					//tabs css
					$(".home-tabs .tab-right").removeClass("tab-right");
					$(this).parent(".last").addClass("tab-right");
					
					var id = $(this).attr("href");
					if (!load[i]) {
						options.btnNext = $(id).find(".slide-next");
						options.btnPrev = $(id).find(".slide-prev");
						$(".min-jCarousel").eq(i).jCarouselLite(options);
						load[i] = true;
					}
				});
			});
		} 
		catch (e) {
		}
		
		//
		//home survey
		//this is test code
		var loading = function(){
			$("<div class='loading'>loading...</div>").css({
				color: "#FFFF00",
				"font-weight": "bold",
				"line-height": $("#form-home-survey").height() + "px",
				"text-align": "center",
				position: "absolute",
				top: 0,
				left: 0,
				"z-index": 9,
				"background-color": "#000",
				filter: "alpha(opacity=0.5)",
				opacity: "0.5",
				width: $("#form-home-survey").width() + "px",
				height: $("#form-home-survey").height() + "px"
			}).appendTo("#form-home-survey");
			$.ajax({
	                        type: "POST",
	                        url: "/layout/set/popup/content/action",
	                        async: false,
				data: $("#form-home-survey").serialize(),
	                        success: function( responseText ){	
                                    $("#result-poll").html( responseText );
                                    $("#send-poll").hide();
                                    $("#form-home-survey .loading").hide();
                                    $("#return-poll").css("display","block");
		                }
	                });
		};

		var view = function(){
                        $("<div class='loading'>loading...</div>").css({
				color: "#FFFF00",
				"font-weight": "bold",
				"line-height": $("#form-home-survey").height() + "px",
				"text-align": "center",
				position: "absolute",
				top: 0,
				left: 0,
				"z-index": 9,
				"background-color": "#000",
				filter: "alpha(opacity=0.5)",
				opacity: "0.5",
				width: $("#form-home-survey").width() + "px",
				height: $("#form-home-survey").height() + "px"
			}).appendTo("#form-home-survey");
		        $.ajax({
	                        type: "POST",
	                        url: "/layout/set/popup/content/collectedinfo/"+$("#survey-nodeid").val(),
	                        async: false,
				data: $("#form-home-survey").serialize(),
	                        success: function( responseText ){	
                                    $("#result-poll").html( responseText );
                                    $("#send-poll").hide();
                                    $("#form-home-survey .loading").hide();
                                    $("#return-poll").css("display","block");
		                }
	                });
		};

		var getData = function(){
			var data = [];
			for (var i = 0; i < $(":radio", "#form-home-survey").size(); i++) {
				data[i] = (94 + i) + "%";
			}
			return data;
		};
		var showData = function(){
			var data = getData();
			setTimeout(function(){
				$(".loading", "#form-home-survey").hide();
				$(":radio", "#form-home-survey").hide();
				$.each($(":radio", "#form-home-survey"), function(i, n){
					$(n).before("<span>" + data[i] + "</span>");
				});
				$("#home-c5-col3 p input").hide();
				$("#home-c5-col3 p input").eq(2).show();
			}, 500);
			
		};

		//submit
		$(".submit", "#form-home-survey").click(function(){
                        var radio=$("#form-home-survey").find(":radio");
			var result=true;
			for(var i=0;i<radio.length;i++){
			    if(!radio[i].checked){
			        result=false;
                            }
			    else{
			        result=true;
			        break;
			    }
			}
                        if(!result){
                            alert("请选择任一选项后进行提交，谢谢支持！");
			    return false;
		        }
			//loading
			loading();
			//load data
			//showData();
		});
		//view button
		$("#btnFrmHomeSurveyView").click(function(){
			//loading
			view();
			//load data
			//showData();
		});
		//back button
		$("#btnFrmHomeSurveyReturn").click(function(){
			//reset
                        $("#send-poll").show();
                        $("#result-poll").empty();
                        $("#return-poll").hide();
		});

	});
})(jQuery);

function  kvLoadingImg(){
        $(".loading").fadeOut(6000);
}
