$(document).ready(function() {
	/*$("#drag-button").hover(
		function() {
			$("#drag-hint").show();
		},
		function() {
			$("#drag-hint").hide();
		}
	);*/
	
	$("#search").keyup(function(){
	if (this.value.length>=3) {
		var my = $("#searchbar").hasClass("privatesearch") ? 1 : 0;
		$.post(
			"/library/tag/filterTags/",
			{query:this.value, private:my},
			function (data) {
				$("#taglist").empty();
				if (data.tags.length>0) {
					$.each(data.tags, function(i, val) {
						$("#taglist").append('<div class="tag"><a href="/library/links/tags/&tag='+val.name+(my ? '&source=my' : '')+'" class="name">'+val.name+'</a><a href="#" class="num">'+val.c+'</a></div><div class="clear"></div>');
					});
				} else {
					$("#taglist").append('Nothing found!');
				}
			},
			"json"
		);
	}
	return false;
	});
	
	$('.auto-submit-star').rating({ 
		callback: function(val, link){ 
			$.post(
				"/library/rating/rate/",
				{value:val, media_id:this.name.substr(4)},
				function (data) {
					if (data.error!='') {
						alert(data.error)
					} else {
					}
				},
				"json"
			);
		} 
	});
	
	imagePreview();

});

function switchPrivate(i) {
	$.post(
		"/library/links/switchPrivate/",
			{id:i},
			function (data) {
				if (data.error!='')
					alert(data.error);
				else {
					if (data.public==1) {
						$("#switchPrivate"+i+" img").fadeOut();
						$("#switchPrivate"+i).attr('title', 'Make this link private');
						
						$("#switchPrivate"+i+" img").fadeIn();
						$("#switchPrivate"+i+" img").attr('src', '/img/unlock_16x16.gif');
					} else {
						$("#switchPrivate"+i+" img").fadeOut();
						$("#switchPrivate"+i).attr('title', 'Make this link public');
						
						$("#switchPrivate"+i+" img").fadeIn();
						$("#switchPrivate"+i+" img").attr('src', '/img/lock_16x16.gif');
					}
				}
			},
			"json"
		);
}


function onABCommComplete(data) {
	var emails = [];
	for (var i = 0; i < data.length; i++) {
		emails.push(data[i][1]);
	}
	document.getElementById('contacts').value = emails.join(',');
	document.getElementById('invite_form').submit();
}

function clearField(elem) {
	elem.value = '';
}

var loginclicked = 0;
function loginClick() {
	if (loginclicked==1)
		return false;
	else
		loginclicked = 1;
	if (confirm('Do you want your password to be remembered?')) {
		$("#remember").attr('value', 1);
		loginclicked=0;
	}
	else {
		$("#remember").attr('value', 0);
		loginclicked=0;
	}
}

function hidePasswdField(elem) {
	$("#realpasswd").html('<input tabindex="2" type="password" name="password" id="loginpassword" />');
	$("#loginpassword").focus();
	$("#loginpassword").focus();
}

function flash_notice(msg)
{
	$("#flash_error").text('');
	$("#flash_notice").text(msg);
	
}

function flash_error(msg)
{
	$("#flash_notice").text('');
	$("#flash_error").text(msg);
	
}

function checkCompatibility() {
	/* check for a cookie */
//	alert(document.cookie);
	if (document.cookie == "") {
		document.getElementById('cookieexists').value ="false";
		return;
	}
    
	var a_all_cookies = document.cookie.split( ';' );
	for ( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == 'testcookie' ) {
			document.getElementById('cookieexists').value ="true";
			return;
		}
	}
    document.getElementById('cookieexists').value ="false";
}



function showCountryInfo(value) {
	var el = document.getElementById('usInfo');
	var el2 = document.getElementById('internationalInfo');
	if(value == "us") {
		el.style.visibility = 'visible';
		el2.style.visibility = 'hidden';
	}else{
		el.style.visibility = 'hidden';
		el2.style.visibility = 'visible';
	}
	
}

function ajaxStatesToCity(value) {

	callback = function(response) {
		var cities = response.split(",");
		document.getElementById('city').length = 0;
		document.getElementById('city').options[0] = new Option("United States Cities","");
		for (i=0; i<cities.length; i++) {
			if (cities[i]!='') {
				city = cities[i].split("+");
				document.getElementById('city').options[i+1] = new Option(city[1],city[0]);
			}
		}
		document.getElementById("city").disabled = false;
	}
	req = new AjaxCall('POST', '/geo/city/getUSCity/', "state="+value, callback);
	req.execute();
	
}

function ajaxCitysToZip(value) {

	callback = function(response) {
		var zips = response.split(",");
		document.getElementById('zip').length = 0;
		document.getElementById('zip').options[0] = new Option("Zip Code","");
		for (i=0; i<zips.length; i++) {
			if (zips[i]!='') {
				zip = zips[i].split("+");
				document.getElementById('zip').options[i+1] = new Option(zip[1],zip[0]);
			}
		}
		document.getElementById("zip").disabled = false;
	}
	req = new AjaxCall('POST', '/geo/city/getZips/', "city="+value, callback);
	req.execute();

}

function ajaxCountryToCity(value) {

	callback = function(response) {
		var cities = response.split(",");
		document.getElementById('city_id').length = 0;
		document.getElementById('city_id').options[0] = new Option("Cities","");
		for (i=0; i<cities.length; i++) {
			if (cities[i]!='') {
				city = cities[i].split("+");
				document.getElementById('city_id').options[i+1] = new Option(city[1],city[0]);
			}
		}
		document.getElementById("city_id").disabled = false;
	}
	req = new AjaxCall('POST', '/geo/city/getCitiesByCountry/', "id="+value, callback);
	req.execute();

}

function updateURL(field) {

	var el = document.getElementById("newUrl"); 
	var el2 = document.getElementById("urlNum"); 
	
	if (field.value.length > 40) {
		field.value = field.value.substring(0, 40);
	}else{
		el2.innerHTML = 40 - field.value.length;
	}	
	
	s = new String(field.value.toLowerCase());
	s = s.replace(" ","_");
	s = s.replace("!","_");
	s = s.replace("@","_");
	s = s.replace("#","_");
	s = s.replace("$","_");
	s = s.replace("%","_");
	s = s.replace("^","_");
	s = s.replace("&","_");
	s = s.replace("*","_");
	s = s.replace("(","_");
	s = s.replace(")","_");
	s = s.replace("+","_");
	s = s.replace("=","_");
	s = s.replace("{","_");
	s = s.replace("}","_");
	s = s.replace("[","_");
	s = s.replace("]","_");
	s = s.replace("\\","_");
	s = s.replace("|","_");
	s = s.replace(":","_");
	s = s.replace(";","_");
	s = s.replace("\"","_");
	s = s.replace("'","_");
	s = s.replace("<","_");
	s = s.replace(">","_");
	s = s.replace(",","_");
	s = s.replace("/","_");
	s = s.replace("?","_");
	s = s.replace("`","_");
	s = s.replace("~","_");
	el.innerHTML = s;
	field.value = s;

}

function ajaxCheckProfileAvail(url) {

	callback = function(response) {
		var el = document.getElementById("urlCheck");
		if(response == '0'){
			el.innerHTML = "sorry already taken.";
		}else{
			el.innerHTML = "you are all good!";
		}
	}

	var url = document.getElementById("profileURL").value;
	req = new AjaxCall('POST', '/profile/profile/isFree/', "name="+url, callback);
	req.execute();

}

function getFormVars(var_names) {
	for (i=0; i<var_names.length; i++)
		var_names[i] = var_names[i]+'='+document.getElementById(var_names[i]).value;
	return var_names.join('&');
}

function saveAlbumDescr(album_id) {
	
	callback = function(response) {
		if (response.substr(0, 6)=='error:') 
			$("#item_"+album_id+"_msg").text(response.substr(6,response.length-6));
		if (response.substr(0, 7)=='notice:') 
			$("#item_"+album_id+"_msg").text(response.substr(7,response.length-7));
		$("#item_"+album_id+"_msg").slideDown("slow");
		window.setTimeout('hideItemNotice("'+"item_"+album_id+"_msg"+'");', 2000);
	}
	
	//var fields = new Array('album_title_'+album_id, 'album_descr_'+album_id, 'album_permissions_'+album_id);
	req = new AjaxCall('POST', '/photos/my_gallery/updateAlbum/', 'album_id='+album_id+'&album_title='+document.getElementById('album_title_'+album_id).value+'&album_descr='+document.getElementById('album_descr_'+album_id).value+'&album_permissions='+document.getElementById('album_permissions_'+album_id).value, callback);
	req.execute();
}

function hideItemNotice(item_id) {
	$("#"+item_id).hide("slow");
}

function savePhotoDescr(photo_id) {
	
	callback = function(response) {
		if (response.substr(0, 6)=='error:') 
			$("#item_"+photo_id+"_msg").text(response.substr(6,response.length-6));
		if (response.substr(0, 7)=='notice:') 
			$("#item_"+photo_id+"_msg").text(response.substr(7,response.length-7));
		$("#item_"+photo_id+"_msg").slideDown("slow");
		window.setTimeout('hideItemNotice("'+"item_"+photo_id+"_msg"+'");', 2000);
	}
	
	req = new AjaxCall('POST', '/photos/my_gallery/updatePhoto/', 'photo_id='+photo_id+'&photo_title='+document.getElementById('photo_title_'+photo_id).value+'&photo_descr='+document.getElementById('photo_descr_'+photo_id).value, callback);
	req.execute();
}

/*
function deleteAlbumPhoto(photo_id) {
	
	callback = function(response) {
		if (response.substr(0, 6)=='error:') 
			flash_error(response.substr(6,response.length-6));
		if (response.substr(0, 7)=='notice:') 
			flash_notice(response.substr(7,response.length-7));
	}
	
	req = new AjaxCall('POST', '/photos/my_gallery/deletePhoto/', 'photo_id='+photo_id, callback);
	req.execute();
}
*/

function setPhotoAsAlbumCover(photo_id) {
	
	callback = function(response) {
		if (response.substr(0, 6)=='error:') 
			$("#item_"+photo_id+"_msg").text(response.substr(6,response.length-6));
		if (response.substr(0, 7)=='notice:')
			$("#item_"+photo_id+"_msg").text(response.substr(7,response.length-7));
		$("#item_"+photo_id+"_msg").slideDown("slow");
		window.setTimeout('hideItemNotice("'+"item_"+photo_id+"_msg"+'");', 2000);
	}
	
	req = new AjaxCall('POST', '/photos/my_gallery/setAlbumCover/', 'photo_id='+photo_id, callback);
	req.execute();
}

function setPhotoAsProfileImage(photo_id) {
	
	callback = function(response) {
		if (response.substr(0, 6)=='error:')
			$("#item_"+photo_id+"_msg").text(response.substr(6,response.length-6));
		if (response.substr(0, 7)=='notice:')
			$("#item_"+photo_id+"_msg").text(response.substr(7,response.length-7));
		$("#item_"+photo_id+"_msg").slideDown("slow");
		window.setTimeout('hideItemNotice("'+"item_"+photo_id+"_msg"+'");', 2000);
	}
	
	req = new AjaxCall('POST', '/photos/my_gallery/setProfileImage/', 'photo_id='+photo_id, callback);
	req.execute();
}




function searchUsersByName(text) {
	
	if (text.length<3) {
		document.getElementById('users_list').innerHTML = '';
		return;
	}

	callback = function(response) {
		if (response.substr(0, 6)=='error:')  {
		} else 
			if (response.substr(0, 5)=='empty')
				document.getElementById('users_list').innerHTML = '';
			else
				document.getElementById('users_list').innerHTML = response;
	}
	
	req = new AjaxCall('POST', '/users/users/findByName/', 'search='+text, callback);
	req.execute();
}

function resetSearchByName() {
	document.getElementById('users_list').innerHTML = '';
	document.getElementById('search_string').value = '';
}

function savePictureComment(picture_id) {
	callback = function(response) {
		location.href = '/photos/gallery/viewPhoto/&id='+picture_id;
	}
	
	req = new AjaxCall('POST', '/photos/gallery/savePictureComment/', 'photo_id='+picture_id+'&comment='+document.getElementById('add_comment').value, callback);
	req.execute();
}

function cat_switch(menu,image) {//
	nameDiv=document.getElementById(menu);
	myimage=document.getElementById(image);
	if (nameDiv.style.display=='none') {
		nameDiv.style.display='block';
		myimage.src='/images/test/minus.gif';
	} else {
		nameDiv.style.display='none';
		myimage.src='/images/test/plus.gif';
	}
}

function switchPermSet(value) {
	if (value==1)
		document.getElementById('permissions').style.display = 'none';
	else
		document.getElementById('permissions').style.display = 'block';
}

/* aqTip v1.1 - Pop up a box next to the object the mouse is currently pointing to.
   Copyright (C) 2008 Paul Pham <http://aquaron.com/~jquery/aqTip>

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
(function($){
$.fn.aqTip = function(html,options) {
   var opts = $.extend({}, $.fn.aqTip.defaults, options);

   return this.each(function() {
      var $obj = $(this);

      $('<div class="aqTip"><\/div>').appendTo($obj);

      var $layer = $('.aqTip',$obj);

      $layer.css({ display: 'none', position: 'absolute' }).css(opts.css);

      if (jQuery.isFunction(html)) html($layer);
      else $layer.html(html);

      var p = $obj.position();
      var ow = $obj.width() > $layer.width() 
         ? $obj.width() : $layer.width();
      var x = p.left + ow + opts.marginX;
      if (x > document.body.clientWidth)
         x = p.left - ow - opts.marginX;

      $layer.css({ left: x+'px', top: p.top+opts.marginY+'px' });

      $obj.hover(function(){$layer.show()}, function(){$layer.hide()});
   });
};

$.fn.aqTipOne = function(html,options) {
   var opts = $.extend({}, $.fn.aqTip.defaults, options);
   return this.each(function() {
      if (!$('#aqTip').length) {
         $('<div id="aqTip"><\/div>').appendTo(document.body);
         $('#aqTip').css({ display: 'none', position: 'absolute' })
            .css(opts.css);
      }

      var $obj = $(this);
      if (html) {
         $('#aqTip').html(html);

         var p = $obj.position();
         var ow = $obj.width() > $('#aqTip').width() 
            ? $obj.width():$('#aqTip').width();
         var x = p.left + ow + opts.marginX;
         if (x > document.body.clientWidth)
            x = p.left - ow - opts.marginX;

         $('#aqTip').show()
            .css({ left: x+'px', top: p.top+opts.marginY+'px' })
      } else
         $('#aqTip:visible').hide()

      return false;
   });
};

$.fn.aqTip.defaults = { 
   marginX: 10, marginY: 10, 
   css: { 
      backgroundColor: '#fff', color: '#444',
      border: '1px solid #ddd', padding: '5px' }
};
})(jQuery);

function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;

//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += "    ";

if(typeof(arr) == 'object') { //Array/Hashes/Objects
 for(var item in arr) {
  var value = arr[item];
 
  if(typeof(value) == 'object') { //If it is an array,
   dumped_text += level_padding + "'" + item + "' ...\n";
   dumped_text += dump(value,level+1);
  } else {
   dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
  }
 }
} else { //Stings/Chars/Numbers etc.
 dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
} 

/*
 ### jQuery Star Rating Plugin v2.5 - 2008-09-10 ###
 * http://www.fyneworks.com/ - diego@fyneworks.com
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 ###
 Project: http://plugins.jquery.com/project/MultipleFriendlyStarRating
 Website: http://www.fyneworks.com/jquery/star-rating/
*//*
	Based on http://www.phpletter.com/Demo/Jquery-Star-Rating-Plugin/
 Original comments:
	This is hacked version of star rating created by <a href="http://php.scripts.psu.edu/rja171/widgets/rating.php">Ritesh Agrawal</a>
	It thansform a set of radio type input elements to star rating type and remain the radio element name and value,
	so could be integrated with your form. It acts as a normal radio button.
	modified by : Logan Cai (cailongqun[at]yahoo.com.cn)
*/

/*# AVOID COLLISIONS #*/
;if(window.jQuery) (function($){
/*# AVOID COLLISIONS #*/
	
	// IE6 Background Image Fix
	if ($.browser.msie) try { document.execCommand("BackgroundImageCache", false, true)} catch(e) { }
	// Thanks to http://www.visualjquery.com/rating/rating_redux.html
	
	// default settings
	$.rating = {
		cancel: 'Cancel Rating',   // advisory title for the 'cancel' link
		cancelValue: '',           // value to submit when user click the 'cancel' link
		split: 0,                  // split the star into how many parts?
		
		// Width of star image in case the plugin can't work it out. This can happen if
		// the jQuery.dimensions plugin is not available OR the image is hidden at installation
		starWidth: 14,
		
		//NB.: These don't need to be defined (can be undefined/null) so let's save some code!
		//half:     false,         // just a shortcut to settings.split = 2
		required: true,         // disables the 'cancel' button so user can only select one of the specified values
		//readOnly: false,         // disable rating plugin interaction/ values cannot be changed
		//focus:    function(){},  // executed when stars are focused
		//blur:     function(){},  // executed when stars are focused
		//callback: function(){},  // executed when a star is clicked
		
		// required properties:
		groups: {},// allows multiple star ratings on one page
		event: {// plugin event handlers
			fill: function(n, el, settings, state){ // fill to the current mouse position.
				//if(window.console) console.log(['fill', $(el), $(el).prevAll('.star_group_'+n), arguments]);
				this.drain(n);
				$(el).prevAll('.star_group_'+n).andSelf().addClass('star_'+(state || 'hover'));
				// focus handler, as requested by focusdigital.co.uk
				var lnk = $(el).children('a'); val = lnk.text();
				if(settings.focus) settings.focus.apply($.rating.groups[n].valueElem[0], [val, lnk[0]]);
			},
			drain: function(n, el, settings) { // drain all the stars.
				//if(window.console) console.log(['drain', $(el), $(el).prevAll('.star_group_'+n), arguments]);
				$.rating.groups[n].valueElem.siblings('.star_group_'+n).removeClass('star_on').removeClass('star_hover');
			},
			reset: function(n, el, settings){ // Reset the stars to the default index.
				if(!$($.rating.groups[n].current).is('.cancel'))
					$($.rating.groups[n].current).prevAll('.star_group_'+n).andSelf().addClass('star_on');
				// blur handler, as requested by focusdigital.co.uk
				var lnk = $(el).children('a'); val = lnk.text();
				if(settings.blur) settings.blur.apply($.rating.groups[n].valueElem[0], [val, lnk[0]]);
			},
			click: function(n, el, settings){ // Selected a star or cancelled
				$.rating.groups[n].current = el;
				var lnk = $(el).children('a'); val = lnk.text();
				// Set value
				$.rating.groups[n].valueElem.val(val);
				// Update display
				$.rating.event.drain(n, el, settings);
				$.rating.event.reset(n, el, settings);
				// click callback, as requested here: http://plugins.jquery.com/node/1655
				if(settings.callback) settings.callback.apply($.rating.groups[n].valueElem[0], [val, lnk[0]]);
			}      
		}// plugin events
	};
	
	$.fn.rating = function(instanceSettings){
		if(this.length==0) return this; // quick fail
		
		instanceSettings = $.extend(
			{}/* new object */,
			$.rating/* global settings */,
			instanceSettings || {} /* just-in-time settings */
		);
		
		// loop through each matched element
		this.each(function(i){
			
			var settings = $.extend(
				{}/* new object */,
				instanceSettings || {} /* current call settings */,
				($.metadata? $(this).metadata(): ($.meta?$(this).data():null)) || {} /* metadata settings */
			);
			
			////if(window.console) console.log([this.name, settings.half, settings.split], '#');
			
			// Generate internal control ID
			// - ignore square brackets in element names
			var n = (this.name || 'unnamed-rating').replace(/\[|\]/, "_");
   
			// Grouping
			if(!$.rating.groups[n]) $.rating.groups[n] = {count: 0};
			i = $.rating.groups[n].count; $.rating.groups[n].count++;
			
			// Accept readOnly setting from 'disabled' property
			$.rating.groups[n].readOnly = $.rating.groups[n].readOnly || settings.readOnly || $(this).attr('disabled');
			
			// Things to do with the first element...
			if(i == 0){
				// Create value element (disabled if readOnly)
				$.rating.groups[n].valueElem = $('<input type="hidden" name="' + n + '" value=""' + (settings.readOnly ? ' disabled="disabled"' : '') + '/>');
				// Insert value element into form
				$(this).before($.rating.groups[n].valueElem);
				
				if($.rating.groups[n].readOnly || settings.required){
					// DO NOT display 'cancel' button
				}
				else{
					// Display 'cancel' button
					$(this).before(
						$('<div class="cancel"><a title="' + settings.cancel + '">' + settings.cancelValue + '</a></div>')
						.mouseover(function(){ $.rating.event.drain(n, this, settings); $(this).addClass('star_on'); })
						.mouseout(function(){ $.rating.event.reset(n, this, settings); $(this).removeClass('star_on'); })
						.click(function(){ $.rating.event.click(n, this, settings); })
					);
				}
			}; // if (i == 0) (first element)
			
			// insert rating option right after preview element
			eStar = $('<div class="star"><a title="' + (this.title || this.value) + '">' + this.value + '</a></div>');
			$(this).after(eStar);
			
			// Half-stars?
			if(settings.half) settings.split = 2;
			
			// Prepare division settings
			if(typeof settings.split=='number' && settings.split>0){
				var stw = ($.fn.width ? $(eStar).width() : 0) || settings.starWidth;
				var spi = (i % settings.split), spw = Math.floor(stw/settings.split);
				$(eStar)
				// restrict star's width and hide overflow (already in CSS)
				.width(spw)
				// move the star left by using a negative margin
				// this is work-around to IE's stupid box model (position:relative doesn't work)
				.find('a').css({ 'margin-left':'-'+ (spi*spw) +'px' })
			};
			
			// Remember group name so controls within the same container don't get mixed up
			$(eStar).addClass('star_group_'+n);
			
			// readOnly?
			if($.rating.groups[n].readOnly)//{ //save a byte!
				// Mark star as readOnly so user can customize display
				$(eStar).addClass('star_readonly');
			//}  //save a byte!
			else//{ //save a byte!
				$(eStar)
				// Enable hover css effects
				.addClass('star_live')
				// Attach mouse events
				.mouseover(function(){ $.rating.event.drain(n, this, settings); $.rating.event.fill(n, this, settings, 'hover'); })
				.mouseout(function(){ $.rating.event.drain(n, this, settings); $.rating.event.reset(n, this, settings); })
				.click(function(){ $.rating.event.click(n, this, settings); });
			//}; //save a byte!
			
			////if(window.console) console.log(['###', n, this.checked, $.rating.groups[n].initial]);
			if(this.checked) $.rating.groups[n].current = eStar;
			
			//remove this checkbox
			$(this).remove();
			
			// reset display if last element
			if(i + 1 == this.length) $.rating.event.reset(n, this, settings);
		
		}); // each element
			
		// initialize groups...
		for(n in $.rating.groups)//{ not needed, save a byte!
			(function(c, v, n){ if(!c) return;
				$.rating.event.fill(n, c, instanceSettings || {}, 'on');
				$(v).val($(c).children('a').text());
			})
			($.rating.groups[n].current, $.rating.groups[n].valueElem, n);
		//}; not needed, save a byte!
		
		return this; // don't break the chain...
	};
	
	
	
	/*
		### Default implementation ###
		The plugin will attach itself to file inputs
		with the class 'multi' when the page loads
	*/
	$(function(){ $('input[@type=radio].star').rating(); });
	
	
	
/*# AVOID COLLISIONS #*/
})(jQuery);
/*# AVOID COLLISIONS #*/


this.imagePreview = function(){	
	/* CONFIG */
		xOffset = 10;
		yOffset = 30;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
	/* END CONFIG */

	$("a.preview").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? '<br />' + this.t  : "";
		$("body").append("<p id='preview'><img src='"+ this.rel +"' alt='Image preview' />"+ c +"</p>");
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },

	function(){
		this.title = this.t;	
		$("#preview").remove();
    });	

	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};