$(document).ready(function(){
	$('body').supersleight();

	$("a.update_favorite").click(function(event){
		event.preventDefault();
		var fav_url = $(this).attr('href');
		var stream = $(this).attr('title');
		$("div #favorite_"+stream).html('<span class="small">Processing...</span>');
		$("div #favorite_"+stream).load(fav_url);
	});

	$("div.favorited").hover(function(){
		if ($(this).hasClass('favorited_free') == true) {
			$(this).addClass('favorited_free_hover');
		} else if ($(this).hasClass('favorited_nude') == true) {
			$(this).addClass('favorited_nude_hover');
		} else if ($(this).hasClass('favorited_private') == true) {
			$(this).addClass('favorited_private_hover');
		} else {
			$(this).addClass('favorited_pornstar_hover');
		}
	}, function(){
		if ($(this).hasClass('favorited_free') == true) {
			$(this).removeClass('favorited_free_hover');
		} else if ($(this).hasClass('favorited_nude') == true) {
			$(this).removeClass('favorited_nude_hover');
		} else if ($(this).hasClass('favorited_private') == true) {
			$(this).removeClass('favorited_private_hover');
		} else {
			$(this).removeClass('favorited_pornstar_hover');
		}
	});

	$("div.modeldiv").hover(function(){
		if ($(this).hasClass('modeldiv_free') == true) {
			$(this).addClass('modeldiv_free_hover');
			var isFree = true;
		} else if ($(this).hasClass('modeldiv_nude') == true) {
			$(this).addClass('modeldiv_nude_hover');
		} else if ($(this).hasClass('modeldiv_private') == true) {
			$(this).addClass('modeldiv_private_hover');
		} else {
			$(this).addClass('modeldiv_pornstar_hover');
		}

		if($(this).children("a.modelname").hasClass("has_long_name")){
			$(this).children("a.modelname").not("a.long_name").hide();
			$(this).children("a.modelstatus").hide();
			$(this).children("a.long_name").show();
		}

		var modelImage = $(this).children("a.modelimage");
		var streamName = modelImage.attr('rel');

		if (streamName) {
			if ((streamName.length > 0) && (isFree == true)) {
				var so = new SWFObject("http://banners.cams.com/images/cams/flash/cams_live.swf", streamName, "155", "116", "9", "#000000");
				so.addParam("wmode", "transparent");
				so.addParam("allowfullscreen", "true");
				so.addParam("allowscriptaccess", "always");
				so.addParam("scale", "noscale");
				so.addParam("quality", "high");
				so.addParam("autostart", "true");
				so.addParam("flashvars", "genreKeys=01,02,05,08,09&logoURL=http%3A%2F%2Fwww.metrobabes.com%2Fimages%2Fpixel_trans.gif&colorTheme=0xFF0000&modelNameColor=0x000000&volume=0&skinURL=cams_live_skin_3.swf&clickURL=%2Froom.php%3Fid%3D2%26stream%3D"+streamName+"&streamName="+streamName+"&wonImageURL=http://www.metrobabes.com/images/default.jpg&forceStream=1");
				so.addParam("movie", "http://banners.cams.com/images/cams/flash/cams_live.swf");
				so.addVariable("stagewidth", "155");
				so.addVariable("stageheight", "116");
				so.write(modelImage.attr('id'));
			}
		}
	}, function(){
		if ($(this).hasClass('modeldiv_free') == true) {
			$(this).removeClass('modeldiv_free_hover');
			var isFree = true;
		} else if ($(this).hasClass('modeldiv_nude') == true) {
			$(this).removeClass('modeldiv_nude_hover');
		} else if ($(this).hasClass('modeldiv_private') == true) {
			$(this).removeClass('modeldiv_private_hover');
		} else {
			$(this).removeClass('modeldiv_pornstar_hover');
		}

		if($(this).children("a.modelname").hasClass("has_long_name")){
			$(this).children("a.modelname").not("a.long_name").show();
			$(this).children("a.modelstatus").show();
			$(this).children("a.long_name").hide();
		}

		var modelImage = $(this).children("a.modelimage");
		var streamName = modelImage.attr('rel');
		if (streamName) {

			if ((streamName.length > 0) && (isFree == true)) {
				modelImage.html('');
			}
		}
	});

	/*
	$("a.modelrating").simpletip({
		fixed: true,
		position: 'right',
		onBeforeShow: function(){
			var rating_id = this.getParent().attr('id');
			var rating_vars = rating_id.split("_");
			var source = rating_vars[1];
			var stream = rating_vars[2];
			this.load('ratings_ajax.php?action=tooltip_ratings&stream='+stream+'&source='+source);
		}
	});
	*/

	$("a#toggle_filters").click(function(event){
		event.preventDefault();
		if ($("div#homepage_filters").css('display') == 'none') {
			$("#homepage_search").css('height','auto');
			$("div#homepage_filters").slideDown('medium');

			// change icon to minus
			$(this).html('<strong>-</strong> Hide Filters');
		} else {
			$("div#homepage_filters").slideUp('medium', function(){
				$("#homepage_search").css('height','41px');
			});

			// change icon to plus
			$(this).html('<strong>+</strong> Show Filters');
		}
	});

	$("select[name=sort_by]").change(function(){
		$("form[name=form_search]").submit();
	});

	$("#search_box").click(function(){
		var term = $(this).val();
		if (term == 'Search by Model Name') {
			$(this).val('');
		}
	});

	if ($("#show_ugly_controls").length > 0 ) {
		$("a.update_filtered").click(function(event){
			event.preventDefault();
			var fav_url = $(this).attr('href');
			var stream = $(this).attr('title');
			$("div #filtered_"+stream).html('<span class="small">Processing...</span>');
			$("div #filtered_"+stream).load(fav_url);
		});

		$('input.model-star').rating({
			callback: function(value, link){
				var name = $(this).attr('name');
				var rating_vars = name.split("_");
				var source = rating_vars[1];
				var stream = rating_vars[2];
				$.post('ratings_ajax.php', {
					rating: value,
					source: source,
					stream: stream
				});
			}
		});
	}
});