$(function() {
	refresh_songs();
	setInterval(function(){
		refresh_songs();
	}, 21000);
	$('#trenutnozvami').cycle({
		fx: 'fade',
		cleartypeNoBg: true,
		cleartype: true,
		speed: 400,
		timeout: 3000,
		next: '.modnaprej',
		prev: '.modnazaj',
		cleartype: 1,
		pause: 1
	});
	$('#carouselbannerwrapper').after('<div id="bannernav">').cycle({
		fx:	'fade',
		speed: 400,
		timeout: 6000,
		pager: '#bannernav',
		pause: 1
	});
	$('.poslusajradio').popupWindow({ 
		centerScreen:1,
		windowName: "OnlinePredvajalnik",
		width:490,
		height:365
	});
	$('.poslusajwebradio').popupWindow({ 
		centerScreen:1,
		windowName: "OnlineWebradioPredvajalnik",
		width:490,
		height:365
	});
	$("a[rel='galcbox']").colorbox({transition:"elastic", maxWidth:"75%", maxHeight:"75%"});
/*
 $("#trenutnozvamisklop").hover(function(){
        $(this).children(".modnazaj").slideDown('slow');
    },function(){
        $(this).children(".modnaprej").slideUp('slow');
    });
	
	 $("#trenutnozvamisklop").hover(
        function() {
        	alert("!!");
                $(".modnazaj", this).css("display", "block");
                $(".modnaprej", this).css("display", "block");
            },
            function() {
                $(".modnazaj", this).css("display", "none");
                $(".modnaprej", this).css("display", "none");
            }
    );
*/
	
	/*
	$("a[rel='colorbox']").colorbox({transition:"fade", maxWidth:"75%", maxHeight:"75%"});
	$("a[rel='example2']").colorbox({transition:"fade"});
	$("a[rel='example3']").colorbox({transition:"none", width:"75%", height:"75%"});
	$("a[rel='example4']").colorbox({slideshow:true});
	$(".example5").colorbox();
	$(".example6").colorbox({iframe:true, innerWidth:425, innerHeight:344});
	$(".example7").colorbox({width:"80%", height:"80%", iframe:true});
	$(".example8").colorbox({width:"50%", inline:true, href:"#inline_example1"});
	$(".example9").colorbox({
		onOpen:function(){ alert('onOpen: colorbox is about to open'); },
		onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
		onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); },
		onCleanup:function(){ alert('onCleanup: colorbox has begun the close process'); },
		onClosed:function(){ alert('onClosed: colorbox has completely closed'); }
	});
	*/
	$(".dvvote").click(function(){
		$.ajax({
		type: 'POST',
		dataType: 'json',
		url: 'moduli/glasuj.php',
		data: 'akcija=dvvote&idskladbe=' + $(this).attr('id'),
			success: function(html){
				if(html.akcija == "USPESNA"){
					$("#dialogi").dialog({
						bgiframe: true,
						resizable: false,
						//width: 300,
						//height:140,
						modal: true,
						overlay: {
							backgroundColor: '#000000',
							opacity: 0.5
						},
						title: html.naslovokna,
						buttons: {
							'Ok': function() {
								$(this).dialog('close');
							}
						},
						open:function() {
							$("#dialogvsebina").html(html.sporocilo);
						},
						close: function(){
							location.reload();
						}
					});
				}
			}
		});
	});
	$(".spvote").click(function(){
		$.ajax({
		type: 'POST',
		dataType: 'json',
		url: 'moduli/glasuj.php',
		data: 'akcija=spvote&idskladbe=' + $(this).attr('id'),
			success: function(html){
				if(html.akcija == "USPESNA"){
					$("#dialogi").dialog({
						bgiframe: true,
						resizable: false,
						//width: 300,
						//height:140,
						modal: true,
						overlay: {
							backgroundColor: '#000000',
							opacity: 0.5
						},
						title: html.naslovokna,
						buttons: {
							'Ok': function() {
								$(this).dialog('close');
							}
						},
						open:function() {
							$("#dialogvsebina").html(html.sporocilo);
						},
						close: function(){
							location.reload();
						}
					});
				}
			}
		});
	});
	$(".rbvote").click(function(){
		$.ajax({
		type: 'POST',
		dataType: 'json',
		url: 'moduli/glasuj.php',
		data: 'akcija=rbvote&idskupine=' + $(this).attr('id'),
			success: function(html){
				if(html.akcija == "USPESNA"){
					$("#dialogi").dialog({
						bgiframe: true,
						resizable: false,
						//width: 300,
						//height:140,
						modal: true,
						overlay: {
							backgroundColor: '#000000',
							opacity: 0.5
						},
						title: html.naslovokna,
						buttons: {
							'Ok': function() {
								$(this).dialog('close');
							}
						},
						open:function() {
							$("#dialogvsebina").html(html.sporocilo);
						},
						close: function(){
							location.reload();
						}
					});
				}
			}
		});
	});
	
	$(".xmasvote").click(function(){
		$.ajax({
		type: 'POST',
		dataType: 'json',
		url: 'moduli/glasuj.php',
		data: 'akcija=xmasvote&id=' + $(this).attr('id'),
			success: function(html){
				if(html.akcija == "USPESNA"){
					$("#dialogi").dialog({
						bgiframe: true,
						resizable: false,
						//width: 300,
						//height:140,
						modal: true,
						overlay: {
							backgroundColor: '#000000',
							opacity: 0.5
						},
						title: html.naslovokna,
						buttons: {
							'Ok': function() {
								$(this).dialog('close');
							}
						},
						open:function() {
							$("#dialogvsebina").html(html.sporocilo);
						},
						close: function(){
							location.reload();
						}
					});
				}
			}
		});
	});
	
	
	$(".premierevote").click(function(){
		$.ajax({
		type: 'POST',
		dataType: 'json',
		url: 'moduli/glasuj.php',
		data: 'akcija=premierevote&id=' + $(this).attr('id'),
			success: function(html){
				if(html.akcija == "USPESNA"){
					$("#dialogi").dialog({
						bgiframe: true,
						resizable: false,
						//width: 300,
						//height:140,
						modal: true,
						overlay: {
							backgroundColor: '#000000',
							opacity: 0.5
						},
						title: html.naslovokna,
						buttons: {
							'Ok': function() {
								$(this).dialog('close');
							}
						},
						open:function() {
							$("#dialogvsebina").html(html.sporocilo);
						},
						close: function(){
							location.reload();
						}
					});
				}
			}
		});
	});
	
	$("#trenutnozvami").hover(function(){
		        $(".navMod").slideDown('slow');
		    },function(){
		        $(".navMod").slideUp('slow');
		    });


	
});

function ShowControls(){
	$(".modnazaj").slideDown('slow');
    $(".modnaprej").slideDown('slow');
}

function HideControls(){
	$(".modnazaj").slideUp('slow');
    $(".modnaprej").slideUp('slow');
}


function uncache(url){
	var d = new Date();
	var time = d.getTime();
	return url + '&time='+time;
}
function refresh_songs(){
	$.ajax({
		type: 'POST',
		url: 'moduli/skladba.php',
		data: uncache('izpis=skladbe'),
		cache: false,
		error: function(xhr, status, errorThrown){
			$('#currentsong').html(errorThrown+'\n'+status+'\n'+xhr.statusText);
		},
		success: function(html){
			$('#currentsong').empty().html(html);
			$('#currentsong').cycle({
				fx: 'scrollDown',
				cleartypeNoBg: true,
				cleartype: true,
				speed: 400,
				timeout: 3500,
				next: '.currentsongeach',
				cleartypeNoBg: true,
				pause: 0
			});
		}
	});
}
function nalozi_predvajalnik(datoteka, next_player_id, trackartist, tracktitle){
	var flashvars = {
		artists: trackartist,
		titles: tracktitle,
		playerID: "player_container_"+next_player_id,
		bg: "0xF6F6F6",
		leftbg: "0x999999",
		lefticon: "0xF6F6F6",
		rightbg: "0x999999",
		rightbghover: "0xcccccc",
		righticon: "0xF6F6F6",
		righticonhover: "0x666666",
		text: "0x666666",
		slider: "0x666666",
		track: "0xFFFFFF",
		border: "0x666666",
		loader: "0x666666",
		loop: "no",
		autostart: "no",
		remaining: "yes",
		initialvolume: 30,
		soundFile: datoteka
	}
	var params = {
		menu: "false",
		wmode: "transparent"
	}
	var attributes = {
		id: "player_container_"+next_player_id,
		name: "player_container_"+next_player_id
	}
	swfobject.embedSWF("jquery/player/player.swf", "player_container_"+next_player_id, "290", "24", "9.0.0","expressInstall.swf", flashvars, params, attributes);
}
