jQuery(document).ready(function() {

	var playItem = 0;

	var myPlayList = [
		{name:"В Глубине Кривых Зеркал",mp3:"/mp3/playlist/VGKZ.mp3"},			
		{name:"И Кто Теперь?",mp3:"/mp3/playlist/IKT.mp3"},		
		{name:"Один Закон",mp3:"/mp3/playlist/OZ.mp3"},		
		{name:"Set The World On Fire (E-Type cover)",mp3:"/mp3/playlist/E-TYPE.mp3"},					
		{name:"Боги Не Слышат Нас",mp3:"/mp3/playlist/BNSN.mp3"},		
		{name:"Воля и Разум (\"Ария\"-cover)",mp3:"/mp3/playlist/VIR.mp3"},				
		{name:"День За Днём",mp3:"/mp3/playlist/01-DZD.mp3"},
		{name:"Нет Пощады",mp3:"/mp3/playlist/07-NP.mp3"},
		{name:"В Эту Ночь",mp3:"/mp3/playlist/09-VeN.mp3"},		
		{name:"Там (Где Всё Будет Иначе)",mp3:"/mp3/playlist/06-TAM.mp3"},			
		{name:"Demolishing The Ruins",mp3:"/mp3/playlist/DTR.mp3"},				
		{name:"Icons Of The Past",mp3:"/mp3/playlist/IOTP.mp3"},				
		{name:"Synthetic Masterpiece",mp3:"/mp3/playlist/SM.mp3"}
	];
	jQuery("#jquery_jplayer").jPlayer({
		ready: function() {
			displayPlayList();
			playListInit(false); // Parameter is a boolean for autoplay.
		},
		volume: 50
	})
	.jPlayerId("play", "player_play")
	.jPlayerId("pause", "player_pause")
	.jPlayerId("stop", "player_stop")
	.jPlayerId("loadBar", "player_progress_load_bar")
	.jPlayerId("playBar", "player_progress_play_bar")
	.jPlayerId("volumeMin", "player_volume_min")
	.jPlayerId("volumeMax", "player_volume_max")
	.jPlayerId("volumeBar", "player_volume_bar")
	.jPlayerId("volumeBarValue", "player_volume_bar_value")
	.onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		var myPlayedTime = new Date(playedTime);
		var ptMin = (myPlayedTime.getUTCMinutes() < 10) ? "0" + myPlayedTime.getUTCMinutes() : myPlayedTime.getUTCMinutes();
		var ptSec = (myPlayedTime.getUTCSeconds() < 10) ? "0" + myPlayedTime.getUTCSeconds() : myPlayedTime.getUTCSeconds();
		jQuery("#play_time").text(ptMin+":"+ptSec);

		var myTotalTime = new Date(totalTime);
		var ttMin = (myTotalTime.getUTCMinutes() < 10) ? "0" + myTotalTime.getUTCMinutes() : myTotalTime.getUTCMinutes();
		var ttSec = (myTotalTime.getUTCSeconds() < 10) ? "0" + myTotalTime.getUTCSeconds() : myTotalTime.getUTCSeconds();
		jQuery("#total_time").text(ttMin+":"+ttSec);
	})
	.onSoundComplete( function() {
		playListNext();
	});

	jQuery("#ctrl_prev").click( function() {
		playListPrev();
		return false;
	});

	jQuery("#ctrl_next").click( function() {
		playListNext();
		return false;
	});

	function displayPlayList() {
		jQuery("#playlist_list ul li").remove();
		for (i=0; i < myPlayList.length; i++) {
			jQuery("#playlist_list ul").append("<li id='playlist_item_"+i+"'>"+ myPlayList[i].name +"</li>");
			jQuery("#playlist_item_"+i).data( "index", i ).hover(
				function() {
					if (playItem != jQuery(this).data("index")) {
						jQuery(this).addClass("playlist_hover");
					}
				},
				function() {
					jQuery(this).removeClass("playlist_hover");
				}
			).click( function() {
				var index = jQuery(this).data("index");
				if (playItem != index) {
					playListChange( index );
				}
			});
		}
	}
	
	function playListInit(autoplay) {
		if(autoplay) {
			playListChange( playItem );
		} else {
			playListConfig( playItem );
		}
	}

	function playListConfig( index ) {
		jQuery("#playlist_item_"+playItem).removeClass("playlist_current");
		jQuery("#playlist_item_"+index).addClass("playlist_current");
		playItem = index;
		jQuery("#jquery_jplayer").setFile(myPlayList[playItem].mp3, myPlayList[playItem].ogg);
	}

	function playListChange( index ) {
		playListConfig( index );
		jQuery("#jquery_jplayer").play();
	}

	function playListNext() {
		var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
		playListChange( index );
	}

	function playListPrev() {
		var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
		playListChange( index );
	}
	
	jQuery("#playlist0").click( function() {
		playListConfig( 0 );
		jQuery("#jquery_jplayer").play();
	});

	jQuery("#playlist1").click( function() {
		playListConfig( 1 );
		jQuery("#jquery_jplayer").play();
	});
	
	jQuery("#playlist2").click( function() {
		playListConfig( 2 );
		jQuery("#jquery_jplayer").play();	
	});	
	
	jQuery("#playlist2").click( function() {
		playListConfig( 2 );
		jQuery("#jquery_jplayer").play();	
	});		

	jQuery("#playlist3").click( function() {
		playListConfig( 3 );
		jQuery("#jquery_jplayer").play();	
	});	

	jQuery("#playlist4").click( function() {
		playListConfig( 4 );
		jQuery("#jquery_jplayer").play();	
	});	

	jQuery("#playlist5").click( function() {
		playListConfig( 5 );
		jQuery("#jquery_jplayer").play();	
	});	

	jQuery("#playlist6").click( function() {
		playListConfig( 6 );
		jQuery("#jquery_jplayer").play();	
	});		

	jQuery("#playlist7").click( function() {
		playListConfig( 7 );
		jQuery("#jquery_jplayer").play();	
	});		
	
	jQuery("#playlist8").click( function() {
		playListConfig( 8 );
		jQuery("#jquery_jplayer").play();	
	});			
	
	jQuery("#playlist9").click( function() {
		playListConfig( 9 );
		jQuery("#jquery_jplayer").play();	
	});		

	jQuery("#playlist10").click( function() {
		playListConfig( 10 );
		jQuery("#jquery_jplayer").play();	
	});		
	
	jQuery("#playlist11").click( function() {
		playListConfig( 11 );
		jQuery("#jquery_jplayer").play();	
	});			
	
	jQuery("#playlist12").click( function() {
		playListConfig( 12 );
		jQuery("#jquery_jplayer").play();	
	});			
	
  jQuery('#gotop').click(function() {
    go_top();
    return false;
  });


  fancybox_init();
  comment_smiles();

});


function fancybox_init () {
    jQuery.fn.getTitle = function() {
      var arr = jQuery("a.fancybox");
      jQuery.each(arr, function() {
        var title = jQuery(this).children("img").attr("title");
        jQuery(this).attr('title',title);
      })
    }
    var thumbnails = 'a:has(img)[href$=".bmp"],a:has(img)[href$=".gif"],a:has(img)[href$=".jpg"],a:has(img)[href$=".jpeg"],a:has(img)[href$=".png"],a:has(img)[href$=".BMP"],a:has(img)[href$=".GIF"],a:has(img)[href$=".JPG"],a:has(img)[href$=".JPEG"],a:has(img)[href$=".PNG"]';
    jQuery(thumbnails).addClass("fancybox").attr("rel","fancybox").getTitle();	
    jQuery("a.fancybox").fancybox({
      'imageScale': true,
      'padding': 10,
      'zoomOpacity': true,
      'zoomSpeedIn': 500,
      'zoomSpeedOut': 500,
      'overlayShow': true,
      'overlayOpacity': 0.3,
      'hideOnContentClick': false,
      'centerOnScroll': true
    });

}


jQuery.fn.appendVal = function(txt) {
   return this.each(function(){
       this.value += txt;
   });
};

function go_top (comment_id) {
    jQuery((window.opera) ? tbody = 'html' : 'html, body').animate({ scrollTop: 0 }, 1000);
}

function comment_quote (comment_id) {
  comment_author = jQuery('#commentauthor-'+comment_id).text();
  quotebody = jQuery('#commentbody-'+comment_id).text();
  quotebody = quotebody.replace(/(^\s+)|(\s+$)/g, "");
  quotebody = "[quote id="+comment_id+"]"+quotebody+"[/quote]\n";
  jQuery('#comment').appendVal(quotebody);
  jQuery('#comment').focus();
  return false;
}


function comment_append(txt) {
  jQuery('#comment').appendVal(txt);
  jQuery('#comment').focus();
  return false;
} 

function email ()
{
  eml = 'ur.tsolreveindahousednab';
  eml = eml.replace('in'+'da'+'ho'+'use', '@');
  splitext = eml.split("");
  revertext = splitext.reverse();
  eml = revertext.join("");
  return eml;
}

function email2 ()
{
  eml = 'ur.tsolreveindahouseyub';
  eml = eml.replace('in'+'da'+'ho'+'use', '@');
  splitext = eml.split("");
  revertext = splitext.reverse();
  eml = revertext.join("");
  return eml;
}
