function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

function parseScript(_source) {
		var source = _source;
		var scripts = new Array();
		var script_str;
 
		// Strip out tags
		while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
			var s = source.indexOf("<script");
			var s_e = source.indexOf(">", s);
			var e = source.indexOf("</script", s);
			var e_e = source.indexOf(">", e);
 
			// Add to scripts array
			scripts.push(source.substring(s_e+1, e));
			// Strip from source
			source = source.substring(0, s) + source.substring(e_e+1);
		}

		// Loop through every script collected and eval it
		for(var i=0; i<scripts.length; i++) {
			try {
				eval(scripts[i]);
			}
			catch(ex) {
				// do what you want here when a script fails
			}
		}
		
		
		// Return the cleaned source
		return source;
}


function content(url, pars, placeholder){
	document.getElementById(placeholder).innerHTML = returnContent(url, pars);
}

function returnContent(url, pars){

 return jQuery.ajax({
  type: 'GET',
  url: url,
  data: pars,
  contentType: 'plain/text',
  dataType: 'script',
  processData: false,
  cache: false,
  async: false,
  complete: function(res){
	  		parseScript(res.responseText);
			}
 }).responseText ;
	

}

function trazi(){
	jQuery("#secondarycontent").load("x_kolekcija_trazi.php","pojam=" + document.getElementById("textfield").value);
}



 
function slideShow() {
 
	//Set the opacity of all images to 0
	jQuery('#gallery a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	jQuery('#gallery a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	jQuery('#gallery .caption').css({opacity: 0.7});
 
	//Resize the width of the caption according to the image width
	jQuery('#gallery .caption').css({width: jQuery('#gallery a').find('img').css('width')});
	
	
	//Get the caption of the first image
	jQuery('#gallery .content').html(jQuery('#gallery a:first').find('div').html())
	.animate({opacity: 0.7}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	numbering('1');
}
 
function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = (jQuery('#gallery a.show') ?  jQuery('#gallery a.show') : jQuery('#gallery a:first'));
 
	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? jQuery('#gallery a:first') :current.next()) : jQuery('#gallery a:first'));	
	
	//Get next image caption
	var caption = next.find('div');	
	

	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
 
	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	jQuery('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:50 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	jQuery('#gallery .caption').animate({opacity: 0.7}, 50 ).animate({height: '50px'},500 );
	
	//Display the content
	jQuery('#gallery .content').html(caption.html());
	
	numbering(current.attr("id"));
}

function numbering(current)
{
	var n = jQuery("#gallery a").size();
	var table = "<table cellpadding=\"3\" cellspacing=\"2\">";
	table += "<tr>";
	for(i=1;i<=n;i++)
	{
		if(i==current) table += "<td class=\"selected\" onclick=\"switch_gallery('"+i+"')\">" + i + "</td>";
		else table += "<td onclick=\"switch_gallery('"+i+"')\">" + i + "</td>";
	}
	table += "</tr>"
	table += "</table>";
	jQuery('#gallery .numbering').html(table);
	jQuery('#gallery .numbering td').css({opacity: 0.7});
	jQuery('.selected').css({color: '#FFF200'});
}

function switch_gallery(number){
	
}