// when document ready...
$(function() {
	removeDWStyles();
	moveMoveTos();
	useBgImg();
	dirtyNewsFix();
});



function makeSearch() {
  var text = $("#searchText").val();
  location.href = "/Default.aspx?ID=606&q="+text;
}



/**
 * Prints current page
 * @return {void}
 */
function printPage() {
	window.print();
}



/**
 * Removes stylesheet link created by Dynamic Web
 * putting in 'custom CSS' from DW Stylesheet module
 * @return {void}
 */
function removeDWStyles() {
	$("link[href^='/Files/Stylesheet']").remove();
}





/**
 * Removes left-margin for columns in a ".row .col" setup
 * So they adjust the full left-alignment
 * @return {void}
 */
function NoMarginLeft1stCol() {
	$(".row").each( function() {
		$(".col").eq(0).removeClass("marginLeft");
	} );
}





/**
 * Moves elements with the attribute "moveto" into another destination element
 * The destination element is determined by the value of the moveto-attribute
 * which is used as a selector
 * @return {void}
 */
function moveMoveTos() {
	$("[moveto]").each( function(i) {
		var moveObj = eval( '(' + $(this).attr('moveto') + ')' );
		var firstItem = (moveObj.first) ? ".eq(0)" : "";
		var execStr = "$('"+moveObj.destination+"')"+firstItem+"."+moveObj.moveMethod+"($(this));";
		eval(execStr);
	} );
}




/**
 * Sets and background image for all elements having a value in the attribute "usebgimg"
 * @return {void}
 */
function useBgImg() {
	$("[usebgimg]").each( function(i) {
		var useBgImg = $(this).attr('usebgimg');
		if(useBgImg!='')
			$(this).css('background','transparent url('+useBgImg+') no-repeat 0 0');
	} );
}




/**
 * A dirty fix to the buggy/lacking display of 
 * Unwanted BR elements in the description
 * DW news read-more text and link
 * @return {void}
 */
function dirtyNewsFix() {
	$(".newsList .item .description br").remove();
	$(".newsList .item div[align='right'] a").addClass("go").parent().removeAttr("align");
}
