jQuery.noConflict();

jQuery(document).ready(function() {

	var mouseover;
	
	jQuery(".logout").click(function () {
		jQuery(".tx-felogin-pi1 form").submit();
    });
	
	jQuery(".username-text input:text").focus(function () {
		jQuery(this).val("");
    	});
    	
	jQuery("input.form_bg").focus(function () {
		jQuery(this).val("");
	});

	jQuery("input:password").focus(function () {
       		jQuery(this).val("");
    	});

	jQuery("#top-middle-middle2-middle").html(jQuery(".search-hidden").html());
	
	jQuery(".top-links-signin-green").mouseover(function(){
	
		if (!mouseover) {
			mouseover = true;
			jQuery(".search").fadeOut("slow", function(){
				jQuery("#top-middle-middle2-middle").html(jQuery(".felogin-hidden").html());
				jQuery(".tx-felogin-pi1").show();	
				jQuery(".username-text input").focus(function () {
        				jQuery(this).val("");
        				jQuery("#top-middle-middle2-middle").stopTime("hide");
				});
				jQuery(".username-text input").blur(function () {
        				jQuery("#top-middle-middle2-middle").oneTime(5000, "hide", function() {
						jQuery("#top-middle-middle2-middle").html(jQuery(".search-hidden").html());
    						jQuery(".search").fadeIn("slow");
				   				
    						mouseover = false;
  					});
				});
				
			});
		
			jQuery("#top-middle-middle2-middle").stopTime("hide");
			jQuery("#top-middle-middle2-middle").oneTime(5000, "hide", function() {
				jQuery("#top-middle-middle2-middle").html(jQuery(".search-hidden").html());
    				jQuery(".search").fadeIn("slow");
				   				
    				mouseover = false;
  			});
  			
  		}	
			
	});
	
	
	/* IFRAME RESIZE */
	
	// Set specific variable to represent all iframe tags.
	var iFrames = document.getElementsByTagName('iframe');

	// Resize heights.
	function iResize() {
		// Iterate through all iframes in the page.
		for (var i = 0, j = iFrames.length; i < j; i++)	{
			// Set inline style to equal the body height of the iframed content.
			iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 50 + 'px';
			
		}
	}
	
	// Check if browser is Safari or Opera.
	if ( jQuery.browser.safari || jQuery.browser.opera) {
		// Start timer when loaded.
		jQuery('iframe').load(function() {
			setTimeout(iResize, 0);
		});
	
		// Safari and Opera need a kick-start.
		for (var i = 0, j = iFrames.length; i < j; i++) {
			var iSource = iFrames[i].src;
			iFrames[i].src = '';
			iFrames[i].src = iSource;
		}
	} else	{
		// For other good browsers.
		jQuery('iframe:not(.no-resize)').load(function() {
			// Set inline style to equal the body height of the iframed content.
			this.style.height = this.contentWindow.document.body.offsetHeight + 50 + 'px';
		});
	}
	
	
	/* IFRAME - END */
	
	/* TABS - UREDI */
	
	jQuery('#tab-container > ul').tabs();
	
	/* TABS - END */
	
	/* MOUSEOVER LEFT CORRECTION */
	var left = (jQuery(window).width()-1014)/2;

	jQuery('div:has(.mouseover-menu-firstpage)').css('left', left);
	jQuery('div:has(.mouseover-menu)').css('left', left);
	
	jQuery(window).bind('resize', function(){
		var leftResize = (jQuery(window).width()-1014)/2;
		if (leftResize < 0) leftResize = 5
		jQuery('div:has(.mouseover-menu-firstpage)').css('left', leftResize);
		jQuery('div:has(.mouseover-menu)').css('left', leftResize);
	});
	
	/* MOUSEOVER - END */
	
	/* SCROLLABLE 3-LEVEL MENU */
	
	if (jQuery('.scrollable .content').children().length > 10) {
		var counter;
		var counter2;
	   
	   	jQuery(".content").each(function() {
	      		counter = 1;
	      		jQuery(this).children("div").each(function() {
	      		if (jQuery(this).hasClass('thirdmeni-item-sel')) counter2 = counter;
	      			counter++;
	      		});
	    });
	   	
		var api = jQuery('.scrollable').scrollable({  
	    		size: 8, 
	    		vertical: true,
	    		next: 'div.next-wrapper',
	    		prev: 'div.prev-wrapper',
	    		items: '.content',
	    		clickSteps: 4,
	    		api: true
		});
		var length = jQuery('.scrollable .content').children().length;
		//length = length - 6;
		var offset = 4;
		var addoffset = 4;
		var cou = counter2;
		if (counter2 > ( length - 4)) {
			//length = length + 6;
			diff = length - cou;
			addoffset = addoffset - diff;
			offset += addoffset;
		}
		api.seekTo(counter2-offset);
	} else {
		jQuery('.prev-wrapper').remove();
		jQuery('.next-wrapper').remove();
		jQuery('.scrollable').css('height', jQuery('.scrollable .content').children().length*24);
	} 
	
	
	
	/*
	jQuery('.scrollable').scrollable({  
	    size: 11, 
	    vertical: true,
	    next: 'div.next-wrapper',
	    prev: 'div.prev-wrapper',
	    items: '.content'
	});
	*/
	/*
	var api = jQuery('.scrollable').scrollable({  
	    size: 11, 
	    vertical: true,
	    next: 'div.next-wrapper',
	    prev: 'div.prev-wrapper',
	    activeClass: 'active',
	    items: '.content',
	    api: true
	});
	
	api.move(1);
	
	
	api.onSeek(function() { 
		 
	    // inside callbacks the "this" variable is a reference to the API 
	    console.info("current position is: " + this.getIndex());
	    api.move(3);
	});
	*/
	
	
	/* SCROLLABLE - END */
	
	/* POZICIONIRANJE STIKER-JA - VIZITKA */
	if (jQuery('div.latest_news').length > 0 ) {
		
		var p = jQuery('.third-level-meni');
		var position = p.position();
	
		var leftOffset = 240;
		var topOffset = 135;
		
		var cssObj = {
	        	'position' : 'absolute',
	        	'left' : position.left-leftOffset+'px',
	        	'top' : position.top+topOffset+'px'
	      	}
	      	
		jQuery('.latest_news').css(cssObj);
		
		jQuery(window).resize(function(){
			position = p.position();
			
			var cssObj = {
	        		'position' : 'absolute',
	        		'left' : position.left-leftOffset+'px',
	      		  	'top' : position.top+topOffset+'px'
	      		}
	      	
			jQuery('.latest_news').css(cssObj);
		});
	
	}
	 
	/* STICKER END*/
	
	/* KROZKI */
	
	jQuery('.krozki_hidden').hide();
	jQuery('.hide_on_load').hide();
	
	jQuery('.delete_urnik').click(function() {
		jQuery(this).parent().parent().remove();
	});
	
	jQuery('.add_urnik_button').click(function() {
		var id = jQuery(this).attr('id');
		id = id.substring(id.lastIndexOf('_')+1); 
		var zaporedni_id = jQuery('#krozek_urnik_'+id+' .counter').val();
		if (!zaporedni_id) zaporedni_id=0;
		zaporedni_id++;
		jQuery('#krozek_urnik_'+id).append(getUrnikElement(id, zaporedni_id));
		jQuery('#krozek_urnik_'+id+' .counter').val(zaporedni_id);
		jQuery('.delete_urnik').click(function() {
			jQuery(this).parent().parent().remove();
		});
	});
	
	jQuery('.check').click( function () { 
		var id = jQuery(this).val();
		//var zaporedni_id = jQuery('#krozek_urnik_'+id+' .counter').val();
		//if (!zaporedni_id) zaporedni_id=0;
		if (this.checked) {
			
			//zaporedni_id++;
			//jQuery('#nov_urnik_'+id).show('fast');
			jQuery('#krozek_urnik_'+id).slideDown('slow', function() {
				jQuery('#nov_urnik_'+id).fadeIn('slow');
			});
			//if (jQuery('#krozek_urnik_'+id).html() == '') {
				//jQuery('#krozek_urnik_'+id).append(getUrnikElement(id, zaporedni_id));
				//zaporedni_id++;
				//jQuery('.delete_urnik').click(function() {
				//	jQuery(this).parent().remove();
				//});
				
				/*
				jQuery('#nov_urnik_'+id).click(function() {
					jQuery('#krozek_urnik_'+id).append(getUrnikElement(id, zaporedni_id));
					zaporedni_id++;
					jQuery('.delete_urnik').click(function() {
						jQuery(this).parent().remove();
					});
				});
				*/
			//}
			
		} else {
			//jQuery('#nov_urnik_'+id).hide('fast');
			//jQuery('#krozek_urnik_'+id).hide('slow');
			jQuery('#nov_urnik_'+id).fadeOut('slow', function() {
				jQuery('#krozek_urnik_'+id).slideUp('slow');
			});
		}
	
	});
	
	/* KROZKI - END */
	
	/* OSEBNA OBVESTILA - UREJANJE */
	
	jQuery('.remove_notice').toggle(
		function() {
			var $rootTr = jQuery(this).parent().parent();
			var $hideTr = jQuery(this).parent().parent().children('.notice_data');
			$hideTr.fadeTo('slow', 0.33);
			jQuery(this).html('<img src="http://www.ssgt.si/fileadmin/templates/ssgt-nova/images/plus-18h.jpg" alt="dodaj"/>');
			//	jQuery(this).parent().parent().remove();
			var ids = jQuery('#remove_ids').val();
			//ids = ids+$rootTr.children(':first').children(':first').val()+',';
			ids = ids+jQuery(this).prev().val()+',';
			jQuery('#remove_ids').val(ids);
		}, 
		function() {
			var $rootTr = jQuery(this).parent().parent();
			var $hideTr = jQuery(this).parent().parent().children('.notice_data');
			$hideTr.fadeTo('slow', 1);
			jQuery(this).html('<img src="http://www.ssgt.si/fileadmin/templates/ssgt-nova/images/minus-18h.jpg" alt="odstrani"/>');
			var ids = jQuery('#remove_ids').val();
			//var restoreId = $rootTr.children(':first').children(':first').val();
			var restoreId = jQuery(this).prev().val();
			var temp = ids.split(',');
			var tempString = '';
			for ( var i in temp ) {
				if (temp[i] != restoreId) tempString += temp[i]+',';
			}
			tempString = tempString.slice(0, -1)
			//tempString = tempString.substring(tempString.lastIndexOf(',')); 
			jQuery('#remove_ids').val(tempString);
		}
	);
	
	/* OSEBNA OBVESTILA - END*/
	
	/*GALERIJA*/
	
	var galleries = jQuery('.ad-gallery').adGallery({
		loader_image: 'fileadmin/templates/ssgt-nova/images/loader.gif',
		width: false, // Width of the image, set to false and it will read the CSS width
		height: 400, // Height of the image, set to false and it will read the CSS height
		thumb_opacity: 0.7, // Opacity that the thumbs fades to/from, (1 removes fade effect)
		                      // Note that this effect combined with other effects might be resource intensive
		                      // and make animations lag
		start_at_index: 0, // Which image should be displayed at first? 0 is the first image
		animate_first_image: false, // Should first image just be displayed, or animated in?
		animation_speed: 400, // Which ever effect is used to switch images, how long should it take?
		display_next_and_prev: true, // Can you navigate by clicking on the left/right on the image?
		display_back_and_forward: true, // Are you allowed to scroll the thumb list?
		scroll_jump: 0, // If 0, it jumps the width of the container
		slideshow: {
			enable: false,
		    autostart: false
		},
		effect: 'slide-hori', // or 'slide-vert', 'resize', 'fade', 'none' or false
		enable_keyboard_move: true, // Move to next/previous image with keyboard arrows?
		cycle: true, // If set to false, you can't go from the last image to the first, and vice versa
		// All callbacks has the AdGallery objects as 'this' reference
		callbacks: {
		    // Executes right after the internal init, can be used to choose which images
		    // you want to preload
		    init: function() {
		      	// preloadAll uses recursion to preload each image right after one another
		    	this.preloadAll();
		    	// Or, just preload the first three
		    	//this.preloadImage(0);
		    	//this.preloadImage(1);
		    	//this.preloadImage(2);
			},
			/*afterImageVisible: function() {
			      // For example, preload the next image
			      var context = this;
			      this.loading(true);
			      this.preloadImage(this.current_index + 1);
			      this.preloadImage(this.current_index + 2,
			    	function() {
			          			// This function gets executed after the image has been loaded
			          	context.loading(false);
			        }
			      );
			},
			*/

		}
	});
	
	/* GALERIJA - END*/
	/* DATEPICKER OBVESTILA */
	
	jQuery("input[name='tx_cwtfeedit_pi1[starttime]'], input[name='tx_cwtfeedit_pi1[endtime]']").datepicker({ 
		dateFormat: 'd.m.yy',
		changeYear: false,
		dayNames: ['Nedelja', 'Ponedeljek', 'Torek', 'Sreda', 'Četrtek', 'Petek', 'Sobota'],
		dayNamesMin: ['Ne', 'Po', 'To', 'Sr', 'Če', 'Pe', 'So'],
		dayNamesShort: ['Ned', 'Pon', 'Tor', 'Sre', 'Čet', 'Pet', 'Sob'],
		firstDay: 1,
		monthNames: ['Januar','Februar','Marec','April','Maj','Junij','Julij','Avgust','September','Oktober','November','December'],
		monthNamesShort : ['Janr','Feb','Mar','Apr','Maj','Jun','Jul','Avg','Sep','Okt','Novr','Dec'],
		showOn: 'button', 
		buttonImage: 'fileadmin/templates/ssgt-nova/images/calendar.jpg', 
		buttonImageOnly: true
	});

	
	/* DATEPICKER OBVESTILA - END*/
	
	jQuery("#noticeedit").click(function() {
		jQuery("#noticeform").attr("action", "/spletna-ucilnica/obvestila/?no_cache=1#tab-2");
		jQuery("#noticeform").submit();
	});
	
});

function getUrnikElement(krozekID, number) {
	//var style = '' ;
	//if (number != 1) style = 'style="margin-top: 5px;"';
	var style = 'style="margin-top: 5px;"';
	return '<div '+style+'><div style="float:left;"><input type="input" class="urnik_input_' + krozekID + '"  name="tx_4sfeuserediting_pi1[krozek_checkbox.][' + krozekID + '][urnik][' + number + ']" value="" /></div><div style="float:left;"><a class="delete_urnik"><img alt="odstrani" src="fileadmin/templates/ssgt-nova/images/minus.jpg"/></a></div><div class="clear"></div></div>';
	
}

var idIntervalIframe;
function loadBlogAddress(naslov, idframe){
  var refpage;
  top.location.href = 'http://www.ssgt.si/sola/blog/';
  idIntervalIframe = setInterval("loadBlog()",5000); 
}

function loadBlog(){
  if (top.frames[0] != null) {
    top.frames[0].location.href='http://www.google.com/'
    clearInterval(idIntervalIframe); 
    idIntervalIframe = nothing; 
  }
}

function userLogout(){
   jQuery("tx-felogin-pi1 form").submit();
}

