/* begin - CROZ, mgamulin, 20100715 - CQ VIP00000013 */
function iconWrapperHighlight(_iconWrapper, _value) {
	if (_value) {
		jQuery(_iconWrapper).css('background-color', '#F1F1F1');
		jQuery(_iconWrapper).css('text-decoration', 'underline');
	}
	else {
		jQuery(_iconWrapper).css('background-color', 'transparent');
		jQuery(_iconWrapper).css('text-decoration', 'none');
	}
}
/* end - CROZ, mgamulin, 20100715 - CQ VIP00000013 */

jQuery(document).ready(function()
{
	jQuery('.lfr-portlet-used').addClass('lfr-portlet-really-used');
	/* IE FIXES */
	if(jQuery.browser.msie && jQuery.browser["version"] < 8.0)
		jQuery('.movable_boxes .portlet .portlet-wrapper .portlet-content').css({"zIndex" : "-1"});
		
	/* begin - CROZ, mgamulin, 20100715 - CQ VIP00000013 */
	jQuery(".web_services .icons .iconWrapper").hover(
		function(){
			iconWrapperHighlight(this, true);
		},
		function() {
			iconWrapperHighlight(this, false);
		}
	);
	/* end - CROZ, mgamulin, 20100715 - CQ VIP00000013 */


	/* LOGIN BOX */

    /*ST*/
	var time = 100;

	jQuery(".header .container .login a.do_login").bind("click", function()
	{
		jQuery(".header .container .login").addClass("open_login").animate({"height" : "143px"}, time);

		if(jQuery.browser.msie && 6.0 >= jQuery.browser["version"])
			jQuery(".header .container .login").css({"backgroundPosition" : "-306px bottom"});

		jQuery(".header .container .login .closed, .header .container .login .temp").hide();
		jQuery(".header .container .login .open").fadeIn();

		return false;
	});

	jQuery(".header .container .login a.do_login_temp").bind("click", function()
	{
		jQuery(".header .container .login").addClass("open_temporary").removeClass("open_login").animate({"height" : "115px"}, time);

		if(jQuery.browser.msie && 6.0 >= jQuery.browser["version"])
			jQuery(".header .container .login").css({"backgroundPosition" : "-306px bottom"});

		jQuery(".header .container .login .closed, .header .container .login .open").hide();
		jQuery(".header .container .login .temp").fadeIn();

		return false;
	});

	jQuery(".header .container .login a.close").bind("click", function()
	{
		jQuery(".header .container .login").animate({"height" : "43px"}, time);

		if(jQuery.browser.msie && 6.0 >= jQuery.browser["version"])
			jQuery(".header .container .login").css({"backgroundPosition" : "left top"});

		jQuery(".header .container .login .open, .header .container .login .temp").hide();
		jQuery(".header .container .login .closed").fadeIn();

		setTimeout('jQuery(".header .container .login").removeClass("open_temporary").removeClass("open_login")', time - 50);

		return false;
	});


	/* VALIDATION */

	function form_validate(what)
	{
		if( "imenik" == what )
		{
			if( "" == jQuery(".imenik_prezime").val() && "" == jQuery(".imenik_tvrtka").val() && "" == jQuery(".imenik_broj").val() )
			{
				jQuery(".info_field").css({"color" : "#D40023"}).fadeOut().fadeIn().fadeOut().fadeIn();
				return false;
			}
		}
	}
	
	/* SERVICE BOX SIDE SCROLLER */
	var sbss_num_items = jQuery(".web_services .icons_clip .icons .iconWrapper").length;

	if( sbss_num_items > 0 && jQuery("a.wsc").length > 0 )
	{
		var sbss_item_width = jQuery(".icons_clip .icons .iconWrapper").width();
		var ssbs_container_width = sbss_num_items * sbss_item_width;
		var sbss_current_location = -43;
		var time = 100;

		jQuery("a.wsc").show();

		jQuery(".icons_clip").css({"width" : (sbss_item_width*9) + "px", "height" : "110px", "overflow" : "hidden", "position" : "relative", "marginLeft" : "43px"});
		jQuery(".icons_clip .icons").css({"position" : "absolute", "top" : 0, "left" : "-43px" });
		jQuery(".icons_clip .icons").width( ssbs_container_width );

		jQuery('[class*="wsc"]').bind("click", function()
		{
			sbss_current_location = parseInt( jQuery(".icons_clip .icons").css("left") );

			if( jQuery(this).hasClass("services_previous") )
			{
				if( -43 > sbss_current_location )
				{
					if( !jQuery(".icons_clip .icons").is(":animated") )
						jQuery(".icons_clip .icons").animate({"left" : (sbss_current_location + sbss_item_width) + "px"}, time);
				}
			}
			else
			{
				if( -((ssbs_container_width+43)-(sbss_item_width*9)) < sbss_current_location )
				{
					if( !jQuery(".icons_clip .icons").is(":animated") )
						jQuery(".icons_clip .icons").animate({"left" : (sbss_current_location - sbss_item_width) + "px"}, time);
				}
			}

			return false;
		});
	}
	

	/* IMENIK */

	jQuery(".imenik .column .featured form .submit").bind("click", function()
	{
		return form_validate("imenik");
	});

	/***ST***/

	/*LOAD SERVICE BOX DOCK*/
	if (typeof(CustomLayoutConfigurationVM) != 'undefined') {
		CustomLayoutConfigurationVM.showDock();
	}
	/*Override click event on links in footer*/
	jQuery('.ajaxLink').each(function()
	{
		jQuery(this).click(function(event){
			var popup = Liferay.Popup({
				position:[150,150],
				modal:false,
				width:500

			});

			var url = jQuery(this).attr("href");
			jQuery(popup).load(url);
			event.preventDefault();
		});
	});
	removeLoadingPortlets();
});
function removeLoadingPortlets() {
	/*
	var location = jQuery("#locationToRefreshTo").val();
	jQuery(document).everyTime(10000, function(i) {
		jQuery(".loading-animation").each(function(index) {
			var timeCreated = parseInt(jQuery(this).attr("time"));
			var timePassed = new Date().getTime() - timeCreated;
			//use jquery.isready not to refresh more than once
			if (jQuery.isReady && timePassed >= 200000) {
				window.location = location;
			}
		});
	});
	*/
}

function checkPortletOptions(portletOptions, firstEntry) {
	var otherPlaceholder = jQuery(portletOptions.placeHolder);
	return checkPlaceholderPosition(otherPlaceholder);
}

function checkPlaceholderPosition(placeHolder) {
	var column = placeHolder.parent();
	if (typeof(column) == 'undefined') {
		return false;
	} else {
		var column0 = column[0];
		if (typeof(column0) == 'undefined') {
			return false;
		} else if (typeof(column0.id) == 'undefined') {
			return false;
		}
	}
	return true;
}
