$(function() {
	var setup_rating = 1;
	$("#my-rating > input").each(function(){ if ($(this).attr('disabled') == 'disabled') { var setup_rating = 0; }});
	if (setup_rating == 1) {
		$("input.rating").rating({
		    split: 2,
		    callback: function(value, link){
		        $(this).rating('readOnly', true);
		        $('#rate-success').show();
		        $.ajax({
		            type: 'GET',
		            url: '/ajax/',
		            data: 'ac=rate&val='+value+'&id='+$('#art').val(),
		            dataType: 'json',
		            success: function(d) {
		        		var avg = Math.round(d.avg);
		        		$('input.overall-rating').rating('select', '"'+avg+'"'); 
		        	}
		        });
		}});
	}

	$("input:text").each(function() {
		var txt = $(this).attr('rel');
		$(this).focus(function() {
			if ($(this).val() == txt) {
				$(this).removeClass("default");
			    $(this).val("");
			}
	    });
		$(this).blur(function() {
			if ($(this).val() == "") {
				$(this).val(txt);
				$(this).addClass("default");
			}
		});	
		$(this).blur();
	});
	
	$("form").submit(function() {
		var std = 0;		
		$(this).find("input:text").each(function() {
			var txt = $(this).attr('rel');
			if ($(this).val() == txt || $(this).val().length() < 1) {
				if ($(this).attr('id') == 'q') {
					$('#no-search-error').show();
				}
				std = 1;
			}
		});
		return (std == 1) ? false : true; 
	});
		
    $('.new-top').click(function() {  
        $('.new-top').each(function() { $(this).removeClass('active').removeClass('active_last') });
        if ($('#top-rated').css('display') == 'none') {
            $('#a-top').addClass('active');
            $('#top-rated').show();
            $('#newest').hide();
        }
        else {
            $('#a-new').addClass('active_last');
            $('#newest').show();
            $('#top-rated').hide();
        }
        return false;
    });
  
});

function showStaf() {   
    $('#splashpage').show();
    $('#staf').show();
    
    return false;
}

function showStaf() {   
    $('#splashpage').show();
    $('#staf').show();
    
    return false;
}

function showMark(id, username) {   
    $('#splashpage').show();
    $('#notifyadmin').show();
    $('#mark-id').val(id);
    $('#mark-username').html(username);
    
    return false;
}


function closeSplash() {
	$('#splashpage').hide();
	$('#staf').hide();
	$('#menu').hide();
}

function showMenu(menu_width) {   
    $('#splashpage').show();
    $('#menu').show();
    var menu_width = $('#menu-wrap').width();
    var menu_img_width = $('#menu-wrap > img').width();
    $('#menu-wrap > img').width(menu_width);
    $("#menu-wrap > img").draggable();
    setupMenuSlider(menu_width);
    
    $('.menu-pager').click(function() {
        $('#menu-img').attr('src', $(this).attr('rel')).css('left', 0).css('top', 0).css('width', menu_width);
        $('.menu-pager').each(function() { $(this).removeClass('active'); } );
        $(this).addClass('active');
        $("#slider").slider('value', 8);   
        setupMenuSlider();
        return false;
    });  
}

function setupMenuSlider(menu_width) {
    $("#slider").slider({
        value: 8,
        min: 8,
        max: 100,
        slide: function(event, ui) {
            var nw = menu_width;
            if (ui.value > 0) {
                 nw = (menu_width * (ui.value / 8));
                 if (nw <= menu_width) {
                    nw = menu_width;
                 }
            }        
            $('#menu-wrap > img').css('width', nw);
        }
    });
}

function shareMyspace(T, C, U, L) {
	var targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + encodeURIComponent(T) + '&c=' + encodeURIComponent(C) + '&u=' + encodeURIComponent(U) + '&l=' + L;
    window.open(targetUrl);
}

function shareBebo() {u=location.href;t=document.title;window.open('http://www.bebo.com/c/share?Url='+encodeURIComponent(u)+'&Title='+encodeURIComponent(t)+'&MID=8974376238&TUUID=fc7850b8-964c-47bd-8a91-db1d2a5cad3c','sharer','toolbar=0,status=0,width=626,height=436');return false;}


