$().ready(function() {

    $('h1.portalHeading').each(function(){
         $(this).replaceWith("<h2 class='portalHeading'>" + $(this).html() + "</h2>")
    });
    $('h2.h2_portal').each(function(){
         $(this).replaceWith("<h3 class='h3_portal'>" + $(this).html() + "</h3>")
    });

    $('p.featured_heading').each(function(){
         $(this).replaceWith("<h3 class='quick_links'>" + $(this).html() + "</h3>")
    });
    $('.featuredBox').each(function(){
         $(this).replaceWith("<div class='quick_links_box'>" + $(this).html() + "</div>")
    });
    $('.featuredList').each(function(){
         $(this).replaceWith("<ul class='quick_links'>" + $(this).html() + "</ul>")
    });


$('.approved').remove();

    $('a#link-print-preview').printPreview();
	$('a#link-print-preview-form').printPreview();

//Colours alternating rows it a table unless the no_alternating class is supplied to the table
	$('table.tableStyle').each(function(){
		if($(this).hasClass('no_alternating')){
			return false;
		}
		else{
			$(this).find('tr:odd').addClass('tr1');
		}
	});

//Adds class to table if it doesnt have a thead so that th can be styled correctly
$('table').each(function(){
	if($(this).children('thead').length){
		return false;
	}
	else{
		$(this).addClass('no-thead');
	}
});

$('.flagged').each(function(){
        $(this).find('td:last-child').append("<img src='./?a=141988' alt='flagged'/>");    
});  

$('.remove').each(function(){
                $(this).find('td:last-child').append("<img src='./?a=142028' alt='remove'/>");
});

$('.updated').each(function(){
        $(this).find('td:last-child').append("<img src='./?a=142194' alt='updated'/>");    
});

$('#close-btn').click(function() {
   parent.history.back();
   return false;;
});

$.fn.search = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};
$("#search_bar").search();

//if IE6, reposition out of date toolbar
var Browser = {
  Version: function() {
    var version = 999; // we assume a sane browser
    if (navigator.appVersion.indexOf("MSIE") != -1)
      // bah, IE again, lets downgrade version number
      version = parseFloat(navigator.appVersion.split("MSIE")[1]);
    return version;
  }
}

if (Browser.Version() < 7) {
  $('body').prepend($('#review_bar_wrapper').remove().html());
}

$("#update_instructions").hide();
$(".review_update").bind("click", function(){
    $("#update_instructions").slideToggle('fast');
    $(this).toggleClass("active");
    return false;
});


    $('.approve').click(function(){
        if(!confirm('By clicking on the No Change button you are agreeing to approve this page content for another 12 months. If you agree please click on OK, otherwise click Cancel') )
        {
        return false;
        }
    });


    $('.review_reject').click(function(){
        if(!confirm('By clicking on Ok you will be sending an email to the DPI webteam to archive this page. If you do not want to proceed please click on Cancel.') )
        {
        return false;
        }
    });
	

    $('follow_up').click(function(){
        alert('This page has been flagged for review at a later date.')
    });	



 });
