/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

var galCurrentFirst = 0;
var vidCurrentFirst = 0;

$(document).ready(function(){
	Date.format = 'yyyy-mm-dd';
	Date.dayNames = ['Nedelja', 'Ponedeljek', 'Torek', 'Sreda', 'Četrtek', 'Petek', 'Sobota'];
	Date.abbrDayNames = ['ne', 'po', 'to', 'sr', 'če', 'pe', 'so'];
	Date.monthNames = ['januar', 'februar', 'marec', 'april', 'maj', 'junij', 'julij', 'avgust', 'september', 'oktober', 'november', 'december'];
	Date.abbrMonthNames = ['jan', 'feb', 'mar', 'apr', 'maj', 'jun', 'jul', 'avg', 'sep', 'okt', 'nov', 'dec'];


	//	Clock
	$('#jclock').jclock();

	//	Activate gallery
	try {
		if (galleryArray.length > 0) {
			maxImg = (galleryArray.length > 4) ? 3 : 4;

			//	If FLASH
			if (galleryArray[0]["img"].indexOf ('youtube') > -1) {
				var so = new SWFObject(galleryArray[0]["img"], 'flashvideo', '330', '275', '7', '#ffffff');
				so.write ('articleGalleryBig');
			} else {
				$("#articleGalleryBig").html('<img src="/' + galleryArray[0]["img"] + '" id="galImgBig" />');
			}
			$("#articleGalleryBigTitle").text(galleryArray[0]["title"]);

			if (maxImg == 3) $("#articleGalleryThumbs div.thumbs").append('<img src="/dsg/ico/gallery_arrow_up.gif" class="arrow" onclick="galImgScroll(\'up\');" />');
			for (var i = 0; i < maxImg && i < galleryArray.length; i++) {
				var im = document.createElement("img");
				$im = $(im).attr("id","galImgThumb" + i).attr("src",galleryArray[i]["thumb"]);
				$("#articleGalleryThumbs div.thumbs").append(im);
				galleryClickHandler(i,i);
			}
			if (maxImg == 3) $("#articleGalleryThumbs div.thumbs").append('<img src="/dsg/ico/gallery_arrow_down.gif" class="arrow" onclick="galImgScroll(\'down\');" />');
		}
	} catch (e) {
		void(0);
	}

	//	Set textarea autogrow
	$('textarea#comment_content').autogrow();

	//	Comments voting system
	if ($(".commentRating").length) {
		$(".commentRating.vote").children("img").hover(
				function() {
					$(this).attr("src",$(this).attr("src").replace(".gif","_sel.gif"));
				},
				function() {
					$(this).attr("src",$(this).attr("src").replace("_sel.gif",".gif"));
				}
			).click(function(){
			var uaction = $(this).attr("id");
			$.post('/vote', {_wms_module: "ARTICLES_SECTION::commentVote", action: uaction}, function(xml){
				if ($("status",xml).text() == "OK") {
					$("#score_" + $("cid",xml).text()).html($("score",xml).text());
					if ($("score",xml).text() < 0) {
						$("#score_" + $("cid",xml).text()).attr("class", "neg");
					} else {
						$("#score_" + $("cid",xml).text()).attr("class", "pos");
					}

					upimg = (uaction.indexOf('voteup') > -1) ? "/dsg/vote_up_sel.gif" : "/dsg/vote_up_dis.gif";
					dnimg = (uaction.indexOf('votedn') > -1) ? "/dsg/vote_dn_sel.gif" : "/dsg/vote_dn_dis.gif";
					$("#voteup-" + $("cid",xml).text()).attr ("src",upimg).unbind();
					$("#votedn-" + $("cid",xml).text()).attr ("src",dnimg).unbind();
					$("#voteup-" + $("cid",xml).text()).parent("div").removeClass("vote");
				} else {
					alert ($("description",xml).text());
				}
			});
		});
		$(".commentRating.mustreg").children("img").click(function(){
			alert ('Za glasovanje morate biti prijavljeni.');
		});
	}

	//	Accordion for HIGHLIGHTS
	$('.company').Accordion({
		active: false,
		selectedClass: "sel",
		header: 'dt',
		event: 'click',
		animated: false,
		autoheight: false}).activate('.company> dt:first');

	//	Accordion for PERISKOP
	$('.periskopSide').Accordion({
		active: false,
		selectedClass: "sel",
		header: 'dt',
		event: 'click',
		animated: false,
		autoheight: true}).activate('.periskopSide> dt:first');

	//	Search tabs
	if ($('div.archiveFilter').length) {
		var tabContainers = $('div.archiveFilter > div');

		$('div.archiveFilter ul.articleArchTabs a').click(function () {
			tabContainers.hide().filter(this.hash).show();
			$('div.archiveFilter ul.articleArchTabs a').removeClass('sel');
			$(this).addClass('sel');
			return false;
		});
	}

	$("ul.articleArchCalendar > li").find("a.none").attr("href","javascript:void(0);");

	//	Search calendar
	if ($('.datePicker').length) {
		Date.format = 'dd.mm.yyyy';
		$('.datePicker').datePicker({clickInput:true, startDate:'01.01.2008'});
		//$('#s_fromdate').dpSetEndDate($('#s_fromdate').val());
		$('#s_fromdate').bind('dpClosed',function(e, selectedDates) {
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#s_todate').dpSetStartDate(d.addDays(1).asString());
			}
		});
		$('#s_todate').bind('dpClosed',function(e, selectedDates) {
			var d = selectedDates[0];
			if (d) {
				d = new Date(d);
				$('#s_fromdate').dpSetEndDate(d.addDays(-1).asString());
			}
		});
	}

	//	Guide lists
	if ($('div.guideList').length) {
		var tabContainers = $('div.guideList > div');
		tabContainers.hide().filter(':first').show();

		$('div.guideList> ul a').click(function () {
			tabContainers.hide().filter(this.hash).show();
			$('div.guideList> ul a').removeClass('sel');
			$(this).addClass('sel');
			return false;
		}).filter(':first').click();
	}

	//	Guide calendar
	if ($('#guideCalendar').length) {
		$('#guideCalendar').datePicker({
			startDate: guideCalMin,
			endDate: guideCalMax,
			month: Number(guideCalToday.substring(5,7)) - 1,
			year: Number(guideCalToday.substring(0,4)),
			inline:true,
			renderCallback:function($td, thisDate, month, year) {
				if (thisDate.isWeekend()) {$td.addClass('weekend');}
				if (thisDate.getDate() == Number(guideCalToday.substring(8,10))) {$td.addClass('selected')}
				if (guideCalArr[year] && thisDate.getMonth() == month && in_array(thisDate.getDate(),guideCalArr[year][month + 1])) {
					guideClickHandler($td, thisDate.asString());
				} else {
					$td.addClass('disabled');
				}
			}
		});
	}

	//	Activate video
	try {
		if (videoArray.length > 0) {
			maxImg = 5;
			//	Show first video
			videoShow(0, 'videoplayer');
			$("#videoplayer_thumbs").append('<img src="/dsg/ico/video_arrow_left.gif" class="arrow" onclick="vidImgScroll(\'prev\');" />');
			for (var i = 0; i < maxImg && i < videoArray.length; i++) {
				var im = document.createElement("img");
				$im = $(im).attr("id","vidImgThumb" + i).attr("src",videoArray[i]["thumb"]);
				$("#videoplayer_thumbs").append(im);
				videoClickHandler(i,i);
			}
			$("#videoplayer_thumbs").append('<img src="/dsg/ico/video_arrow_right.gif" class="arrow" onclick="vidImgScroll(\'next\');" />');
		}
	} catch (e) {
		void(0);
	}

	//	Home: latest/mostread
	if ($('div.articlesListHome').length) {
		var tabContainers = $('div.articlesListHome > div');
		tabContainers.hide().filter(':first').show();

		$('div.articlesListHome> ul a').click(function () {
			tabContainers.hide().filter(this.hash).show();
			$('div.articlesListHome> ul li').removeClass('sel');
			$(this).parents("li:first").addClass('sel');
			return false;
		}).filter(':first').click();
	}

	//	Trendmeter
	if ($('div.trendmeterSide').length) {
		var tabContainersTM = $('div.trendmeterSide > div');
		tabContainersTM.hide().filter(':first').show();

		$('div.trendmeterSide> ul a').click(function () {
			tabContainersTM.hide().filter(this.hash).show();
			$('div.trendmeterSide> ul a').removeClass('sel');
			$(this).addClass('sel');
			return false;
		}).filter(':first').click();
	}

	$('#s3').after('<p id="topArtNav" class="nat-pager">').cycle({
		fx:     'scrollLeft',
		speed:   200,
		timeout: 5000,
		pager:  '#topArtNav',
		pause:	1
	});

	$('.bannerPlace').css('display','block');

	$('#lestSelect').change(function(){
		$('#lestData > li').css('display', 'none');
		$('.no' + $(this).val()).css('display','block');
	});
	$('#lestData > li').filter(':first').css('display', 'block');
	$(".lestvicaSide > ul li table tr:even").addClass("even");
	$(".lestvicaSide > ul li table tr:odd").addClass("odd");

	//	Single article video pager
	$('ul.videoArchive').each(function() {
		//SET PAGER VARS
		var currentPage = 0;
		var numPerPage = 9;
		var $ul = $(this);
		$ul.bind('repaginate', function() {
			$ul.find('li').show().slice(0, currentPage * numPerPage).hide().end().slice((currentPage + 1) * numPerPage).hide().end();
		});
		//CALCULATE NUMBER OF PAGES, numRows / numPerPage
		var numRows = $ul.find('li').length;
		var numPages = Math.ceil(numRows / numPerPage);
		//CREATE PAGE NUMBERS, THEN insertAfter($ul)
		var $pager = $('<p class="nat-pager" style="padding-bottom: 10px;"></p>');
		for (var page = 0; page < numPages; page++) {
			$('<a href="javascript:void(0);">' + (page + 1) + '</a>')
			.bind('click', {'newPage': page}, function(event) {
				currentPage = event.data['newPage'];
				$ul.trigger('repaginate');
				$(this).addClass('activeSlide').siblings().removeClass('activeSlide');
			})
			.appendTo($pager).addClass('clickable');
		}
		$pager.find('a:first').addClass('activeSlide');
		$pager.insertAfter($ul);
		//TRIGGER EVENT
		$ul.trigger('repaginate');
	});
	
	
});

function articleCycleLink (url) {
	$('#s3').cycle('stop');
	location.href=url;
	return false;
}

//	Video
function videoClickHandler (thumb, source) {
	$("#vidImgThumb" + thumb).click(function(){videoShow (source, 'videoplayer')});
}

function videoShow (i, targetDiv) {
	var so = new SWFObject(videoArray[i]["url"], 'flashvideo', '300', '252', '7', '#ffffff');
	so.write (targetDiv);
	$("#videoplayer_title").text(videoArray[i]["title"]);
}

function videoShowById (id, targetDiv, title) {
	var so = new SWFObject('http://youtube.com/v/' + id, 'ytflashvideo', '470', '395', '7', '#ffffff');
	so.write (targetDiv);
	$("#ytVideoTitle").text(title);
}

function vidImgScroll (type) {
	arrLength = videoArray.length;
	if (type == 'prev') {
		vidCurrentFirst = (vidCurrentFirst == 0) ? arrLength - 1 : vidCurrentFirst - 1;
	} else {
		vidCurrentFirst = (vidCurrentFirst == arrLength - 1) ? 0 : vidCurrentFirst + 1;
	}

	for (i = 0; i < 5 && i < videoArray.length; i++) {
		index = (vidCurrentFirst + i > (arrLength - 1)) ? vidCurrentFirst + i - (arrLength - 1) - 1 : vidCurrentFirst + i;
		$("#vidImgThumb" + i).attr("src",videoArray[index]["thumb"]).attr("title",videoArray[index]["title"]);
		videoClickHandler(i,index);
	}
}

function in_array (needle, haystack, strict) {
	var found = false, key, strict = !!strict;
	for (key in haystack) if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {found = true;break;}
	return found;
}

function guideClickHandler (el, date) {
	el.click(function(){location.href=guideCalUrl + '?gdate=' + date});
}

//	Gallery
function galleryClickHandler (thumb, source) {
	$("#galImgThumb" + thumb).click(function(){galleryDisplayBig (source)});
}

function galleryDisplayBig (i) {
	if (galleryArray[i]["img"].indexOf ('youtube') > -1) {
		var so = new SWFObject(galleryArray[i]["img"], 'flashvideo', '330', '275', '7', '#ffffff');
		so.write ('articleGalleryBig');
	} else {
		$("#articleGalleryBig").html('<img src="/' + galleryArray[i]["img"] + '" id="galImgBig" title="' + galleryArray[i]["title"] + '" alt="' + galleryArray[i]["title"] + '" />');
	}
	if (galleryArray[i]["title"].length > 0) {
		$("#articleGalleryBigTitle").text(galleryArray[i]["title"]);
	} else {
		$("#articleGalleryBigTitle").text("");
	}
}

function galImgScroll (type) {
	arrLength = galleryArray.length;
	if (type == 'up') {
		galCurrentFirst = (galCurrentFirst == 0) ? arrLength - 1 : galCurrentFirst - 1;
	} else {
		galCurrentFirst = (galCurrentFirst == arrLength - 1) ? 0 : galCurrentFirst + 1;
	}

	for (i = 0; i < 3; i++) {
		index = (galCurrentFirst + i > (arrLength - 1)) ? galCurrentFirst + i - (arrLength - 1) - 1 : galCurrentFirst + i;
		$("#galImgThumb" + i).attr("src",galleryArray[index]["thumb"]).attr("title",galleryArray[index]["title"]);
		galleryClickHandler(i,index);
	}
}

//	Comments
function commentAddReply (cid) {
	$("#reply_id").val(cid);
	$("#comment_content").val("").focus();
	return false;
}

function commentAddQuote (cid) {
	$("#reply_id").val(cid);
	replyCnt = "[QUOTE=" + $("span#author" + cid).html() + "]" + $("#comment_" + cid).text() + "[/QUOTE]\n";
	$("#comment_content").val(replyCnt).focus();
	return false;
}

function commentFilter (choice) {
	$.cookie('comments_filter', choice, { expires: 31536000});
	location.href = location.href;
}

function commentSubmit () {
	var str_in = $('#comment_content').val();
	var chr = "";
	var nLowerAlpha = 0;
	var nUpperAlpha = 0;
	re		= /([\.!\?]{5,})/;
	re_str	= /\[QUOTE\=.*?\/QUOTE\]/;
	str = str_in.replace(re_str, "");

	//	Check if anything is entered
	if (str == document.getElementById('comment_content').defaultValue) {
		$("#comment_error_box").html("Vpišite komentar.").show();
		return false;
	}

	//	Check for content
	if (str.length <= 10) {
		$("#comment_error_box").html("Komentar mora vsebovati vsaj 10 znakov.").show();
		return false;
	}

	//	Check for repeating spec. characters
	if (str.match(re)) {
		$("#comment_error_box").html("V komentarju ne smetite z ločili.").show();
		return false;
	}

	//	Count upperchars
	for (position = 0; position < str.length; position++) {
	   chr = str.charAt(position);
	   if (chr >= "a" && chr <= "z") nLowerAlpha++;
	   if (chr >= "A" && chr <= "Z") nUpperAlpha++;
	}

	if (str.length > 10 && nLowerAlpha < nUpperAlpha) {
		$("#comment_error_box").html("Komentar ne sme vsebovati toliko velikih črk.").show();
		return false;
	}

	document.getElementById ('comment_form').submit ();
}

function removeComment (id) {
	if (confirm ('Ste prepričani, da želite zbrisati komentar?')) {
		$.post("/novice", {_wms_module: "ARTICLES_SECTION::commentRemove", cid: id}, function(xml){
			if ($("status",xml).text() == "OK") {
				//alert ($("cid",xml).text());
				$("#comment" + $("cid",xml).text()).remove();
			} else {
				alert ($("description",xml).text());
			}
		});
	}
}

//	Poll
function pollCastVote (poll_id) {

	var selOption = null;

	$("#pollSide").find("input").each(function(){
		if ($(this).attr("checked") == true) selOption = $(this).val();
	});

	if (selOption) {
		$.post('/anketa', {_wms_module: "POLL_ARCHIVE::pollVote", option: selOption}, function(xml){
			if ($("status",xml).text() == "OK") {
				sum = $("sum",xml).text();
				$("#pollSide").hide();
				poll = "<ul>";
				$("option",xml).each(function(){
					width = ($("score",this).text() != 0) ? Math.round (($("score",this).text() / sum) * 100) : 0;
					poll+= '<li>' + $("title",this).text() + ' - ' + width + '%<div class="pollbar" style="width: ' + width * 2 + 'px;">&nbsp;</div></li>';
				});
				poll+= "</ul>";
				poll+= '<p class="pollArchiveBtn"><a href="/anketa"><img  src="/dsg/title/arhiv.gif"  width="67"  height="17" alt="" /></a></p><p class="pollVote">Število glasov: ' + sum + '</p>';

				$("#pollSide").html(poll).fadeIn("slow");
			}
		});
	}
}


//	print_readable function for dispalying arrays
function print_r (theObj)
{
	var output = '';
	if (theObj.constructor == Array || theObj.constructor == Object)
	{
		for(var p in theObj)
		{
			if(theObj[p].constructor == Array || theObj[p].constructor == Object)
			{
				output+= "["+p+"] => "+typeof(theObj)+"\n";
				output+= " "
				output+= print_r(theObj[p]);
				output+="\n"
			} else {
				output+="["+p+"] => "+theObj[p]+"\n";
			}
		}
		output+="\n"
	}
	return output;
}

var upload_number;
if (!upload_number) upload_number = 2;

var video_number;
if (!video_number) video_number = 2;



function addUGCFileFields () {
	if (document.getElementById ('ugc_file_tpl')) {
		if ($("#ugcFileFields > div.orderSet").length >= 5) {
			alert ('Dodate lahko največ 5 slik.');
			return false;
		}

		var cnt = document.getElementById ('ugc_images_arr');
		var tpl	= document.getElementById ('ugc_file_tpl');
		var el	= tpl.cloneNode (true);
		el.innerHTML = tpl.innerHTML;
		newCnt = parseInt(cnt.value) + 1;

		el.style.display = 'block';
		el.id = 'orderSet_' + newCnt;
		el.innerHTML = el.innerHTML.replace(/TMPID/g, newCnt);
		document.getElementById ('ugcFileFields').appendChild(el);
		cnt.value = newCnt;

		scripts = el.getElementsByTagName ('SCRIPT');
		for (i = 0; i < scripts.length; i++) {
			eval (scripts[i].innerHTML);
		}

		return true;
	}

	return false;
}

function addUGCVideoFields () {
	if (document.getElementById ('ugc_video_tpl')) {
		if ($("#ugcVideoFields > div.orderSet").length >= 5) {
			alert ('Dodate lahko največ 5 videov.');
			return false;
		}

		var cnt = document.getElementById ('ugc_videos_arr');
		var tpl	= document.getElementById ('ugc_video_tpl');
		var el	= tpl.cloneNode (true);
		el.innerHTML = tpl.innerHTML;
		newCnt = parseInt(cnt.value) + 1;

		el.style.display = 'block';
		el.id = 'orderVSet_' + newCnt;
		el.innerHTML = el.innerHTML.replace(/TMPID/g, newCnt);
		document.getElementById ('ugcVideoFields').appendChild(el);
		cnt.value = newCnt;

		scripts = el.getElementsByTagName ('SCRIPT');
		for (i = 0; i < scripts.length; i++) {
			eval (scripts[i].innerHTML);
		}

		return true;
	}

	return false;
}

function removeUGCFileFields (elemId) {
	try {
		if (confirm ("Zbrišem datoteko?")) {
			document.getElementById ('ugcFileFields').removeChild (document.getElementById ('orderSet_' + elemId));
			document.getElementById ('ugc_images_remarr').value += ',' + elemId;
		}
	} catch (e) {

	}
}

function removeUGCVideoFields (elemId) {
	try {
		if (confirm ("Zbrišem video?")) {
			document.getElementById ('ugcVideoFields').removeChild (document.getElementById ('orderVSet_' + elemId));
			document.getElementById ('ugc_videos_remarr').value += ',' + elemId;
		}
	} catch (e) {

	}
}





	function addFileInput() {

	  var d = document.createElement("div");
	  var l = document.createElement("a");
	  var file = document.createElement("input");
	  file.setAttribute("type", "file");
	  file.setAttribute("name", "image["+upload_number+']');
	  l.setAttribute("href", "javascript:removeFileInput('f"+upload_number+"');");
	  l.appendChild(document.createTextNode("Odstrani"));
	  d.setAttribute("id", "f"+upload_number);
		if (document.getElementById("images").value >= upload_number) {
			  d.appendChild(file);
			  d.appendChild(l);
			  document.getElementById("moreUploads").appendChild(d);
		  }
	 // document.getElementById("images").value = upload_number;
		if (document.getElementById("images").value >= upload_number) {
			  upload_number++;
		}
		if (document.getElementById("images").value == (upload_number-1)) {
			document.getElementById('moreUploadsLink').style.display = 'none';
		}
   }
   function removeFileInput(i)
   {
	 var elm = document.getElementById(i);
	 document.getElementById("moreUploads").removeChild(elm);
	 upload_number = upload_number - 1;
   }

   function addInput()
   {
	  var d = document.createElement("div");
	  var l = document.createElement("a");
	  var input = document.createElement("input");
	  input.setAttribute("type", "text");
	  input.setAttribute("name", "video["+video_number+']');

	  l.setAttribute("href", "javascript:removeFileInput('v"+video_number+"');");
	  l.appendChild(document.createTextNode("Odstrani"));
	  d.setAttribute("id", "v"+video_number);
	  if(document.getElementById("videos").value >= video_number) {
		  d.appendChild(input);
		  d.appendChild(l);
		  document.getElementById("moreVideos").appendChild(d);
		  // document.getElementById("videos").value = video_number;
		  video_number++;
	  }
	  if(document.getElementById("videos").value == (video_number-1)){
			document.getElementById('moreVideosLink').style.display = 'none';
		}
   }
   function removeInput(i)
   {
	 var elm = document.getElementById(i);
	 document.getElementById("moreVideos").removeChild(elm);
	 video_number = video_number - 1;
   }

   
   
   
   function switchKeywords(id) {
		if($('#ks_'+id).hasClass('keyhidden')) {
			$('ul.keywordsMenu li').removeClass('sel');
			$('#ls_'+id).addClass('sel');
			
			$('div.keywordsSection:not(.keyhidden)').addClass('keyhidden');
			$('#ks_'+id).removeClass('keyhidden');
		}
	}

   
   
   
   
   
   
   
   
   
   
   