var aplication = "/si/ajax/";


function PostNewsComment() {
	var comment = jQuery.trim($("textarea#comment").val());
	var news_id = $("input[name='news_id']").val();
	
	//Post novice 
	$.post(aplication, {  go_add_comment : 1,
	 					  comment: comment, 
	 					  news: news_id },
   		function(data){
     		$("b#warning").html(data);
  		});
}
function getCommentNews(nid, nid2) {
	$.post(aplication, {  go_comment : 1,
	 					  news: nid, 
	 					  page: nid2 },
   		function(data){
     		$("div#comments").html(data);
  		});	
}
function isArticleUseful(nid) {
    //alert($("input[name='opinion']:checked").val());
	$.post(aplication, {  go_useful : 1,
	 					  news: nid, 
	 					  val: $("input[name='opinion']:checked").val() },
   		function(data){
     		$('body').append(data);
  		});	
}

$(function(){
	var IsReadOnly = false;
	if ($("input[name='ratio_disabled']").size()) {
		IsReadOnly = true;
	}
	
 	$('input[type=radio].star').rating({half:true,
 		                                split:2,
 		                                readOnly:IsReadOnly,
 		                                required: true,
 		                                callback: function(){
 		                                	//alert($(this).val());
 		                                	var news_id = $("input[name='news_id']").val();
		                                	$.post(aplication, {  go_rating : 1,
											 					  news: news_id, 
											 					  ratio: $(this).val() },
										   		function(data){
										     		//$("div#comments").html(data);
										     		//alert(data);
										     		$("div#news_mark").html(data);
									     		});	
 		                                }
	});
	
	
	$('#goRightBig').click(
		function () {
			$("#goLeftBig").show();
			var item = $("#big-image img").attr("rel");
			item = item.split('_');
			var javascript = $("#" + "image_" + (parseInt(item[1])+1)).attr("href");	
			javascript = javascript.split('Javascript: ');
			$('body').append('<script type="text/javascript">'+ javascript[1] + '</script>');
			if ($("#" + "image_" + (parseInt(item[1])+2)).size() == 0) {
				$(this).hide();
			}
	    });
	
	$('#goLeftBig').click(
		function () {
			
			$("#goRightBig").show();
			var item = $("#big-image img").attr("rel");
			item = item.split('_');
			var javascript = $("#" + "image_" + (parseInt(item[1])-1)).attr("href");	
			javascript = javascript.split('Javascript: ');
			$('body').append('<script type="text/javascript">'+ javascript[1] + '</script>');
	
			if (parseInt(item[1]) == 1) {
				$(this).hide();
			}
	    });
	    
	//Slike sliding
	if ($('#photo-gallery').size() > 0) {
    	$('#photo-gallery').cycle({
            fx:      'scrollHorz',
            timeout:  0,
            prev:    '#goLeft',
            next:    '#goRight'
        });  
    }
    
    if ($('#slide-hot-news').size() > 0) {
        $('#slide-hot-news').cycle({
            timeout:  2000,
            fx:      'scrollLeft',
            speed: 3000
        }); 
    }
	
	
	
	
});


//photo-gallery
function viewNewsImage(image, title, author, num) {
	var html = '<img src="/images/image.gif?type=gallery&amp;cimage='+image+'&amp;size=750&amp;h_size=475" alt="'+title+'" rel="image_'+num+'"/><br />'+author;	
	$("#big-image").html(html);
	$("#goRightBig").show();
	$("#goLeftBig").show();
	//Prikaz oz. odstranitev gumbov za back pa next
	if (num == 0) {
		$("#goLeftBig").hide();
		if ($("#photo-gallery a").size() > 0) {
			$("#goRightBig").show();	
		}
		else {
			$("#goRightBig").hide();	
		}
	}
	
	if ((num+1) == $("#photo-gallery a").size()) {
		$("#goRightBig").hide();
		if ($("#photo-gallery a").size() > 1) {
			$("#goLeftBig").show()	
		}
	}
}
function LoginFrom(){
    $("div#login_post").html('<img src="/static/images/loading_small.gif">');
    $.post(aplication, { user_name: $("input[name='user_name']").val(), 
                         user_pass: $("input[name='user_password']").val() },
    function(data){
        $("div#login_post").html(data);
    });
}

function slideDown() {
    $("div#loginFrom").slideToggle();
}

function LostPassword() {
    var html = $("#lostPasswordFrom").html();
    $("#process").html(html);
    $("#lostPasswordFrom").remove();
}
function LostPasswordFrom() {
    //alert($("input[name='opinion']:checked").val());
    $("div#password_post").html('<img src="/static/images/loading_small.gif">');
	$.post(aplication, {  go_lost_password : 1, 
	 					  val: $("input[name='email']").val() },
   		function(data){
     		$('#password_post').html(data);
     		$("input[name='email']").val("")
  		});	    
}

function RemoveParentSpan() {
	$("a[class='remove-flv']").click(
		function() {
			$(this).parent("span").remove();
			if ($(this).attr("rel") == "flv") {
				$("#upload_1").show();
			}
		});	
}


$(function(){
	if ($("#upload_1").size()>0) {
        //Uplaod video
    	new AjaxUpload('upload_1', 
    		{
    			action: aplication,
    			/*autoSubmit: false,*/
    			data: {
        			attachment  : '1'
      			},
    
    			onSubmit: function(file, extension) {
    				if ((extension && /^(flv)$/.test(extension))) {
    					$(".loading-upload-1").html('<img src="/static/images/ajax-loader-e-neo.gif" alt="Nalagam.." />');
    				}
    				else {
    					alert("Napačen format datoteke. Naložite lahko datoteko z končnico *.flv.");
    					return false;
    				}
    			},
    			onComplete: function(file, extension) {
    				//alert(extension);
    				$(".loading-upload-1").html("");
    				if (extension.length > 0) {
                        $(".loading-upload-1").after('<span class="flv-file">'+file+' &nbsp; <a href="javascript: void(0)" class="remove-flv" rel="flv">Odstrani</a><input type="hidden" name="file[]" value="' + extension + '" /></span>');
    		          	$("#upload_1").hide();
    			     	RemoveParentSpan();		
                    }
                    else {
                        alert("Datoteka je prevelika.");
                        return false;
                    }	
    			}
    		});
    }
		
	if ($("#upload_2").size()>0) {
    	//Uplaod slike
    	new AjaxUpload('upload_2', 
    		{
    			action: aplication,
    			/*autoSubmit: false,*/              
    			data: {
        			attachment  : '1'
      			},
    
    			
    			onSubmit: function(file, extension) {
    				if ((extension && /^(jpg|png|jpeg|gif)$/.test(extension))) {
    					$(".loading-upload-2").html('<img src="/static/images/ajax-loader-e-neo.gif" alt="Nalagam.." />');
    				}
    				else {
    					alert("Napačen format datoteke. Naložite lahko datoteko z končnico *.jpg, *.png, *.jpeg in *.gif.");
    					return false;
    				}
    			},
    			onComplete: function(file, extension) {
    				//alert(file);
    			     if (extension.length > 0) {
        				$(".loading-upload-2").html("");
        				$(".loading-upload-2").after('<span class="img-file">'+file+' &nbsp; <a href="javascript: void(0)" class="remove-flv">Odstrani</a><input type="hidden" name="image[]" value="' + extension + '" /></span>');
        				
        				RemoveParentSpan();
    				}
                    else {
                        alert("Datoteka je prevelika!");
                        return false;
                    }	
    			}
    		});            
		
	   RemoveParentSpan();
	}
});




















