$(document).ready(function() {
try{

	$('a.btnNewsletterSettings').parent().find(".newsletterSettings").hide();

	$('a.btnNewsletterSettings').live("click", function(){
		$(this).blur();
		var panel = $(this).parent().find(".newsletterSettings");
		
		if(panel.is(".rollin"))
		{  }
		else
		{
			panel.addClass("rollin");
			panel.stop().slideToggle(250, function(){ 
				panel.removeClass("rollin");
			});
		}
		return false;
	});

}catch(ex){}

try{
	$(".content").each(function(){
		$(this).find("a").each(function(){
			$(this).css("color", $(this).parents(".content").css("color"));
		});
	});
}catch(ex){}

try{
	$('div.block_img').each(function(){
		
		if($(this).find('a:first').length > 0)
		{
			$(this).css('cursor','pointer');
			$(this).bind('click', function() {
				var link = $(this).find('a:first').attr('href');
				if (link.indexOf(location.hostname) == -1)
					window.open (link,"mywindow"); 
				else
					location.href = link;
			});
		}
	});
}catch(ex){}

try{
	// doc2form styling
	$('.Doc2Form .umbEditorTextField').each(function(){
		$(this).before($('<div class="newsletter_front png_bg">&nbsp;</div>'));
		$(this).after($('<div class="newsletter_back png_bg">&nbsp;</div>'));
	});
	$('.Doc2Form input[type="checkbox"]').each(function(){
		
		var txt = $(this).prev().text();
		$(this).prev().html('&nbsp;');
		$(this).addClass('checkbox');
		$(this).next().text(txt).addClass('checkboxLabel');
		//$(this).after($('<label for="' + $(this).attr('id') + '">&nbsp;</label>').text(txt));
		//alert($(this).attr('class'));
	});
}catch(ex){}

try{
	/* link icons */
	var parentSelector = "#blocks ";
	// Add pdf icons to pdf links
	$(parentSelector + "a[href$='.pdf']").addClass("pdf").addClass("png_bg").attr("target", "_blank");
 
	// Add txt icons to document links (doc, rtf, txt)
	$(parentSelector + "a[href$='.doc'], a[href$='.txt'], a[href$='.rtf']").addClass("txt").addClass("png_bg").attr("target", "_blank");
 
	// Add zip icons to Zip file links (zip, rar)
	$(parentSelector + "a[href$='.zip'], a[href$='.rar']").addClass("zip").addClass("png_bg").attr("target", "_blank");

	// Add email icons to email links
	// not used Gino was not in favor of icons in front of email links
	// $(parentSelector + "a[href^='mailto:']").addClass("email").addClass("png_bg");
 
	// add pngfix to buttons in rte environement
	$(parentSelector + ".richtextButtonBig").addClass("png_bg");
	$(parentSelector + ".richtextButtonSmall").addClass("png_bg");

	//Add external link icon to external links - 
	$(parentSelector + 'a').filter(function() {
		//Compare the anchor tag's host name with location's host name
	    return this.hostname && this.hostname !== location.hostname;
	  }).attr("target", "_blank"); // pssible to add  .addClass("external").addClass("png_bg");



	/* end link icons */

}catch(ex){}

try{

    // THIS IS NEW CODE FOR THE AUTOMATIC INFINITE CAROUSEL

    	var autoscrolling = false;

    	$('.carrouselcontent').infiniteCarousel().mouseover(function () {
    	    autoscrolling = false;
    	}).mouseout(function () {
    	    autoscrolling = true;
    	});
    
    	setInterval(function () {
       	if (autoscrolling) {
        	    $('.carrouselcontent').trigger('next');
        	}
    	}, 5000);
}catch(ex){}
});