$(document).ready(function(){

	$("#mobileLoginView").hide();
	
	$('.topMenu').mouseover(function(){
		$(this).css("cursor","pointer");
		$(this).css("color","#FF0000");
	});
	
	$('.topMenu').mouseout(function(){
		$(this).css("color","#FFFFFF");
	});
	

	
	$('#txtTopMenuSearch').click(function(){
		$('#txtTopMenuSearch').val("");
		$('#txtTopMenuSearch').addClass('searchBoxAfter');
		$(".ac_results").show();
	});
	
	$("#userNameDisplay").click(function(){
		window.location = hosturl+'/Profile'
	});
	
	$('#menuLogout').click(function(){
		if($('#menuLogout').html()=='Logout') Logout();
		if($('#menuLogout').html()=='Login') Login();
	});
	
	$('#home').click(function(){
		window.location = hosturl+"/Home";
	});
	$('#movies').click(function(){
		window.location = hosturl+ "/Movies";
	});
	
	$('#musics').click(function(){
		window.location = hosturl+ "/Musics";
	});
	
	$('#onepage').click(function(){
		window.location = hosturl+ "/OnePage";
	});
	
	$('#kdrama').click(function(){
		window.location = hosturl+ "/Movies/Korea";
	});
	
	$('#signUp').click(function(){
		window.location = hosturl+ "/SignUp";
	});
	
	
	
	$("#txtTopMenuSearch").autocomplete(hosturl+'/Bend/MovieSearch',
				{minChars:1,max:11,autoFill:false,formatItem:function(row,index,total) {
		
												$(document).click(function(){
													
													
													$(".ac_results").hide();
													
													e = jQuery.Event("keydown");
													e.which = 50;
													$("#txtTopMenuSearch").trigger(e);

												});
												
												
												record = JSON.parse(row);
												
												
												
												prevIndex = index-1;
												$("#returnListIndex"+prevIndex).click(function(){
													returnVal = $(this).attr('returnVal');
													type = $(this).attr('returnType');
													id = $(this).attr('srcReturnId');
													
													
													if(type=="MOVIE" || type=="MOVIE-MM"){
														window.location = hosturl+"/PlayMovie/"+id;
													}
													if(type=="ARTIST" || type=="ARTIST-MM"){
														window.location = hosturl+"/Artist/"+id;
													}
												});
												if(index==total) return "";
												
												imageUrl = record.imgUrl;
												
												return "<div class='srcReturnContainer' returnType='"+record.type+"' srcReturnId='"+record.id+"' returnVal='"+record.returnval+"' id='returnListIndex"+index+"' class='zawgyi'>" +
														"<img class='srcReturnImg' src='"+imageUrl+"' width='50'> " + record.returnval + "</div>\n";
												
											},
											formatResult:function(data,pos,totalData){
												record = JSON.parse(data);
												if(record.type=='EOF') return " ";
												return record.returnval;
											}
				});
	
	
//	$("#txt_search").keydown(function(event){
//	  if (event.keyCode==13) {
//			var q = $("#txt_search").val();
//			$.getJSON("src_bend.php",{q:q, limit:10 },function(data){
//				if(data.type=="MOVIE" || data.type=="MOVIE-MM"){
//					window.location="play_movies.php?id=" + data.id + "&no=1";
//				};
//				if(data.type=="ARTIST" || data.type=="ARTIST-MM"){
//					window.location="src_artist.php?id=" + data.id;
//				};
//			});
//	  }
//	});
	
	
	
});




function Logout(){
	$.ajax({
		url:'Bend/Logout',
		type :"POST",
		data: {},
		dataType:"json",
		success:function(data){
			
			if(data.status=="success"){
				window.location = hosturl;
				
			}else{
				FmvAlert(data.data);
			}
		}
		
	});
}


function Login(){
	$.getJSON(hosturl+'/Bend/GetMobileLoginView',{},function(data){
		
		$("#mobileLoginView").show();
		$("#mobileLoginView").html(data.data);
		
		LoginReady();
		
		$("#txtPassword").keydown(function(event){
			if(event.keyCode==13){
				LoginAuth();
			}
		});
	});
	
	
	
}
