/**
 * @author jun k8440ty@nate.com
*/

function Check_Login(){
	$.ajax({
		type: "POST",
		url: "./include/check_login.php",
		success: function(msg){
			if(msg =="true"){
				$("#login_wrap").remove();
			}
		},
		error: function(){
			alert('error');
		}
	});
}
$(document).ready(function() {
	Check_Login();
	Get_Index_Movie();
	footerInclude();

	//popup show
	$("#popupdiv").hide();

	if (!$.browser.msie6) {
		$("#popupdiv").left();
	}
	if ($.browser.msie6) {
		$("#popupdiv").left_ie6();
		$("#closeimg").attr("src","./css/popup/fancy_closebox.gif");
	}
	
	if ( popup_getCookie( "Notice" ) != "done" )
	{
		$("#popupdiv").show();
	}
});







//popup function start
function popup_getCookie( name ){
    var nameOfCookie = name + "=";
    var x = 0;
    while ( x <= document.cookie.length )
    {
            var y = (x+nameOfCookie.length);
            if ( document.cookie.substring( x, y ) == nameOfCookie ) {
                    if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
                            endOfCookie = document.cookie.length;
                    return unescape( document.cookie.substring( y, endOfCookie ) );
            }
            x = document.cookie.indexOf( " ", x ) + 1;
            if ( x == 0 )
                    break;
    }
    return "";
}
function popup_setCookie( name, value, expiredays )
{
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function popup_close()
{
        popup_setCookie( "Notice", "done" , 1);
        $("#popupdiv").hide();
}
function na_call(str){  eval(str);}
//popup function end








function footerInclude(){
	$.post("./include/footer.html",{},function(data){
		$("#footer").html(data);
		
	});

}

function Get_Index_Movie(){
	$.ajax({
		type: "POST",
		url: "./php/get_index_movie.php",
		success: function(msg){
			var string = createXMLFromString(msg);
			Set_Index_Movie(string);
		},
		error: function(){
			alert('error');
		}
	});
}
			
			
			
function Set_Index_Movie(xml){
	var html ="<ul class='movie_list'>";
	$(xml).find('item').each(function(){
		html +=
		"<li class='list'>"+
			"<table><tr>"+
				"<td class='img' valign='top'  height='105' width='140'>"+
					"<div class='image_box'>"+
						"<div class='img_wrapper'>"+
							"<div class='img_outer'>"+
								"<div class='img_inner'>"+
									"<a href='./view/view_movie.html?mno="+$(this).find("movie_no").text()+"'>"+
										"<img src='"+$(this).find("basepath").text()+"/thumb/"+$(this).find("thumb_file").text()+"' width=140 height=105 alt='thumb image' />"+
									"</a>"+
								"</div>"+
							"</div>"+
						"</div>"+
					"</div>"+
						
					
				"</td>"+
				"<td class='movie_content' valign='top'>"+
					"<ul>"+
						"<li class='movie_title'>"+
							"<a href='./view/view_movie.html?mno="+$(this).find("movie_no").text()+"'>"+
								"<span>"+$(this).find("movie_title").text()+"</span>"+
							"</a>"+
						"</li>"+
						"<li class='description'><span>"+$(this).find("description").text().substr(0,60)+"</sapn></li>"+
						"<li class='views'>"+
							"<span class='views'>조회수 "+$(this).find("views").text()+" 회</span>"+
							"<span class='name'>"+$(this).find("user_id").text()+"</li>"+
					"</ul>"+
				"</td>"+
			"</tr></table>"+
		"</li>";
	});
	html += "</ul><div class='more'><a href='./view/view_list.html?page=1'><span class='arrow'>▶▶</span> 최신 무비 더 보기</a></div>";
	
	$("#pri_wrap").html(html);
	Get_Index_Notice();
}



function Get_Index_Notice(){
	$.ajax({
		type: "POST",
		url: "./php/get_index_notice.php",
		success: function(msg){
			var string = createXMLFromString(msg);
			Set_Index_Notice(string);
		},
		error: function(){
			alert('error');
		}
	});
}
//http://mightyplayer.com/customer/notice_view.html?no=213
function Set_Index_Notice(xml){
	var html ="";
	$(xml).find('item').each(function(){

		html +=
		'<li class="content"><img src="./image/dot.gif" /><span class="title"><a href="./customer/notice_view.html?no='+$(this).find("no").text()+'">'+$(this).find("title").text()+'</a></span>'+
		
			'<span class="date">['+$(this).find("date").text()+']</span>'+
		'</li>';
	});

	
	$("#notice").append(html);
}

function Get_Login(){

	$.ajax({
		type: "POST",
		url: "./login/php/get_login.php",
		data: "id=" + $("#user_id").val()+"&pw=" + $("#user_pw").val(),
		success: function(msg){
			if(msg =="true"){
				 location.href="./";
			}else{
				alert("아아디 혹은 암호가 틀렸습니다.");
			}
		},
		error: function(){
			alert('error');
		}
	});
}

function password_Enter(e){

	if(e.keyCode == 13){
		Get_Login();
	}
}


