// JavaScript Document

$(document).ready(function(){
////////////////////////////////////////////////////////////////////////////
	
	$("#main_menu_head li").hover(function(){
		var gWidth = (($(this).width()+46)/2)-7;
		$(this).css({'background-color' : '#7C7C7C'});
		$(this).find("img").css({'left' : gWidth, 'display' : 'block'});
	}, function(){
		$(this).css({'background-color' : '#1E7DC1'});
		$(this).find("img").css({'display' : 'none'});
	});
	
	$('#main_menu_head #menuMain_2').click(function() {
		$('#mainSub_menu_head_2').delay(500).slideToggle('slow');
  		$('#head_mainSub_menu li:not(#mainSub_menu_head_2)').slideUp(500);
		return false;
	});
	
	$('#main_menu_head #menuMain_3').click(function() {
		$('#mainSub_menu_head_3').delay(500).slideToggle('slow');
  		$('#head_mainSub_menu li:not(#mainSub_menu_head_3)').slideUp(500);
		return false;
	});
	
	$('#main_menu_head #menuMain_6').click(function() {
		$('#mainSub_menu_head_6').delay(500).slideToggle('slow');
  		$('#head_mainSub_menu li:not(#mainSub_menu_head_6)').slideUp(500);
		return false;
	});
	
	$('#AdvanceSearch').click(function() {
		$('#mainSub_menu_head_8').delay(500).slideToggle('slow');
  		$('#head_mainSub_menu li:not(#mainSub_menu_head_8)').slideUp(500);
		return false;
	});
//////////////////////////////////////////////////////////////////////////

	$(".show_member_login").click(function () {
		openOvarlay("#overlay");
		//$.post("index_newsletter.php",$("#from_sendNew").serialize(), function(data) {
		$.post("boxlogin.php", function(data) {			
			$("#box_ajax").html(data);
			boxCenter("#box_ajax");
			$("#box_ajax").slideDown(500);
		});
		return false;
	});
	
	$(".favorite_check").click(function () {
		openOvarlay("#overlay");
		//$.post("index_newsletter.php",$("#from_sendNew").serialize(), function(data) {
		$.post("boxlogin.php", function(data) {			
			$("#box_ajax").html(data);
			boxCenter("#box_ajax");
			$("#box_ajax").slideDown(500);
		});
		return false;
	});
	
	$("#member_signUp").click(function () {
		openOvarlay("#overlay");		
		boxCenterStatic("#box_ajax2");
		$("#box_ajax2").slideDown(500);
	});
	
	$("#member_change").click(function () {
		openOvarlay("#overlay");		
		//$.post("index_newsletter.php",$("#from_sendNew").serialize(), function(data) {	
		boxCenterStatic("#box_if_member_change");
		$("#box_if_member_change").slideDown(500);
	});
	
	$(".play_music").click(function () {
		openOvarlay("#overlay");
		boxCenter_lineEye(".play_Music_box")			
		$(".play_Music_box").slideDown(500);
		
		$(".closeBox_play_Music_box, .cancel").click(function () {									
			$(".play_Music_box").slideUp(200);
			closeOvarlay('#overlay');
			replaceSwfWithEmptyDiv();	
		});
	});
	
	$(".Mobile_Download").click(function () {
		var xx = $(this).attr("rel");
		var yy = xx.split(",");

		
		var mobile_song_names = hexDecode(yy[0]);
		var mobile_artist_names = hexDecode(yy[1]);
		var mobile_digital = yy[2];
		var mobile_ivr = yy[3];
		var mobile_digital13 = yy[4];
		
		
		$.post("data_mobile_download.php?mobile_song_names="+mobile_song_names+"&mobile_artist_names="+mobile_artist_names+"&mobile_digital="+mobile_digital+"&mobile_ivr="+mobile_ivr+"&mobile_digital13="+mobile_digital13, function(data) {
			
			openOvarlay("#overlay");
			$(".Mobile_Download_box").html(data);
			boxCenter_lineEye(".Mobile_Download_box");			
			$(".Mobile_Download_box").slideDown(500);
		
			$(".closeBox_Mobile_Download, .cancel").click(function () {									
				$(".Mobile_Download_box").slideUp(200);
				closeOvarlay('#overlay');
			});
		});	
	});
	
	$(".box_rate_show").click(function () {
		openOvarlay("#overlay");
		$.post($(".box_rate_show").attr('href'), function(data) {
			$("#box_ajax_Rate_Albums").html(data);
			boxCenter_lineEye("#box_ajax_Rate_Albums");
			$("#box_ajax_Rate_Albums").show();
		});
		return false;
	});
	
	$(".order_show").click(function () {
		openOvarlay("#overlay");
		var xx = $(this).attr("rel");
		var yy = xx.split(",");

		
		$("#order_show_song_names").html(yy[0]);
		$("#order_show_artist_names").html(yy[1]);
		$("#order_show_song_id").html(yy[2]);
		
		$.post("inc_lightbox_shop.php?shop_id="+yy[2]+"&order_show_song_names="+hexDecode(yy[0])+"&order_show_artist_names="+hexDecode(yy[1]), function(data) {
			$("#box_ajax4").html(data);	
			boxCenter_lineEye("#box_ajax4");		
			$("#box_ajax4").slideDown(500);
		
			$(".closeBox_order, .cancel").click(function () {									
				$("#box_ajax4").slideUp(200);
				closeOvarlay('#overlay');
				$("#box_ajax4").html("");
			});
			return false;
		});	
		return false;
	});
	
	$(".addFavoriteFail").click(function () {
		$(".play_Music_box").hide();
		$(".play_Music_box").html();
		
		$.post("boxlogin.php", function(data) {			
			$("#box_ajax").html(data);
			boxCenter("#box_ajax");
			$("#box_ajax").slideDown(500);
		});
		return false;
	});
	
	$(".addFavorite").click(function () {
		$(".play_Music_box").hide(200);
		replaceSwfWithEmptyDiv();	
		
		$.post($(".addFavorite").attr('href'), function(data) {
			$("#confirm_favorite").html(data);
			boxCenter_lineEye("#box_ajax_favorite");
			$("#box_ajax_favorite").show();
			
			$.post("favorite_data.php", function(data2) {
				var strData2 = jQuery.trim(data2);
				$("#total_record_fav").html(strData2);
				/*$("#favorite_back").click(function () {
					$("#box_ajax_favorite").fadeOut(100);
					$("#box_ajax_favorite").html();	
					return false;
				})*/
			});
			
			/*$(".closeBoxFavorite").click(function () {
				$("#box_ajax_favorite").fadeOut(100);
				$("#box_ajax_favorite").html();	
				$(".play_Music_box").fadeOut(100);
				closeOvarlay('#overlay');
				replaceSwfWithEmptyDiv();	
			})*/
		});
		return false;
	});
	
	$(".addFavorite2").click(function () {
		openOvarlay("#overlay");
		boxCenter_lineEye("#box_ajax_favorite");
		$.post($(".addFavorite2").attr('href'), function(data) {
			
			$("#confirm_favorite").html(data);
			$("#box_ajax_favorite").show();
			
			
			$.post("favorite_data.php", function(data2) {
				$("#total_record_fav").html(data2);
				$("#favorite_back").click(function () {
					$("#box_ajax_favorite").fadeOut(100);
					closeOvarlay("#overlay");
					$("#box_ajax_favorite").html();	
					return false;
				})
			});
			
			$(".closeBoxFavorite").click(function () {
				$("#box_ajax_favorite").fadeOut(100);
				$("#box_ajax_favorite").html();	
				$(".play_Music_box").fadeOut(100);
				closeOvarlay('#overlay');
				replaceSwfWithEmptyDiv();	
			})
		});
		return false;
	});
});

function openOvarlay(obj) {
	var wwwi = $(document).width();
	var hhhi = $(document).height();
	$(obj).css({'width':wwwi,'height':hhhi,'display':'block'});
}
function closeOvarlay(obj) {
	var wwwi = $(document).width();
	var hhhi = $(document).height();
	$(obj).css({'width':0,'height':0,'display':'none'});
}

function boxCenterStatic(obj) {
	var boxW = $(obj).width()/2;
	var boxH = $(obj).height()/2;
	var wwwi2 = ($(document).width()/2)-boxW;	
	var wwwh2 = ($(window).height()/2)-boxH;
	
	var wwwh3 = $(window).scrollTop()+10+"px"

	$(obj).css({'left':wwwi2,'top':wwwh3});
}

function boxCenter(obj) {
	var boxW = $(obj).width()/2;
	var boxH = $(obj).height()/2;
	var wwwi2 = ($(document).width()/2)-boxW;	
	var wwwh2 = ($(window).height()/2)-boxH;
	
	var wwwh3 = $(window).scrollTop()+wwwh2+"px"

	$(obj).css({'left':wwwi2,'top':wwwh3});
	
	$(window).scroll(function() {
		$(obj).animate({top:$(window).scrollTop()+wwwh2+"px" },{queue: false, duration: 500});
		if($(window).scrollTop()==0){
			$(obj).animate({top:$(window).scrollTop()+wwwh2+"px" },{queue: false, duration: 500});
		}
	});
}

function boxCenter_lineEye(obj) {
	var boxW = $(obj).width()/2;
	var boxH = $(obj).height()/2;
	var wwwi2 = ($(document).width()/2)-boxW;	
	var wwwh2 = (($(window).height()/2)-100)-boxH;
	
	var wwwh3 = $(window).scrollTop()+wwwh2+"px"

	$(obj).css({'left':wwwi2,'top':wwwh3});
	
	$(window).scroll(function() {
		$(obj).animate({top:$(window).scrollTop()+wwwh2+"px" },{queue: false, duration: 500});
		if($(window).scrollTop()==0){
			$(obj).animate({top:$(window).scrollTop()+wwwh2+"px" },{queue: false, duration: 500});
		}
	});
}
/////////////////////// BOX_SIGNUP_CHANGE ///////////////////////
function submitBoxSignUpChange() {
	$("#box_if_member_change").hide();
	boxCenterStatic("#box_if_member_change_post");
	$("#box_if_member_change_post").slideDown(500);
}

function closeBoxSignUpChange() {
	$("#box_if_member_change_post").hide();
	$("#box_if_member_change").hide();
	closeOvarlay('#overlay');
}

function closeBoxSignUpChangePost() {
	$("#box_if_member_change_post").hide();
	closeOvarlay('#overlay');
}
/////////////////////// BOX_SIGNUP_CHANGE ///////////////////////


/////////////////////// BOX_SIGNUP /////////////////////////////
function submitBoxSignUp() {
	$("#box_ajax2").hide();
	boxCenterStatic("#box_ajax2_post");
	$("#box_ajax2_post").slideDown(500);
}

function closeBoxSignUp() {
	$("#box_ajax2").hide();
	$("#box_ajax2_post").hide();
	closeOvarlay('#overlay');
}

function closeBoxSignUpPost() {
	$("#box_ajax2_post").hide();
	closeOvarlay('#overlay');
}

function btnGoLogin() {
	$("#box_ajax2").hide();
	$("#box_ajax2_post").hide();
	$.post("boxlogin.php", function(data) {			
		$("#box_ajax").html(data);
		boxCenter("#box_ajax");
		$("#box_ajax").slideDown(500);
	});
}
/////////////////////// BOX_SIGNUP /////////////////////////////

/////////////////////// BOX_SIGNUP_POST /////////////////////////////
function closeBoxSignupPost() {
	$('#box_ajax2_post').slideUp(100);
	closeOvarlay('#overlay');
}
/////////////////////// BOX_SIGNUP_POST /////////////////////////////

function replaceSwfWithEmptyDiv(){
	var targetID = "FlashID";
   var el = document.getElementById(targetID);
   if(el){
      var div = document.createElement("div");
      el.parentNode.insertBefore(div, el);
      //Remove the SWF
      swfobject.removeSWF(targetID);
      //Give the new DIV the old element's ID
      div.setAttribute("id", targetID);
   }
}

function clickme(artist,ablum,filemp3,song_id){ // id="NameArtistPlayer"></div><div id="NameAlbumArtistPlayer"
var artist = hexDecode(artist);
var ablum = hexDecode(ablum);
  	$('#NameArtistPlayer').html(artist);
	//$('#song_idArtistPlayer').html(song_id);
	if(song_id != ''){
    	$("#addFavoriteId").attr('href', 'favorite_submit.php?action=song&song_id='+song_id);
	}
	$('#NameAlbumArtistPlayer').html(ablum);
 			var flashvars = {};
			flashvars.mp3 = "file_song/song_example_file/"+filemp3;
			flashvars.width = "440";
			flashvars.height = "34";
			flashvars.showstop = "1";
			flashvars.showvolume = "1";
			flashvars.loadingcolor = "7b7b7b";
			flashvars.bgcolor  = "5E5E5E";
			flashvars.bgcolor1 = "5E5E5E" ;
			flashvars.bgcolor2 = "5E5E5E";
			flashvars.slidercolor2 = "7B7B7B";
			flashvars.sliderovercolor = "7B7B7B";
			flashvars.buttoncolor = "989898";
			flashvars.buttonovercolor = "7B7B7B";	
			flashvars.autoplay="1";
			flashvars.volume="80";
			var params = {};
			params.play = "true";
			params.quality = "high";
			params.wmode = "transparent";
			var attributes = {};
			attributes.id = "FlashID";
			swfobject.switchOffAutoHideShow();
			swfobject.embedSWF("musicplayer/player_maxi.swf", "FlashID", "440", "34", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}




