// WEBSITE SETTINGS
var fs2 = {

	//lang: 'fr',
	lang: $("html").attr("lang"),
	xmlReqUrl: '/api.php'
	
};


$(document).ready(function() {

	// **** Search function
	//
	$("#f_search").autocomplete('/api.php?comp=ajax-xml&cmd=autocomplete&lang='+fs2.lang).result(function(event, data) {
		var url = data[1];
		location.href = url;
	});

	// *** Genres Menu ***
	//
	$("#menu_genres").mouseover(function(){
		
		var offset = $(this).offset();
		var height = $(this).height();
		var top = offset.top+height;
		var left = offset.left;
		
		var position 	= {'top':top,'left':left};
		var html		= $('#div_menu_genres').html();
		
		submenu.open( position, html );
		
	});
	
	$('#mainmenu li[class!=submenu]').mouseover(function(){ submenu.close(); });
	//
	// *** /Genres Menu ***
	
	// *** Account Menu ***
	//
	$("#menu_account").mouseover(function(){
		
		var offset = $(this).offset();
		var height = $(this).height();
		var top = offset.top+height;
		var left = offset.left;
		
		var position 	= {'top':top,'left':left};
		var html		= $('#div_menu_account').html();
		
		submenu.open( position, html );
		
	});
	//
	// *** /Account Menu ***
	
	// *** Artist Menu ***
	//
	$("#menu_artist").mouseover(function(){
		
		var offset = $(this).offset();
		var height = $(this).height();
		var top = offset.top+height;
		var left = offset.left;
		
		var position 	= {'top':top,'left':left};
		var html		= $('#div_menu_artist').html();
		
		submenu.open( position, html );
		
	});
	//
	// *** /Artist Menu ***
	

	// ADD ARTIST TO FAVORITES
	$("#fav_add_artist").click(function(e){
		e.preventDefault();
		var id_artist = $("#profile_name").attr('class').slice(4);
		
		$.get( fs2.xmlReqUrl, {'comp' : 'ajax-xml', 'cmd' : 'fav_add_item', 'id_item': id_artist, 'item_type': '1', 'lang' : fs2.lang}, function(data){
		
			var res = $(data).find('status').text();
			
			if( res == 'NOK'){
				popup.load( '/ui/html/error.html.php', 'lang='+fs2.lang );
			}
			if( res == 'LOGIN-REQ'){
				popup.load( '/ui/html/login-req.html.php', 'lang='+fs2.lang );
			}
			if( res == 'OK'){
				popup.load( '/ui/html/confirm.html.php', 'lang='+fs2.lang );
			}
		});	
	});
	
	// REMOVE ARTIST FROM FAVORITES
	$("#fav_remove_artist").click(function(e){
		e.preventDefault();
		var id_artist = $("#profile_name").attr('class').slice(4);
		
		$.get( fs2.xmlReqUrl, {'comp' : 'ajax-xml', 'cmd' : 'fav_remove_item', 'id_item': id_artist, 'item_type': '1', 'lang' : fs2.lang}, function(data){
		
			var res = $(data).find('status').text();
			
			if( res == 'NOK'){
				popup.load( '/ui/html/error.html.php', 'lang='+fs2.lang );
			}
			if( res == 'LOGIN-REQ'){
				popup.load( '/ui/html/login-req.html.php', 'lang='+fs2.lang );
			}
			if( res == 'OK'){
				popup.load( '/ui/html/confirm.html.php', 'lang='+fs2.lang );
			}
		});	
	});
	
	// SEND MESSAGE TO ARTIST
	$("#message_to_artist").click(function(e){
		e.preventDefault();
		var id_artist = $("#profile_name").attr('class').slice(4);
		popup.load( '/ui/html/send-message.html.php', 'lang='+fs2.lang+'&user_id='+id_artist+'&user_type=2' );
	});
	
	// ADD ALBUM TO FAVORITES
	$("#fav_add_album").click(function(e){
		e.preventDefault();
		var id_album = $("#profile_name").attr('class').slice(4);
		
		$.get( fs2.xmlReqUrl, {'comp' : 'ajax-xml', 'cmd' : 'fav_add_item', 'id_item': id_album, 'item_type': '2', 'lang' : fs2.lang}, function(data){
		
			var res = $(data).find('status').text();
			
			if( res == 'NOK'){
				popup.load( '/ui/html/error.html.php', 'lang='+fs2.lang );
			}
			if( res == 'LOGIN-REQ'){
				popup.load( '/ui/html/login-req.html.php', 'lang='+fs2.lang );
			}
			if( res == 'OK'){
				popup.load( '/ui/html/confirm.html.php', 'lang='+fs2.lang );
			}
		});	
	});
	
	// REMOVE ALBUM FROM FAVORITES
	$("#fav_remove_album").click(function(e){
		e.preventDefault();
		var id_album = $("#profile_name").attr('class').slice(4);
		
		$.get( fs2.xmlReqUrl, {'comp' : 'ajax-xml', 'cmd' : 'fav_remove_item', 'id_item': id_album, 'item_type': '2', 'lang' : fs2.lang}, function(data){
		
			var res = $(data).find('status').text();
			
			if( res == 'NOK'){
				popup.load( '/ui/html/error.html.php', 'lang='+fs2.lang );
			}
			if( res == 'LOGIN-REQ'){
				popup.load( '/ui/html/login-req.html.php', 'lang='+fs2.lang );
			}
			if( res == 'OK'){
				popup.load( '/ui/html/confirm.html.php', 'lang='+fs2.lang );
			}
		});	
	});
	
	// ADD TRACK TO FAVORITES
	$("a.fav_add_track").click(function(e){
		e.preventDefault();
		var id_item = $(this).parent().parent().attr('class').slice(4);
		
		$.get( fs2.xmlReqUrl, {'comp' : 'ajax-xml', 'cmd' : 'fav_add_item', 'id_item': id_item, 'item_type': '3', 'lang' : fs2.lang}, function(data){
		
			var res = $(data).find('status').text();
			
			if( res == 'NOK'){
				popup.load( '/ui/html/error.html.php', 'lang='+fs2.lang );
			}
			if( res == 'LOGIN-REQ'){
				popup.load( '/ui/html/login-req.html.php', 'lang='+fs2.lang );
			}
			if( res == 'OK'){
				popup.load( '/ui/html/confirm.html.php', 'lang='+fs2.lang );
			}
		});	
	});
	
	// ADD ALBUM TO SHOPPING CART
	$("a.buy_album").click(function(e){
		e.preventDefault();
		var id_item 	= $("#profile_name").attr('class').slice(4);
		var item_type 	= 1;
		
		$.get( fs2.xmlReqUrl, {'comp' : 'ajax-xml', 'cmd' : 'buy_album', 'id_item': id_item, 'item_type': item_type, 'lang' : fs2.lang}, function(data){
			popup.load( '/ui/html/cart_add_item.html.php', 'lang='+fs2.lang+'&id_item='+id_item+'&item_type='+item_type );
		});	
	});
	
	// ADD ALBUM TRACK TO SHOPPING CART
	$("a.buy_track").click(function(e){
		e.preventDefault();
		var id_item 	= $(this).parent().parent().attr('class').slice(4);
		var item_type 	= 2;
		
		$.get( fs2.xmlReqUrl, {'comp' : 'ajax-xml', 'cmd' : 'buy_album', 'id_item': id_item, 'item_type': item_type, 'lang' : fs2.lang}, function(data){
			popup.load( '/ui/html/cart_add_item.html.php', 'lang='+fs2.lang+'&id_item='+id_item+'&item_type='+item_type );
		});	
	});
	
	// ADD SINGLE TO SHOPPING CART
	$("a.buy_single").click(function(e){
		e.preventDefault();
		var id_item 	= $(this).parent().parent().attr('class').slice(4);
		var item_type 	= 3;
		
		$.get( fs2.xmlReqUrl, {'comp' : 'ajax-xml', 'cmd' : 'buy_album', 'id_item': id_item, 'item_type': item_type, 'lang' : fs2.lang}, function(data){
			popup.load( '/ui/html/cart_add_item.html.php', 'lang='+fs2.lang+'&id_item='+id_item+'&item_type='+item_type );
		});	
	});
	
	// COMMENT ALBUM
	$("a.review_album").click(function(e){
		e.preventDefault();
		var id_item 	= $("#profile_name").attr('class').slice(4);
		var item_type 	= 2;
		
		popup.load( '/ui/html/comment-album.html.php', 'lang='+fs2.lang+'&item_id='+id_item+'&item_type='+item_type );
	});
	
	// ADD TRACK TO PLAYLIST
	$("a.pls_add_track").click(function(e){
		e.preventDefault();
		var id_item 	= $(this).parent().parent().attr('class').slice(4);
		popup.load( '/ui/html/playlist_add_track.html.php', 'lang='+fs2.lang+'&id_item='+id_item );
	});
	
	

	

});