function hoverWithColor(){
    $('.asset-abstract, .asset-content').hover(function(event){
        $(this).dequeue();
        /*$(this).animate({"backgroundColor":"#FEA767"},500,null);*/
        $(this).animate({
            "backgroundColor":"#FB8832"
        },500,null);
    },function(event){
        $(this).dequeue();
        $(this).animate({
            "backgroundColor":"#EEF0F2"
        },500,null);
    }
    );
}

//var defaultGlobalHeight = '100%';
var minmaxIndicator = ["[-]","[+]"];

function initClickableAssetPublishers(portletInstanceCountPosition){
    var defaultGlobalHeight = $('.portlet-asset-publisher .portlet-body').eq(portletInstanceCountPosition).height();//not really global
    $('.portlet-asset-publisher h1.portlet-title').each(function(){
        if($(this).has('.minmax-indicator').length==0){
            $(this).append('<span class="minmax-indicator">'+minmaxIndicator[0]+'</span>');
            $(this).find('.minmax-indicator').css('float','right');
        }
    });


    $('.portlet-asset-publisher h1.portlet-title').eq(portletInstanceCountPosition).click(function(){
        if($(this).parents('.portlet-asset-publisher').find('.portlet-body').height()==0){
            $(this).parents('.portlet-asset-publisher').find('.portlet-body').find('div').show();
            $(this).parents('.portlet-asset-publisher').find('.portlet-body').animate({
                height:defaultGlobalHeight
            },500,null,function(){
                //$(this).parents('.portlet-asset-publisher').find('.portlet-body').find('div').show();
                });
            $(this).find('.minmax-indicator').text(minmaxIndicator[0]);
        }else{
            minimizeAssetPublisher(portletInstanceCountPosition);
        //            if(defaultGlobalHeight<$(this).parents('.portlet-asset-publisher').find('.portlet-body').height()){
        //                defaultGlobalHeight = $(this).parents('.portlet-asset-publisher').find('.portlet-body').height();
        //            }
        //            $(this).parents('.portlet-asset-publisher').find('.portlet-body').animate({
        //                height:'0px'
        //            },500,null,function(){
        //                $(this).find('div').hide();
        //            });
        //            $(this).find('.minmax-indicator').text(minmaxIndicator[1]);
        }
    });
    $('.portlet-asset-publisher h1.portlet-title').css('cursor','pointer');
}

function minimizeAssetPublisher(portletInstanceCountPosition){
    /*if(defaultGlobalHeight=='100%'){
		defaultGlobalHeight = $('.portlet-asset-publisher .portlet-body').height();
	}*/

    $('.portlet-asset-publisher .portlet-body').eq(portletInstanceCountPosition).animate({
        height:'0px'
    },500,null,function(){
        $(this).find('div').hide()
    });
	
    if($('.portlet-asset-publisher h1.portlet-title').eq(portletInstanceCountPosition).has('.minmax-indicator').length>0){
        $('.portlet-asset-publisher h1.portlet-title').eq(portletInstanceCountPosition).find('.minmax-indicator').text(minmaxIndicator[1]);
    }else{
        $('.portlet-asset-publisher h1.portlet-title').eq(portletInstanceCountPosition).append('<span class="minmax-indicator">'+minmaxIndicator[1]+'</span>');
        $('.portlet-asset-publisher h1.portlet-title').eq(portletInstanceCountPosition).find('.minmax-indicator').css('float','right');
    }
	
}

function clickAssetPublisher(portletInstanceCountPosition){
    $('.portlet-asset-publisher h1.portlet-title').eq(portletInstanceCountPosition).click();
}

function mapPortletToPortlet(fromPortletId, toPortletId){
    $('.portlet').each(function(){
	
        if($(this).attr('id').indexOf(fromPortletId)!=-1){
            $(this).find('a').each(function(){
                if($(this).attr('href').indexOf(fromPortletId)!=-1){
                    var oldURL = $(this).attr('href');
                    var newURL = oldURL.replace(fromPortletId,toPortletId);
                    $(this).attr('href',newURL);
                }
            });
        }
    });
}

function mapPortletFromPortlet(fromPortletId, toPortletId){
    $('.portlet').each(function(){
	
        if($(this).attr('id').indexOf(toPortletId)!=-1){
            $(this).find('a').each(function(){
                if($(this).attr('href').indexOf(fromPortletId)!=-1){
                    var oldURL = $(this).attr('href');
                    var newURL = oldURL.replace(fromPortletId,toPortletId);
                    $(this).attr('href',newURL);
                }
            });
        }
    });
}

function switchHeaderImage(homeURL){
    if(window.location.href != homeURL && window.location.href != (homeURL+"/home")){
        var randomNumber = Math.random() * 13;
        randomNumber = Math.ceil(randomNumber);
        var i = new Image();
        i.src = '/idef2-theme/images/header_images/'+randomNumber+'_bottom_header_bg.jpg';
        $(i).load(function(){
            $('#header_bottom').fadeOut(500, function(){
                $(this).css('background-image','url("/idef2-theme/images/header_images/'+randomNumber+'_bottom_header_bg.jpg")');
            });
            $('#header_bottom').fadeIn(1000);
        });
    }
}


