﻿$(document).ready(function() {	
	 
	if (!$.browser.msie) {
		window.addEventListener("message", receiveMessage, false);
	}
	else
	{
		attachEvent ('onmessage', receiveMessage);
	}
	snow();
	logoAnimOn("#logo-on",2000);
	logoAnimOn("#rlogo-on",4000);
	logoAnimOn("#llogo-on",4000);
	
	$("#btRegister").click(function() {
		$.fancybox({
			'scrolling'   : 'auto',
			'padding'       : '10px',
			'margin'		: '10px',
			'href'          : "ajax/register_get.asp",        
			'transitionIn'  : 'fade',
			'transitionOut' : 'fade',
			'type'			: 'ajax',
			'title'			: 'Popuni potrebna polja i učlani se na naš portal',
			'centerOnScroll': true
		});	
	});
	
	$("#btDodajSliku").click(function() {
		$.fancybox({
			'scrolling'   : 'auto',
			'padding'       : '10px',
			'margin'		: '10px',
			'href'          : "ajax/gallery_pic_get.asp",        
			'transitionIn'  : 'fade',
			'transitionOut' : 'fade',
			'type'			: 'ajax',
			'title'			: 'Dodavanje slike',
			'centerOnScroll': true,
			'onClosed': function() {
					reloadPage();
				}
		});	
	});
	
	$("#btDodajGaleriju").click(function() {
		$.fancybox({
			'scrolling'   : 'auto',
			'padding'       : '10px',
			'margin'		: '10px',
			'href'          : "ajax/gallery_get.asp",        
			'transitionIn'  : 'fade',
			'transitionOut' : 'fade',
			'type'			: 'ajax',
			'title'			: 'Popuni potrebna polja i kreiraj galeriju',
			'centerOnScroll': true
		});	
	});
	
	$("#btLogin").click(function() {
		$.fancybox({
			'scrolling'   : 'auto',
			'padding'       : '10px',
			'margin'		: '10px',
			'href'          : "ajax/login_get.asp",        
			'transitionIn'  : 'fade',
			'transitionOut' : 'fade',
			'type'			: 'ajax',
			'title'			: 'Popuni email i lozinku i prijavi se na naš portal',
			'centerOnScroll': true
		});	
	});

	$("#btLogout").click(function() {
		$.fancybox({
			'scrolling'   : 'auto',
			'padding'       : '10px',
			'margin'		: '10px',
			'href'          : "ajax/logout_get.asp",        
			'transitionIn'  : 'fade',
			'transitionOut' : 'fade',
			'type'			: 'ajax',
			'title'			: 'Odjava',			
			'centerOnScroll': true
		});	
	});

	$("#btSettings").click(function() {
		$.fancybox({
			'scrolling'   : 'auto',
			'padding'       : '10px',
			'margin'		: '10px',
			'href'          : "ajax/postavke.asp",        
			'transitionIn'  : 'fade',
			'transitionOut' : 'fade',
			'type'			: 'ajax',
			'title'			: 'Korisničke postavke',			
			'centerOnScroll': true
		});	
	});
	
	/*if (!$.browser.msie) {
		$(".menuheader li a").hover(
			function() {
				$(this).closest("li").stop(true,true).animate({color: '#FFFF00'},1);
				var aas = $(this).closest("li").find("a");
				aas.stop(true,true);
				aas.animate({color: '#FFFF00'},500);
			},
			function() {
				$(this).closest("li").stop(true,true).animate({color: '#FFFFFF'},1);
				var aas = $(this).closest("li").find("a");
				aas.stop(true,true);
				aas.animate({color: '#FFFFFF'},500);
			}
		);
	}*/
});

function forumPreSubmit(isLoggedIn, forumForm, editor) {
	$('#koment',forumForm).val(jQuery.wymeditors(editor).xhtml());
	var ret = checkForumForm($(forumForm), isLoggedIn);
	return ret;
}

function checkForumForm(frm,guest) {
	if ($('#zaboravi',frm).length > 0) {
		if ($('#zaboravi',frm).val() == 'true') {
			return true;
		}	
		else {
			alert($('#zaboravi',frm).val());
		}
	}
	if (guest) {
		if ($('#koment',frm).val().replace(/<br\/?>/,'')=='') {
			showError('Greška u poljima:<br><br>Niste upisali komentar!');
			return false;
		}
		if ($('#spamcheck',frm).val()=='') {
			showError('Greška u poljima:<br><br>Niste upisali kod za provjeru protiv spama!');
			return false;
		}		
		if ($('#ime',frm).length > 0) {
			if ($('#ime',frm).val()=='') {
				showError('Greška u poljima:<br><br>Niste upisali ime ili nadimak!');
				return false;
			}	
			if ($('#ime',frm).val().length<3) {
				showError('Greška u poljima:<br><br>Ime ili nadimak mora imati bar 3 slova!');
				return false;
			}	
		}
	}
	else {
		if ($('#koment',frm).val().replace(/<br\/?>/,'')=='') {
			showError('Greška u poljima:<br><br>Niste upisali komentar!');
			return false;
		}	
	}
	return true;
}

function showError(err) {
	var errobj = $("<div style='width:100%;position;relative;text-align:center;'><span style='' id='fberrmsg'>" +err+ "</span></div>");
	if ($("#fancybox-title-float-main").length>0) {
		$("#fancybox-title-float-main").html('').append(errobj);
		errobj.animate({color:'red'},200).animate({color:'white'},200).animate({color:'red'},200).animate({color:'white'},200).animate({color:'red'},200).animate({color:'white'},200);
	}
	else {
		$.fancybox({
			'autosize' : true,
			'scrolling'   : 'auto',
			'padding'       : '20px',
			'margin'		: '20px',
			'content'          : "<div style='text-align:center;'><div id='fberrmsg' class='fberrmsginside'>" + err + "</div></div>",        
			'transitionIn'  : 'fade',
			'transitionOut' : 'fade',
			'title'			: 'Greška',
			'centerOnScroll': true,
			onComplete: function() {$("#fberrmsg").animate({color:'red'},200).animate({color:'white'},200).animate({color:'red'},200).animate({color:'white'},200).animate({color:'red'},200).animate({color:'white'},200);}
		});			
	}
}

function htmlEscape(str) {
    return String(str)
            .replace(/&/g, '&amp;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;');
}

if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}
	
function ConfirmDelete(message) {
	var answer = confirm(message);
	return answer;
}

function post(formId, ajaxPostUrl, add, callback, stripHTML) {
	var_form_data = '';
	if (stripHTML) {
		var_form_data = $.param($('#'+formId).map(function(){
				return this.elements ? jQuery.makeArray( this.elements ) : this;
			})
			.filter(function(){
				return this.name && !this.disabled &&
					( this.checked || (/^(?:select|textarea)/i).test( this.nodeName ) ||
						(/^(?:color|date|datetime|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i).test( this.type ) );
			})
			.map(function( i, elem ){
				var val = jQuery( this ).val();

				return val == null ?
					null :
					jQuery.isArray( val ) ?
						jQuery.map( val, function( val, i ){
							return { name: elem.name, value: htmlEscape(val.replace( (/\r?\n/g), "\r\n" )) };
						}) :
						{ name: elem.name, value: htmlEscape(val.replace( (/\r?\n/g), "\r\n" )) };
			}).get()) + add;
	}
	else {
		var_form_data = $('#'+formId).serialize() + add;
	}
	//alert(var_form_data);
    $.ajax({
       type: "POST",
       url: ajaxPostUrl,
       data: var_form_data,
	   error: function(jqXHR, textStatus, errorThrown) {
		alert(jqXHR.responseText);
	   },
       success: function(msg){
			if (callback) {
				callback(msg);
				return false;
			}
			var splitted = msg.split(':');			
			if (splitted.indexOf('ERROR')!=-1) {					
				showError(splitted[splitted.indexOf('ERROR')+1]);
			}
			else if (splitted.indexOf('LOZINKA')!=-1) {
				showError( splitted[splitted.indexOf('LOZINKA')+1] );
				setTimeout("$.fancybox.close();", 2000);
			}
			else {
				if (splitted.indexOf('LOGIN')!=-1) reloadPage();
				if (splitted.indexOf('LOGOUT')!=-1) reloadPage();
				if (splitted.indexOf('RELOAD')!=-1) reloadPage();
			}
			return true;
       }
    });
}

function reloadPage(){
	window.location.reload();
}

function changeUrl(url)
{
	window.location = url;
}	

function logoAnimOn(obj,tm) {
	$(obj).fadeIn(tm, function() {logoAnimOff(obj,tm);});
}
function logoAnimOff(obj,tm) {
	$(obj).fadeOut(tm, function() {logoAnimOn(obj,tm);});
}

function receiveMessage(event)
{
	if (event.origin !== "http://www.boletus.hr")
	return;

	changeUrl(event.data);
}


// OLD

	function switchVisible(objname)
{
		odis = document.getElementById(objname.toString()).style.display;
	  if (odis=='none') {
		document.getElementById(objname.toString()).style.display='';
	  } else {
		document.getElementById(objname.toString()).style.display='none';
	  }
}
function odgovori(pid) {
	
	if (pid == document.getElementById('reply').value) {
		document.getElementById('reply').value = '';
		alert('Odgovaranje poništeno. Post će biti sasvim normalan post na forumu!');
		
	} else {
		document.getElementById('reply').value = pid;
		alert('Ovaj post na forumu će biti odgovor na post broj ' + pid + '!');
		if (editor) editor.focus();
		scroll(0,0);
	}
	return true;
}
function setArticle(aid,forum)
{
		var atitle = prompt("Koji naslov želite dati ovom članku?", "")
		if (atitle!="" && atitle!=null && atitle!="null")
		{document.location='forum_' + forum + '.asp?artid=' + aid + '&title=' + atitle;}
		 else
	  {alert('Prebacivanje u članke poništeno!');}
}
function delPost(id,forum)
{		
		var check = confirm('Jeste li sigurni da želite obrisati tekst?');
		if (check==true)
		{document.location='forum_' + forum + '.asp?delid=' + id;}
		 else
	  {alert('Brisanje poništeno!');}	
}
function movPost(id,forum)
{
		var check = confirm('Jeste li sigurni da želite preseliti tekst u drugi forum?');
		if (check==true)
		{document.location='forum_' + forum + '.asp?movid=' + id;}
		 else
	  {alert('Pomicanje poništeno!');}	
}
function npPost(id,forum)
{
		var check = confirm('Jeste li sigurni da želite označiti tekst kao neprimjeren?');
		if (check==true)
		{document.location='forum_' + forum + '.asp?nepid=' + id;}
		 else
	  {alert('Označivanje poništeno!');}	
}
function prPost(id,forum)
{
		var check = confirm('Jeste li sigurni da želite označiti tekst kao primjeren?');
		if (check==true)
		{document.location='forum_' + forum + '.asp?priid=' + id;}
		 else
	  {alert('Označivanje poništeno!');}	
}
function resetprovjera()
{
	  document.getElementById("provjera").value = "0";
}
function checkform()
{
	return true;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Nevaljali E-mail")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Nevaljali E-mail")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Nevaljali E-mail")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Nevaljali E-mail")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Nevaljali E-mail")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Nevaljali E-mail")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Nevaljali E-mail")
		    return false
		 }

 		 return true					
	}

function ValidateGallery(){
	var kor=$("#date")[0];
	if ((kor.value==null)||(kor.value=="")){
		showError("Morate unesti datum!");
		kor.focus();
		return false;
	}
	var kor2=$("#name")[0];
	if ((kor2.value==null)||(kor2.value=="")){
		showError("Morate unesti naslov!");
		kor2.focus();
		return false;
	}
	return true;
}

function ValidateName() {
	var kor=$("#imekorisnika")[0];
	if ((kor.value==null)||(kor.value=="")){
		showError("Morate unesti ime!");
		kor.focus();
		return false;
	}
	return true;
}

function ValidateUser(){
	var pass=$("#lozinka")[0];
	var ime=$("#ime")[0];
	if ((pass.value==null)||(pass.value=="") ||	(ime.value==null)||(ime.value=="")){
		showError("Morate unesti lozinku i ime!");
		pass.focus();
		return false;
	}
	if (pass.value.length < 3) {
		showError("Lozinka mora biti barem duljine 3 znaka!");
		pass.focus();
		return false;
	}
	return true;
}

function ValidatePass(){
	var pass=$("#lozinka")[0];
	if ((pass.value==null)||(pass.value=="")){
		showError("Morate unesti lozinku!");
		pass.focus();
		return false;
	}
	return true;
}
	
function ValidateMail(){
	var emailID=$("#korisnik")[0];
	
	if ((emailID.value==null)||(emailID.value=="")){
		showError("Molimo vas upišite email!");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	return true;
 }
 
 var Utf8 = {
 
	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

 var LZW = {
    compress: function (uncompressed) {
        "use strict";
        // Build the dictionary.
        var i,
            dictionary = {},
            c,
            wc,
            w = "",
            result = [],
            dictSize = 256;
        for (i = 0; i < 256; i += 1) {
            dictionary[String.fromCharCode(i)] = i;
        }
 
        for (i = 0; i < uncompressed.length; i += 1) {
            c = uncompressed.charAt(i);
            wc = w + c;
            if (dictionary[wc]) {
                w = wc;
            } else {
                result.push(dictionary[w]);
                // Add wc to the dictionary.
                dictionary[wc] = dictSize++;
                w = String(c);
            }
        }
 
        // Output the code for w.
        if (w !== "") {
            result.push(dictionary[w]);
        }
        return result;
    },
 
 
    decompress: function (compressed) {
        "use strict";
        // Build the dictionary.
        var i,
            dictionary = [],
            w,
            result,
            k,
            entry = "",
            dictSize = 256;
        for (i = 0; i < 256; i += 1) {
            dictionary[i] = String.fromCharCode(i);
        }
 
        w = String.fromCharCode(compressed[0]);
        result = w;
        for (i = 1; i < compressed.length; i += 1) {
            k = compressed[i];
            if (dictionary[k]) {
                entry = dictionary[k];
            } else {
                if (k === dictSize) {
                    entry = w + w.charAt(0);
                } else {
                    return null;
                }
            }
 
            result += entry;
 
            // Add w+entry[0] to the dictionary.
            dictionary[dictSize++] = w + entry.charAt(0);
 
            w = entry;
        }
        return result;
    }
}
$(document).ready(function() {
		
			editor = jQuery('#koment').wymeditor({		
				skin: 'compact',
				lang: 'hr',		
				basePath: "/js/",
				html: jQuery('#koment').val(),
				toolsItems: [
				{'name': 'Bold', 'title': 'Strong', 'css': 'wym_tools_strong'}, 
				{'name': 'Italic', 'title': 'Emphasis', 'css': 'wym_tools_emphasis'},
				{'name': 'Superscript', 'title': 'Superscript',
					'css': 'wym_tools_superscript'},
				{'name': 'Subscript', 'title': 'Subscript',
					'css': 'wym_tools_subscript'},
				{'name': 'InsertOrderedList', 'title': 'Ordered_List',
					'css': 'wym_tools_ordered_list'},
				{'name': 'InsertUnorderedList', 'title': 'Unordered_List',
					'css': 'wym_tools_unordered_list'},
				{'name': 'Undo', 'title': 'Undo', 'css': 'wym_tools_undo'},
				{'name': 'Redo', 'title': 'Redo', 'css': 'wym_tools_redo'},
				{'name': 'CreateLink', 'title': 'Link', 'css': 'wym_tools_link'},
				{'name': 'Unlink', 'title': 'Unlink', 'css': 'wym_tools_unlink'},
				{'name': 'InsertImage', 'title': 'Image', 'css': 'wym_tools_image'},
				{'name': 'InsertTable', 'title': 'Table', 'css': 'wym_tools_table'},
				{'name': 'Paste', 'title': 'Paste_From_Word',
					'css': 'wym_tools_paste'},
				{'name': 'Preview', 'title': 'Preview', 'css': 'wym_tools_preview'}
				],
				stylesheet: '/skin/editor_styles.css',
				postInit: function(wym) {
						wym.fullscreen();
						setTimeout(function(){jQuery.wymeditors(0)._wym._iframe.contentWindow.focus();},250);
				}			
			});
			
			if (typeof window.omit_fancyimage == 'undefined' || window.omit_fancyimage == false) {
				$('a[href$="jpg"]:has(img),a[href$="gif"]:has(img),a[href$="png"]:has(img)').fancybox();
			}
			$("a").jTube('small');
			$("a[href='chat.asp']").fancybox({
							'padding'			: 25,
							'width'				: 800,
							'height'			: 600,
							'centerOnScroll'	: true,
							'transitionIn'		: 'fade',
							'transitionOut'		: 'fade',
							'type'              : 'iframe',
							'title'				: 'Chat',
							'href'				: '/chat/default.asp'
							});
			
			$(".postcontent img").each(function () {
            /* Max width for the image */
            var maxWidth = $(".postcontent").width()/2-40;
            /* Max hieght for the image */
            var maxHeight = 300;
            /*Used for aspect ratio*/
            var ratio = 0;
            /*Current image width*/
            var width = $(this).width();
            /*Current image height */
            var height = $(this).height();

            /*Check if the current width is larger than the max*/
            if (width > maxWidth) {
                /*get ratio for scaling image*/
                ratio = (maxWidth / width);
                /* Set New hieght and width of Image*/
                $(this).attr({
                        width : maxWidth,
                        height : (height * ratio),
                        alt : "",
                        title: "Ova slika je smanjena naspram originala zbog njenih prevelikih dimenzija.\nKlik na sliku za uvečani pregled."
                    });
                $(this).css({
                	cursor: 'pointer'
                });
                var idata = {w: maxWidth, h: (height * ratio), pos: $(this).css("position"), l: $(this).css('left'), t: $(this).css('top')};
                
                /* Reset height to match scaled image */
                height = (height * ratio);
                /* Reset width to match scaled image */
                width = (width * ratio);
                /*Check if current height is larger than max*/
                if (height > maxHeight) {
                    /*get ratio for scaling image*/
                    ratio = (maxHeight / height);
                    /*Set new height and width*/
                    $(this).attr({
                            height : maxHeight,
                            width : (width * ratio),
                            alt : "",
                            title: "Ova slika je smanjena naspram originala zbog njenih prevelikih dimenzija.\nKlik na sliku za uvečani pregled."
                        });
										idata = {w: (width * ratio), h: maxHeight, pos: $(this).css("position"), l: $(this).css('left'), t: $(this).css('top')};
                }
                
                $(this).click(function(){
                		$.fancybox({
                			href: $(this).attr('src')
                		});
                });
            }
        });
		});
		
		document.toggleFbRotating = function toggleRotating(programmatic) {
		  var bt = $(document.fbToggleButton);
		  if (document.fbIsEnabled) {
			clearInterval(document.fbRotatingInterval);
			document.fbRotatingInterval = false;
			document.fbIsEnabled = false;
			document.fbToggleButtonText = "Pokreni SlideShow";
		  } else {
			document.fbIsEnabled = true;
			document.fbToggleButtonText = "Zaustavi SlideShow";
			if (!programmatic) $.fancybox.next();
			document.fbRotatingInterval = setInterval($.fancybox.next, 6000);
		  }
		  if (bt.length==1) bt.val(document.fbToggleButtonText);
		}

		document.commentImage = function() {
			if ($("#is-logged-in").val()=='true') {
				alert('Samo prijavljeni korisnici mogu komentirati slike!');
			}
			else
			{
				clearInterval(document.fbRotatingInterval); document.fbIsEnabled = false;
				$("#komentbox").toggle();
			}
		}
		
		function getSrc(title, index) {
			return "ajax/picture_comment.asp?dir=" + title + "&num=" + index;
		}
		
		function formatTitle(title, currentArray, currentIndex, currentOpts) {
			document.lastFbIndex = currentIndex;
			var src = getSrc(title, currentIndex);
			var tbl = '<form id="komentform" style="border:0;margin:0;padding:0;">';		
			tbl += '<table id="komentbox" style="display:none;width:60%;margin:0;padding:0;margin-left:20%;margin-right:20%;" border=0>'
			tbl += '	<tr>'
			tbl += '		<td colspan=3 width=100% align=center>'
			tbl += '			Unesite komentar (max 500 znakova) i pritisnite dugme za unos'
			tbl += '		</td>'
			tbl += '	</tr>'
			tbl += '	<tr>'
			tbl += '		<td colspan=3 align=center valign=top>'
			tbl += '			<TEXTAREA style="font-size:12px;font-face: Tahoma;width:100%;position:relative;" rows=5 id="koment" name="koment"></TEXTAREA>'
			tbl += '		</td>'
			tbl += '	</tr>'
			tbl += '	<tr style="height:20px">'
			tbl += '		<td cellpadding=3 align=center valign=middle style="nowrap" nowrap=true>'
			tbl += '			<input class="myButton" id="postano" onclick="if ($(\'#koment\').val().length>500) {alert(\'Komentar je predugačak!\\nUpišite maksimalno 500 znakova.\');return false;} else { post(\'komentform\',\'ajax/picture_comment.asp?num=' + currentIndex + '&dir=' + title + '\',\'&postano=OK\',function(m){if ($(\'#commentframe\')[0].contentDocument) $(\'#commentframe\')[0].contentDocument.location.reload(true);}, true);$(\'#koment\').val(\'\');};return false;" type=submit name="postano" value=" Pošalji komentar " style="font-size:12px;font-face: Tahoma;">'
			tbl += '		</td>'
			tbl += '	</tr>'
			tbl += '</table>'
			tbl += '</form>'	
			var commentBox = '<div class="fb-inner-title">';
			commentBox += '<div style="padding:10px;">';
			commentBox += '<input class="myButton" style="font-family:georgia;font-size:9px;" id="fbPreviousPic" type="button" style="height:35px;" value="<" onclick="$.fancybox.prev();" />';
			commentBox += '<input class="buttonLook" style="font-family:georgia;font-size:9px;" id="fbPage" type="button" style="height:35px;" value="' + (currentIndex+1) + '/' + currentArray.length + '" />';
			commentBox += '<input class="myButton" style="font-family:georgia;font-size:9px;" id="fbNextPic" type="button" style="height:35px;" value=">" onclick="$.fancybox.next();" />';
			commentBox += '<input class="myButton" style="font-family:georgia;font-size:9px;" id="fbComment" type="button" style="height:35px;" value="Komentiraj Sliku" onclick="document.commentImage();" />';
			commentBox += '<input class="myButton" style="font-family:georgia;font-size:9px;" id="toggleSSButton" type="button" style="height:35px;" value="Zaustavi slideshow" onclick="document.toggleFbRotating(false);" />';
			commentBox += '</div>';
			commentBox += tbl;			
			commentBox += '<iframe width="100%" height="1" id="commentframe" frameborder="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" scrolling="no" noresize="true" src="' + src + '">';
			commentBox += '</div>';
			return commentBox;
		}
		
		$(document).ready(function() {
			$("a").filter('[href*="galerija"]').filter(':not([href*="page"])').filter(':not([href*="pred"])').each(function(i, v){
				var img = $(v);
				var pics = [];
				var link = img.attr("href");
				img.attr("href","");
				link = link.replace(/galerija.asp\?dir=/,"");
				link = link.replace(/num=/,"");
				link = link.replace(/max=/,"");
				var fields = link.split('&');
				var gal = fields[0];
				var index = fields[1];
				
				for (var a=1; a <= parseInt(fields[2]); a++) {
					pics[pics.length] = "http://www.boletus.hr/galerija/" + gal + "/" + a + ".jpg";
				}
				
				(function(index,pics,gal){
					img.click(function() {
						pics = $(pics);
						pics = $.makeArray(pics);
						var ar2 = [];
						for (var el = 0; el < pics.length; el++) {
							ar2[ar2.length] = pics[el];
						}
						$.fancybox(ar2, {
							'padding'			: 5,
							'transitionIn'		: 'fade',
							'transitionOut'		: 'fade',
							'type'              : 'image',
							'changeFade'        : 'slow',
							'index'				: index,
							'centerOnScroll'	: true,
							'cyclic':true,
							'onStart': function(){var bt = $(document.fbToggleButton);
							if (bt.length==1) bt.val(document.fbToggleButtonText);
							},
							'onComplete':  

								function(){
									var bt = $(document.fbToggleButton);
									if (bt.length==1) bt.val(document.fbToggleButtonText);
									$("#commentframe").css("height","0px");
									$("#commentframe")[0].src = getSrc(gal, document.lastFbIndex);
								},							
							'onClosed': function(){ clearInterval(document.fbRotatingInterval); document.fbIsEnabled = false;},
							'showCloseButton'	: false,
							'titlePosition' 	: 'inside',
							'titleFormat'		: formatTitle,
							'title'				: gal + ''
						});
						document.fbToggleButton = '#toggleSSButton';
						if (index==0) {
							document.toggleFbRotating(true);
							document.fbToggleButtonText = "Zaustavi SlideShow";
						} else {
							document.fbToggleButtonText = "Pokreni SlideShow";
						}
						return false;
					});	
				})(index-1,pics,gal);
				
			});
		});
		document.autoSizeFrame = function adjustSize(frameSize) {			
			$("#commentframe").height(frameSize);
		}	
