jQuery.fn.ratings = function(stars, initialRating) {

  //Save  the jQuery object for later use.
  var elements = this;
  
  //Go through each object in the selector and create a ratings control.
  return this.each(function() {
  
    //Make sure intialRating is set.
    if(!initialRating)
      initialRating = 0;
      
    //Save the current element for later use.
    var containerElement = this;
    
    //grab the jQuery object for the current container div
    var container = jQuery(this);
    
    //Create an array of stars so they can be referenced again.
    var starsCollection = Array();
    
    //Save the initial rating.
    containerElement.rating = initialRating;
    
    //Set the container div's overflow to auto.  This ensure it will grow to
    //hold all of its children.
    container.css('overflow', 'auto');
    
    //create each star
    for(var starIdx = 0; starIdx < stars; starIdx++) {
      
      //Create a div to hold the star.
      var starElement = document.createElement('div');
      
      //Get a jQuery object for this star.
      var star = jQuery(starElement);
      
      //Store the rating that represents this star.
      starElement.rating = starIdx + 1;
      
      //Add the style.
      star.addClass('jquery-ratings-star');
      
      //Add the full css class if the star is beneath the initial rating.
      if(starIdx < initialRating) {
        star.addClass('jquery-ratings-full');
      }
      
      //add the star to the container
      container.append(star);
      starsCollection.push(star);
      
      //hook up the click event
      star.click(function() {
        //When clicked, fire the 'ratingchanged' event handler.  Pass the rating through as the data argument.
        elements.triggerHandler("ratingchanged", {rating: this.rating});
        containerElement.rating = this.rating;
      });
      
      star.mouseenter(function() {
        //Highlight selected stars.
        for(var index = 0; index < this.rating; index++) {
          starsCollection[index].addClass('jquery-ratings-full');
        }
        //Unhighlight unselected stars.
        for(var index = this.rating; index < stars; index++) {
          starsCollection[index].removeClass('jquery-ratings-full');
        }
      });
      
      container.mouseleave(function() {
        //Highlight selected stars.
        for(var index = 0; index < containerElement.rating; index++) {
          starsCollection[index].addClass('jquery-ratings-full');
        }
        //Unhighlight unselected stars.
        for(var index = containerElement.rating; index < stars ; index++) {
          starsCollection[index].removeClass('jquery-ratings-full');
        }
      });
    }
  });
};

function choices_nav(){
  window.location.href = jQuery("#choicelist").val();
}

function vote(object_id, number, object_type){
	var ajaxResponse= jQuery.ajax({
	    type: "POST",
	    url: "/"+object_type+"/ajax/"+object_id+"/rating/",
	    data: {rating:number},            
	    async: true,
	    statusCode: { 403: function() {alert('Už si hlasoval !'); } },

	}).responseText;	
}

function cloneMore(selector, type) {
    var newElement = jQuery(selector).clone(true);
    var total = jQuery('#id_' + type + '-TOTAL_FORMS').val();
    newElement.find(':input').each(function() {
        var name = jQuery(this).attr('name').replace('-' + (total-1) + '-','-' + total + '-');
        var id = 'id_' + name;
        jQuery(this).attr({'name': name, 'id': id}).val('').removeAttr('checked');
    });
    newElement.find('label').each(function() {
        var newFor = jQuery(this).attr('for').replace('-' + (total-1) + '-','-' + total + '-');
        jQuery(this).attr('for', newFor);
    });
    total++;
    jQuery('#id_' + type + '-TOTAL_FORMS').val(total);
    jQuery(selector).after(newElement);
}
jQuery(document).ready(function() {
	jQuery.each($(".rating"), function(i,item) {
		var id = jQuery(item).attr("id").split("_");
		jQuery(item).ratings(5,id[2]).bind('ratingchanged', function(event, data) {
	    	vote(id[1], data.rating, id[0]);
	    });
	});

});




                      


                
jQuery(document).ready(function() {
		     $("a.popup").fancybox({
       	'showCloseButton': false,
	      'titlePosition': 'inside',
	      'overlayColor'  : '#FFF',
	      'overlayOpacity' : 0.9,
	      'autoScale' : 'auto',
        'padding': 0,
       });

  
  $(".V").click(function() {
		$.fancybox({
		  'showCloseButton': false,
	    'titlePosition': 'inside',
	    'overlayColor'  : '#FFF',
	    'overlayOpacity' : 0.9,
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 640,
			'height'		: 385,
			'href' : this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1'),
			'type'			: 'swf',
			'swf'			: {
			'wmode'				: 'transparent',
			'allowfullscreen'	: 'true'
			}
		});
		return false;
	});
		$(".Y").click(function() {
		$.fancybox({
		  'showCloseButton': false,
	    'titlePosition': 'inside',
	    'overlayColor'  : '#FFF',
	    'overlayOpacity' : 0.9,
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 640,
			'height'		: 385,
			'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			'wmode'				: 'transparent',
			'allowfullscreen'	: 'true'
			}
		});
		return false;
	});
		
		$("#scroller").simplyScroll({
			className: 'vert',
			horizontal: false,
			frameRate: 40,
			speed: 5
		});		
});

