
	

	function getWindowSize() {
		var result;
		if (parseInt(navigator.appVersion)>3) {
			if (navigator.appName=="Netscape") {
				result = {x:window.innerWidth, y: window.innerHeight};
			}
			if (navigator.appName.indexOf("Microsoft")!=-1) {
				result = { x: document.body.offsetWidth, y: document.body.offsetHeight};
			}
		}
		return result;
	}
	
	function hideRightPanel() {
		jQuery("#content .left").css('width', '100%'); 
		jQuery("#content .right").css('display', 'none').css('opacity','0').css('width', '0px');
	}
	function toggleRightPanelVisibility() {
		if (jQuery("#content .right").css('display')!=='none') {
			jQuery("#content .right").animate({width: '0px', opacity: 0}, function() {jQuery(this).css('display','none');});
			jQuery("#content .left").animate({width: '100%'});
		} else {
			jQuery("#content .right").show('slow').animate({width: '346px', opacity: 1});
			jQuery("#content .left").animate({width: '654px'});
		}
	}
	function flash() { 
		var g = jQuery(".expanded").eq(0); 
		if (jQuery(g).hasClass("flashed")) {
			jQuery(g).removeClass("flashed");
		} else {
			jQuery(g).addClass("flashed");			
		} 
	}
	function fixModerName() {
		jQuery(".ag_username").each(function() { 
			if (jQuery(this).html().match(/DaftViz/i)) 
				jQuery(this).append('<div class="u_description">Administratorius</div>');
			if (jQuery(this).html().match(/Jolka/i)) 
				jQuery(this).append('<div class="u_description">Moderatorius</div>');
			if (jQuery(this).html().match(/Evaldas/i)) 
				jQuery(this).append('<div class="u_description">Moderatorius</div>');
		});
	}
	function format(haystack, needle) {
		for (s in needle) { haystack = haystack.replace("%s", needle[s]); }
		return haystack;
	}

	function showAcaModule() {
		jQuery(".aca_button").slideUp('fast');
		jQuery(".aca_module").slideDown('fast');
	}
	
	var FBLikeArray = [];
	function FBLikeHover(obj, hover, id) {
		if (obj) {
			FBLikeArray[id] = [];
			FBLikeArray[id][0] = hover;
			FBLikeArray[id][1] = obj;
		}
		
		switch(hover) {
			case 1:
				FBLikeArray[id][2] = setTimeout("FBLikeHover(0, 2, '"+id+"')", 600);
				clearTimeout(FBLikeArray[id][3]);
				break;
			case 0:
				FBLikeArray[id][3] = setTimeout("FBLikeHover(0, 3, '"+id+"')", 600);
				clearTimeout(FBLikeArray[id][2]);
				break;
			case 2:
				if (FBLikeArray[id][0] == 1) {
					jQuery(FBLikeArray[id][1]).animate({height: '65px'}, 200);
				}
				break;
			case 3:
				if (FBLikeArray[id][0] == 0) {
					jQuery(FBLikeArray[id][1]).animate({height: '25px'}, 200);
				}
				break;
			default: break;
		}
	}
	
	function addLikeButton(a) {
		if (!jQuery(a).find('iframe').length) {
			var f = jQuery(a).prev().prev().find(".contentheading_news a").attr('href');  //Topic Heading Link
			if (!f) f = jQuery(a).prev().prev().find(".contentheading a").attr('href');  //Topic Heading Link
			
			f = f.replace("component/content/article","naujienos");
			// class="hidden FBLike" onload="$(this).slideDown(150);"
			// efektas
			jQuery(a).append('<center><img style="margin-bottom: 5px;" src="images/line.png" width="98%" height="1" /></center>');
			var fbkomentarai = '<iframe src="http://www.facebook.com/plugins/comments.php?locale=lt_LT&href=http://vikosa.lt%HREF&permalink=1" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:220px ;height:19px; float: left; margin-left: 5px; margin-top: 2px; text-align:left; " allowTransparency="true"></iframe> ';
	//		var googleplus = '<span style="float:right"><g:plusone size="medium" href=http://vikosa.lt%HREF></g:plusone></span>';
			var fbpatinka = '<iframe src="http://www.facebook.com/widgets/like.php?locale=lt_LT&href=http://vikosa.lt%HREF&send=false&layout=button_count&width=150&show_faces=false&action=recommend&colorscheme=light&font&height=25" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:25px; float: right; margin-left: 5px;margin-right: 5px;" allowTransparency="true"></iframe>';
			var tweets = '<span style="text-align: left;float: right; margin-left: 5px; margin-right: 5px;"><a href="http://twitter.com/share" class="twitter-share-button" data-text="" data-url="http://vikosa.lt%HREF" data-count="horizontal">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></span>';
	
			jQuery(a).append(fbpatinka.replace("%HREF", f));
			jQuery(a).append(tweets.replace("%HREF", f));
	//		jQuery(a).append(googleplus.replace("%HREF", f));
			jQuery(a).append(fbkomentarai.replace("%HREF", f));
			jQuery(a).append('<center><img style="margin-bottom: 5px;" src="images/line.png" width="98%" height="1"/></center>');
			
			jQuery(".FBLike").each(function() {
				if (!jQuery(this).hasClass("binded")) {
					jQuery(this).addClass("binded").hover(function() {
	//					$(this).stop("fx", false).animate({height: '80px'});
						FBLikeHover(this, 1, f);
					}, function() {
    //					$(this).stop("fx", false).animate({height: '30px'});
						FBLikeHover(this, 0, f);
					});
				}
			});
		}
	}

	function scrollChecker() {
		//var position = (navigator.appName == "Microsoft Internet Explorer")?document.body.scrollTop:window.pageYOffset;
		var position = 	(navigator.appName == "Microsoft Internet Explorer")?(
									(document.documentElement && document.documentElement.scrollTop)
									?document.documentElement.scrollTop 
									:document.body.scrollTop
						):window.pageYOffset;
//		document.title = t;
		jQuery(".article_separator").each(function() {
			if (jQuery(this).prev().offset().top - (getWindowSize().y*2/3) < position) {
				addLikeButton(this);
			}
		}); 
	}
	function bindScrollChecker() {
		setInterval("scrollChecker()",666);
	}
	
	window.onload = load;
	function load() {
		console.log(jQuery(".clr").length);
		if (jQuery(".article_separator").length > 1) bindScrollChecker();//ADD FACEBOOK LIKE BUTTON
		if (initLightbox) initLightbox();
	}	
	/**********************************************************************************************************/
	if (document.location.href.match("component/content/article")) {jQuery("body").hide(); document.location.href = document.location.href.replace("component/content/article","naujienos"); }
	if (document.location.href.match("www.vikosa.lt")) { jQuery("body").hide(); document.location.href=document.location.href.replace("www.vikosa.lt", "vikosa.lt");}
	if (document.location.href.match("option=com_content&task=view")) {jQuery("*").hide(); }
	
	jQuery(function() {
		if (document.location.href.match("option=com_content&task=view")) {jQuery("body").hide(); document.location.href = "http://vikosa.lt"+jQuery(".contentpagetitle").attr("href").replace("component/content/article","naujienos"); }
		
		/* ARTICLE FIX*/
		jQuery(".contentheading_news a").each(function() { jQuery(this).attr("href", jQuery(this).attr("href").replace("component/content/article","naujienos"))}); //Fix article links
		if (jQuery(".article_separator").length) jQuery(".article_separator").html("");


		/* MENU FIX*/ 
	//	$(".menu-son-of-suckerfish-horizontal li").eq(0).find("a").html("&nbsp;<img src='/images/system/home.png' style='position: relative; top: 3px'/>&nbsp;");
		jQuery("#active_menu-son-of-suckerfish-horizontal").html(format("<span>%s</span>", [jQuery("#active_menu-son-of-suckerfish-horizontal").html()]));
		jQuery(".mainlevel_active-son-of-suckerfish-horizontal").html(format("<span>%s</span>", [jQuery(".mainlevel_active-son-of-suckerfish-horizontal").html()]));

		/* PHOCA GALLERY FIX*/
		if (jQuery("#phocagallery").length) {
			jQuery("#phocagallery").find("a").click(function(event){ 
			    jQuery(".image-browser-root").css('position','fixed');
			});
			jQuery(window).resize(function() {
			    jQuery(".image-browser-root").css('position','fixed');
			});
		}
		
		/* AGORA FORUM FIX*/
		if (jQuery("#ag_agorawrap").length) {
			jQuery(".ag_pms_subject a").prepend("<font style='color: #999; font-size: 10px'>Tema:</font>"); 
			jQuery(".ag_userinfo").find("img").click(function() { jQuery(this).parent().next().slideDown('fast'); })
			jQuery(".ag_forumTools").find("ul ul").css('display','none').css('visibility','visible');
			jQuery(".ag_forumTools").hover(function() {jQuery(this).find("ul ul").slideDown('fast');}, function() {jQuery(this).find('ul ul').slideUp('fast')});
			jQuery('.ag_node ul').css('display','none').css('visibility', 'visible');
			jQuery(".ag_node").hover(function() {jQuery(this).find("ul").fadeIn('fast');}, function() {jQuery(this).find('ul').fadeOut('fast')});
			jQuery("#ag_footer > p").html("Vilniaus Kolegijos Studentų Atstovybė");
			fixModerName();
		}
		
	
		/* RIGHT PANEL FIX*/
		if (jQuery("title").html().match(/fotogalerija/i)) { hideRightPanel(); }
		if ((jQuery("input[value='Log out']").length || jQuery("input[value='Atsijungti']").length) && jQuery("#ag_agorawrap").length)  { hideRightPanel(); }
		
		if (jQuery("#roksearch_search_str").length)
			jQuery("#roksearch_search_str").bind("click",function(){
				if (jQuery(this).attr('value').match(/Search.../) || jQuery(this).attr('value').match(/paieškos/))
					jQuery(this).attr('value', "");
			});

		jQuery(".aquotes").bind("dblclick", function(){toggleRightPanelVisibility()});
//		setInterval("flash()", 400);
		
		jQuery("#lspduk>div").hide();
		jQuery("#lspduk>h3").bind("click", function() {
			if (jQuery(this).hasClass("selected")) {
				jQuery(this).removeClass("selected").next().slideUp('fast');
			} else {
				jQuery(this).addClass("selected").next().slideDown('fast');
			}
		});
		
	});
	

