ddaccordion.init({
	headerclass: "expandable", //Shared CSS class name of headers group that are expandable
	contentclass: "categoryitems", //Shared CSS class name of contents group
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [0], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", "openheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["prefix", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "normal", //speed of animation: "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isclicked){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})

ddaccordion.init({ //2nd level headers initialization
	headerclass: "subexpandable", //Shared CSS class name of sub headers group that are expandable
	contentclass: "subcategoryitems", //Shared CSS class name of sub contents group
	revealtype: "clickgo", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["opensubheader", "closedsubheader"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["none", "", ""], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})// JavaScript Document



$(function() {
		$("#sortable1").sortable({
			revert:false, 
			handle: '.title, .move',
			containment: 'body',
			//opacity: 0.6,
			placeholder: 'ui-state-highlight1',
			forcePlaceholderSize:true,
			forceHelperSize: true,
			update : function () { 
			  var redoslijed1 = $('#sortable1').sortable('toArray');
			  redoslijed1 = [redoslijed1[0].replace("sortable1_",""), redoslijed1[1].replace("sortable1_",""), redoslijed1[2].replace("sortable1_",""), redoslijed1[3].replace("sortable1_","")];
			  $.cookie("glavni", redoslijed1, { expires: 10 });
			}
		});
		
		$("#sortable2").sortable({
			revert: false, 
			handle: 'h1',
			containment: 'body',
			//opacity: 0.6,
			placeholder: 'ui-state-highlight2',
			forcePlaceholderSize:true,
			forceHelperSize: true,
			update : function () { 
			  var redoslijed2 = $('#sortable2').sortable('toArray'); 
			  redoslijed2 = [redoslijed2[0].replace("sortable2_",""), redoslijed2[1].replace("sortable2_","")];
			  $.cookie("highlights", redoslijed2, { expires: 10 });
			}
		});
		
		$("#sortable3").sortable({
			revert: false, 
			handle: 'h2',
			containment: 'body',
			//opacity: 0.6,
			placeholder: 'ui-state-highlight3',
			forcePlaceholderSize:true,
			forceHelperSize: true,
			stop: function(e,ui) {
				ui.item.css({'top':'0','left':'0'});
			},
			update : function () { 
			  var redoslijed3 = $('#sortable3').sortable('toArray'); 
			  redoslijed3 = [redoslijed3[0].replace("sortable3_",""), redoslijed3[1].replace("sortable3_",""), redoslijed3[2].replace("sortable3_","")];
			  $.cookie("information", redoslijed3, { expires: 10 });
			}
		});
		
		$("#sortable4").sortable({
			revert: false, 
			handle: 'h2',
			containment: 'body',
			//opacity: 0.6,
			placeholder: 'ui-state-highlight4',
			forcePlaceholderSize:true,
			forceHelperSize: true,
			update : function () { 
			  var redoslijed4 = $('#sortable4').sortable('toArray'); 
			  redoslijed4 = [redoslijed4[0].replace("sortable4_",""), redoslijed4[1].replace("sortable4_",""), redoslijed4[2].replace("sortable4_","")];
			   $.cookie("newsletter", redoslijed4, { expires: 10 });
			}
		});
		
	});


$(function(){
		$(".minimize").click(function() {
					$(this).parent("div").parent("div").next("div.sadrzaj").slideUp("slow");
					return false;
				});
		$(".maximize").click(function() {
					$(this).parent("div").parent("div").next("div.sadrzaj").slideDown("slow");
					return false;
				});
		   });


//za cycle
$(document).ready(function() {	
	$("#emailSubs select, .rightBox select, #nusers select").selectbox();
	
	$('#slideshowImg').cycle({
		fx: 'fade',
		timeout:       8000,
		next: '.nextPress'
	});
	
	$('#slideshowText').cycle({
		fx: 'blindX',
		timeout:       8000,
		next: '.nextPress',
		height:       'auto'
	});
	
	$('.sadrzaj').hover(function() { 
   		$('#slideshowImg, #slideshowText').cycle('pause'); 
	}, function(){
		$('#slideshowImg, #slideshowText').cycle('resume');
	});
	
	
	$('#slideshowNews').cycle({
		fx: 'blindX',
		timeout:       0,
		next: '.nextNews',
		height:       'auto'
	});
	
	$('#slideshowEvents').cycle({
		fx: 'blindX',
		timeout:       0,
		next: '.nextEvent',
		height:       'auto'
	});	
	
	$('#slideshowDocs').cycle({
		fx: 'blindX',
		timeout:       0,
		next: '.nextDocs',
		height:       'auto'
	});	
	
	$('#slideshowPubs').cycle({
		fx: 'blindX',
		timeout:       0,
		next: '.nextPubs',
		height:       'auto'
	});
	
	$('#slideshowLinks').cycle({
		fx: 'blindX',
		timeout:       0,
		next: '.nextLinks',
		height:       'auto'
	});
	
	$('#slideshowFocus').cycle({
		fx: 'blindX',
		timeout:       0,
		next: '.nextFocus',
		height:       'auto'
	});
	
	$('#slideshowEurope').cycle({
		fx: 'blindX',
		timeout:       0,
		next: '.nextEurope',
		height:       'auto'
	});
	
	$('#slideshowBrussels').cycle({
		fx: 'blindX',
		timeout:       0,
		next: '.nextBrussels',
		height:       'auto'
	});
	
	//za colorbox
	$("a[rel='pressColorbox']").colorbox({
									maxHeight:"90%",
									maxWidth:"90%",
									photo:true
									});
	$("a[rel='iframeColorbox']").colorbox({
									iframe:true,
									width:360,
									height:320
									});
   $("a[rel='newsColorbox'],a[rel='focusColorbox']").colorbox({maxHeight:"90%",
			maxWidth:"90%",photo:true});
	
});


//equal heights
$.fn.equalHeights = function(px) {
	$(this).each(function(){
		var currentTallest = 0;
		$(this).children().each(function(i){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		//if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		// for ie6, set height since min-height isn't supported
		if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({'height': currentTallest}); }
		$(this).children().css({'min-height': currentTallest}); 
	});
	return this;
};

//za paginaciju
var items_per_page = 10;
function pageselectCallback(page_index, jq){
	$("#searchResults .virtualpage").hide();
	var start = page_index * items_per_page;
	$("#searchResults .virtualpage:eq("+start+"), #searchResults .virtualpage:gt("+start+"):lt("+(items_per_page-1)+")").show();
 //return false;
}

function initPagination() {
	var num_entries = $('#searchResults .virtualpage').length;
	// Create pagination element
	$("#Pagination").pagination(num_entries, {
		num_edge_entries: 2,
		num_display_entries: 4,
		callback: pageselectCallback,
		items_per_page:10,
		showPageXofY : false
	});
	if (num_entries < 11) {
		$("#Pagination").hide();
	}
 }
 
//za paginaciju 2
var items_per_page2 = 1;
function pageselectCallback2(page_index, jq){
	$("#searchResults2 .virtualpage").hide();
	var start = page_index * items_per_page2;
	$("#searchResults2 .virtualpage:eq("+start+"), #searchResults2 .virtualpage:gt("+start+"):lt("+(items_per_page2-1)+")").show();
 //return false;
}

function initPagination2() {
	var num_entries = $('#searchResults2 .virtualpage').length;
	// Create pagination element
	$("#Pagination2").pagination(num_entries, {
		num_edge_entries: 2,
		num_display_entries: 5,
		callback: pageselectCallback2,
		items_per_page:1,
		showPageXofY : false
	});
	if (num_entries < 2) {
		$("#Pagination2").hide();
	}
 }
      
$(window).load(function() {
	//za search
	$("#search input").focus(function() {
		$(this).attr("value","");
	});
	
	//za caption
	$('.prImage').hover(function(){   
        $(this).children('.caption').css("width",$(this).width()-20)
		$('.slideshowImg').cycle('pause');
		$('.slideshowText').cycle('pause');
		$(this).children('.caption').slideDown("slow");
    },function(){   
		$(this).children('.caption').slideUp(500, function() {
    		$('.slideshowImg').cycle('resume');
			$('.slideshowText').cycle('resume');
  		});  
    });
	
	//za tooltip
	$('.tooltip').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		extraClass: "pretty",
		fixPNG: true,
		//opacity: 0.85,
		left: 10,
		top:-20
	});
	
	//ajax formular i validacija
	$("#name").attr("value","-- Enter name --");
	$("#adresa").attr("value","-- Enter email --");
	$("#phone").attr("value","-- Enter phone --");
	$("#mob").attr("value","-- Enter mobile --");
	$("#media").attr("value","-- Enter media name --");
	
	$(".subsInput").focus(function() {
						$(this).attr("value","");
					});
	$("#formSubs select").change(function() {
								  $(this).siblings(".jquery-selectbox-currentItem").removeClass("inactive");
						});
	
	
	var loader = jQuery('<img src="images/ajaxLoader.gif" alt="loading..." width="16" height="16"/>')
						.css({relative: "relative", top: "0", left: "0"})
						.appendTo("#loader")
						.hide();
	jQuery().ajaxStart(function() {
		loader.show();
	}).ajaxStop(function() {
		loader.hide();
		$(".subsCancel").click(function() {
			$("#emailSubs, #rssSubs").slideUp();
			return false;
		});
	}).ajaxError(function(a, b, e) {
		throw e;
	});
	jQuery.validator.messages.required = "";
	jQuery.validator.addMethod("notEqualTo", function(value, element, param) {
			return $(param).val()?(value != $(param).val()):(value != param);}, "error");
	$("#formSubs").validate({
		rules: {
			adresa: {
				required: true,
				email: true
			},
			name: {
				required: true,
				notEqualTo: "-- Enter name --"
			}
		},
		messages: {
			adresa: "",
			name: ""
		},
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed mandatory field!<br/>It has been highlighted above'
					: 'You missed ' + errors + ' mandatory fields!<br/>They have been highlighted above';
				$("div.errorContainer span").html(message);
				$("div.errorContainer").show();
			} else {
				$("div.errorContainer").hide();
			}
		},
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				target: "#emailInner"
			});
		}
	});
	
	//paginacija
	initPagination();
	initPagination2();
	
	//jednake visine
	$("#sortable2, #sortable3, #sortable4").equalHeights();
   
   //za tabove
   $("#tabs").tabs({ fx: { height: 'toggle' } });
   
   
   //za pretplatu
	$("#emailSubs, #rssSubs").css("display","none");
	$("#emailSubs, #rssSubs").css("visibility","visible");
	$("#emailSubs, #rssSubs").css("background-color","transparent");
	$("#rssShow").click(function() {
		$("#emailSubs").slideUp("slow", function() {
			$("#rssSubs").slideToggle();
			return false;
		});
	});
	$("#emailShow").click(function() {
		$("#rssSubs").slideUp("slow", function(){
			$("#emailSubs").slideToggle();
			return false;
		});
	});
	$(".subsCancel").click(function() {
		$("#emailSubs, #rssSubs").slideUp();
		return false;
	});
	$("#typeMedia").hide();
	$("input[name=subType]").click(function(){
		if ($("input[name=subType]:checked").val() == 'public') {
			$("#typeMedia").slideUp();
			$("#typePublic").slideDown();
		} else {
			$("#typePublic").slideUp();
			$("#typeMedia").slideDown();
		}
	});
});

