$(window).load(function() {
			
$("ul.sf-menu").superfish({ 
    hoverClass:    'sfHover',          // the class applied to hovered list items 
    pathClass:     'overideThisToUse', // the class you have applied to list items that lead to the current page 
    pathLevels:    1,                  // the number of levels of submenus that remain open or are restored using pathClass 
    delay:         800,                // the delay in milliseconds that the mouse can remain outside a submenu without it closing 
    animation:     {opacity:'show'},   // an object equivalent to first parameter of jQuery’s .animate() method 
    speed:         'normal',           // speed of the animation. Equivalent to second parameter of jQuery’s .animate() method 
    autoArrows:    false,               // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance 
    dropShadows:   true,               // completely disable drop shadows by setting this to false 
    disableHI:     false,              // set to true to disable hoverIntent detection 
    onInit:        function(){},       // callback function fires once Superfish is initialised – 'this' is the containing ul 
    onBeforeShow:  function(){},       // callback function fires just before reveal animation begins – 'this' is the ul about to open 
    onShow:        function(){},       // callback function fires once reveal animation completed – 'this' is the opened ul 
    onHide:        function(){}        // callback function fires after a sub-menu has closed – 'this' is the ul that just closed 
                    });

$("ul.sf-menu li").mouseover(function() {
	$(this).addClass('sfLiHover');
}).mouseout(function() {
	$(this).removeClass('sfLiHover');	
});

    $('#slider').nivoSlider({
        effect:'SlideInLeft', // Specify sets like: 'fold,fade,sliceDown'
                pauseTime:5000,
                pauseOnHover:false,
                controlNavThumbs:true
            });
                        
});


function SelectText(element) {
    var text = document.getElementById(element);
    if ($.browser.msie) {
        var range = document.body.createTextRange();
        range.moveToElementText(text);
        range.select();
    } else if ($.browser.mozilla || $.browser.opera) {
        var selection = window.getSelection();
        var range = document.createRange();
        range.selectNodeContents(text);
        selection.removeAllRanges();
        selection.addRange(range);
    } else if ($.browser.safari) {
        var selection = window.getSelection();
        selection.setBaseAndExtent(text, 0, text, 1);
    }
}



/* VOTING SYSTEM */
$(document).ready(function() {
	//basePath
	$('#rate-stars').raty({
		starOff: basePath + 'js/jquery.raty/img/star-off.png',
		starOn: basePath + 'js/jquery.raty/img/star-on.png',
		click: voteSend
	});
	
	$('.rate-results').each(function() {
		var that = $(this);
		$.post(basePath + 'voting/get/type:' + $(this).parent().attr('type') + '/item_id:' + $(this).parent().attr('item_id'), function(a) {
			if (a.votes > 0) {
				that.html('Average: ' + a.avg_rate + ' ('+ a.votes + ' votes)');
			} else {
				that.html('No votes yet');
			}
		}, 'json');
	});
	
	function voteSend(rate) {
		var that = $(this);
		var t = $(this).parent().find('.rate-results');
		$.post(basePath + 'voting/vote/type:' + $(this).parent().attr('type') + '/item_id:' + $(this).parent().attr('item_id') + '/rate:' + rate, function(a) {
			if (a.ok == 1) {
			t.html('You have successfully voted');
			setTimeout(function() {
				t.hide(1000, function() {
					t.html('Average: ' + a.avg_rate + ' ('+ a.votes + ' votes)');
					t.show(1000);
				});
			}, 2500);
			} else if (a.ok == 2) {
				t.html('You have already voted');
			} else {
				t.html('Please, <a href="' + basePath + 'users/login">login</a> to vote');
			}	
		}, 'json');
	}
	
$('.embed-link').click(function() {
   $(this).parent().find('.embedding-code').css('display', 'block');
   return false;
});
$('#embedding-code').click(function() {
    //SelectText('embedding-code');
   $('#embedding-code').focus().select();
});

});

/* END VOTING SYSTEM */
