


function shuffleArray (o)
{
   for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
   return o;
}

if(jQuery.browser.msie)
{
		try {
			document.execCommand( "BackgroundImageCache", false, true );
		} catch( e ) { };
}

var colorsOnAir = new Array('e1ccf5', 'f3cec8', 'faf4b6');

var timeoutCounter
var linkObj1
var lastOpenPopup


function showPopup(starter, id, additional) {
	if(additional) {
		if (!additional.top)
			additional.top = 0
		if (!additional.left)
			additional.left = 0
	}
	else {
		additional = {left: 0, top: 0}
	}
	positionStarter = $(starter).cumulativeOffset()
	jQuery("#" + id).css({
		top: positionStarter.top + additional.top + 10 + 'px',
		left: positionStarter.left + additional.left + 'px'
	})
	$(id).show()
	return false;
}

function closePopup(id) {
	jQuery('#' + id).hide()
}

function switchAuth(type) {
	jQuery('#' + type + '_our_auth').toggle()
	jQuery('#' + type + '_openid_auth').toggle()
}

function performDelete(href,liid) 
{
	   // alert(href);
	    jQuery.post(href, "", ajaxSuccess, 'json');
	    function ajaxSuccess(data) {
	        if (data.Done) {
	            //debugger;
	            jQuery("#" + liid).fadeOut(300);
	            //jQuery("#" + liid).remove();
	            closePopup('popup_delete_comment');
	        }
	        else {
	            alert(data.Error);
	        }
	    }
	

}

function hateComment(linkObj, name) 
{
	if (!name)
		name = 'Неизвестный'

	var li = jQuery(linkObj).parents("li");
	jQuery('#popup_delete_comment_user').html(name).parent().next().find('a:first').attr('href', "javascript:performDelete('"+linkObj.href+"','"+li[0].id+"');")
	jQuery('#popup_delete_comment_user').html(name).parent().next().find('a:first').click(function () { debugger; alert('dd'); });
    
    
		//.attr('href', linkObj.href)

	jQuery(li).siblings().css({zIndex: 1});
	jQuery(li).css({zIndex: 1000});
	jQuery("#popup_delete_comment").remove()
		.prependTo(jQuery(li))
		.css({top: jQuery(li).height() -5, left: 0})
		.show();

	return false
}

function delFeed(linkObj, feedId) 
{
	return askForDelete(linkObj, 'feed', 'ddd');
}






(function($) {

	$(function(){

		if($.browser.msie && parseInt($.browser.version) == 6)
		{
			$(".removable").hover(function(){ $(this).addClass("hover"); }, function(){ $(this).removeClass("hover"); });
		}

		/* - -----  -*/
		// если экран позволяет, не переносим строки в текстах

		if(typeof Nowrap !== "undefined")
		{
			var textWrap = new Nowrap();
			textWrap.makeNowrap();
		}


		if(!$.browser.safari)
		{
			if(typeof $.fn.TextAreaResizer == "function")
			{
				$('textarea.thik_song_description:not(.processed)').TextAreaResizer();
			}
		}
		/* - -----  -*/

		if($.browser.msie && $.browser.version == 6 )
		{
			$("ul.photo-list li").add("ul.photo-list-user li").add("div.photo_info").hover(function(){ $(this).addClass("hovered") }, function(){ $(this).removeClass("hovered") });
		}		
		
		$("ul.letters li:last-child").attr({id :"last"});
		$("ul.language").click(switchLetter);
		

	});

})(jQuery);

function switchLetter(e) {
	
	var letter = jQuery(e.target).addClass("active").siblings().removeClass("active").end().attr("rel");
	jQuery("ul.letters."+letter).show().siblings("ul.letters").hide();
	
	new Ajax.Request('/actions.html?action=toggle_letters&letter=' + letter + '& ' + Math.random(), {
		method: 'GET'
	})
}


function addZero(digit) {
	if(digit < 10) {
		digit = '0'+digit;
	}
	return digit;
}

function FlashStartPlay() {
	link = jQuery("link[rel='shortcut icon']").attr('href').replace('_play', '').replace('.ico', '_play.ico');
	jQuery("link[rel='shortcut icon']").remove();
	jQuery("head").append("<link rel='shortcut icon' href='" + link + "' />");
}

function FlashStopPlay() {
	link = jQuery("link[rel='shortcut icon']").attr('href').replace('_play.ico', '.ico');
	jQuery("link[rel='shortcut icon']").remove();
	jQuery("head").append("<link rel='shortcut icon' href='" + link + "' />");
}

function htmlspecialchars (str) {
	str = str.replace(/&/g, '&amp;');
	str = str.replace(/"/g, '&quot;');
	//str = str.replace("/'/g", "'");
	str = str.replace(/</g, '&lt;');
	return str.replace(/>/g, '&gt;');
}
