//
// DOM loaded
//

jQuery(function($) {
	
	//
	// Rating functions
	//
	var rated = false;
	// Mouse over and out
	$('#rating a').hover(function() {
	    if(!rated) {
				$(this).addClass('over');
				var currentStar = this.name;
				$(this).parent().find("a").each(function() {
					if(this.name < currentStar) $(this).addClass('over');
				}).end();
				
			}
	}, function() {
	    if(!rated) {
				$(this).parent().find('a').removeClass('over');
			}
	});
/*
	// Rating star was clicked
	$("#rating a").click(function(){
		if(!rated) {
			$('#rating-status').fadeIn('slow');
			rated = true;
			userRating = this.name;
			// Ajax function to cast the vote
			$.ajax({ 
				url: 'ajax-rate.html', 
				type: 'POST', 
				data: "rating=" + userRating + "&user=user-id",
				error: function(){ 
					$('#rating-status').hide();
					alert('Kunde inte spara din röst. Vänligen försök senare.'); 
				}, 
				success: function(msg){ 
					$('#rating-status').html(msg);
				} 
			});
		}
		return false;
	});
*/	
	//
	// Listing functions
	//
	$(".more li a").click(function(){
		// Clear the link-styles and make the current link selected
		$(this).parent().parent().find('a').removeClass('selected');
		$(this).addClass('selected');
		var currentListing = this.name;
		var i = 1;
		//alert("user clicked listing: "+currentListing);
		$(this).parent().parent().parent().find("div").each(function() {
			$(this).slideUp();
			if(i == currentListing) $(this).slideDown();
			i++;
		}).end();

		return false;
	});
	
	// Modal
	$('.tip-friend a').click(function (e) {
		e.preventDefault();
		$('#tipFriend').modal({
  		    close:false,
  		    persist: true,
  		    position: ["20%", ],
  		    overlayId: 'modalOverlay',
  		    containerId: 'modalContainer',
  		    dataId: 'tipFriend',
  		    appendTo: 'form'
  	    });
	});
	
	$('.embed a').click(function (e) {
		e.preventDefault();
		$('#embedClip').modal({
  		    close:false,
  		    position: ["20%",],
  		    overlayId:'modalOverlay',
  		    containerId:'modalContainer'
  	    });
	});
});

