/*TABLE OF CONTENTS for init.js
--------------------------------------------
- ie6 hover
- Unobtrusively add elements required
- Home page slide show
- News slide show
- Can you help us slide show
- Counting functions
- Search add default values
- Increase and decrease text size
- Equal heights of columns
- Recruitment carousel
*/
$(document).ready(function() {		
	//add hover state for ie6  
	  $("#main-navigation li").hover(
	  function () {
		$(this).addClass("hover");
	  },
	  function () {
		$(this).removeClass("hover");
	  }
	);
	//Unobtrusively add elements required
	$('#utilities').prepend(
			'<a id="increase-text-size" class="increase" title="Increase text size" href="#">Increase text size</a>' +
			'<a id="decrease-text-size" class="decrease" title="Decrease text size" href="#">Decrease text size</a>' +
			'<a id="print-this-page" title="Print this page" href="javascript:window.print()">Print this page</a>'
	);
	$('#utilities-bottom').prepend(
			'<a id="increase-text-size-bottom" class="increase" title="Increase text size" href="#">Increase text size</a>' +
			'<a id="decrease-text-size-bottom" class="decrease" title="Decrease text size" href="#">Decrease text size</a>' +
			'<a id="print-this-page-bottom" title="Print this page" href="javascript:window.print()">Print this page</a>'
	);
	$('#footer').prepend(
	'<a class="addthis_button" href="http://www.addthis.com/bookmark.php?v=250&amp;username=xa-4b78cfa276c39f66">' +
	'<img src="/__data/assets/image/0008/197090/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/>' +
	'</a>' +
	'<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4b78cfa276c39f66"></script>'
	);	
	//Home page slide show
	if ($('#image-gallery').length) {
		$('#image-gallery').before('<div id="nav" class="nav">').cycle({
			fx:     'fade',
			speed:  'slow',
			timeout: 5000,
			pager:  '#nav'
		});
	}
	//News slide show
	

	if ($('#news-gallery').length) {
		$('#news-gallery').removeClass("javascript-disabled").cycle({
			fx:     'fade',
			speed:  'slow',
			timeout: 5000,
			prev:   '#news-previous-item', 
			next:   '#news-next-item', 
			after: 	current_count
		});
	}

	//Can you help us slide show
	if ($('#can-you-help-us-gallery').length) {
		$('#can-you-help-us-gallery').removeClass("javascript-disabled").cycle({
			fx:     'fade',
			speed:  'slow',
			timeout: 5000,
			prev:   '#cyhu-previous-item', 
			next:   '#cyhu-next-item',
			after: 	current_count1
		});
	}
	//Counting functions
	function current_count(curr, next, opts) {
	var item_count = "More news stories " + (opts.currSlide+ 1) + '/' + opts.slideCount;
	$('p.counter').html(item_count);
	}; 
	function current_count1(curr, next, opts) {
	var item_count = "More can you help us " + (opts.currSlide+ 1) + '/' + opts.slideCount;
	$('p.current1').html(item_count);
	}; 	
	//Search add default values
	//$('#header input[type=text]').defaultValue('Enter keyword...');
	if ($('#panel-your-police').length) {
		$('#panel-your-police input[type=text]').defaultValue('Enter postcode or suburb');
	}
	//Increase and decrease text size
	$("#content-main").textResize($("a.decrease"), $("a.increase"), $("#reset"), {baseFontSize: "1em", maxZoom: .5, steps: 3});
	//$("#content-main").textResize($("#decrease-text-size-bottom"), $("#increase-text-size-bottom"), $("#reset"), {baseFontSize: "1em", maxZoom: .5, steps: 3});
	
	
	//Equal heights of columns
	function equalHeight(group) {
	tallest = 0;
	group.each(function() {
	thisHeight = $(this).height();
	if(thisHeight > tallest) {
		tallest = thisHeight;
		}
	});
	group.height(tallest);
	}
	
	equalHeight($(".equal-height"));
	
	
	//Increase decrease News and Can You Help Us in accordance with cookie from text resize
	starting_height = $('#panel-news .panel-content').height(); 
	
	if ($.cookie('fontZoomStep') == 2){
		$('#panel-news .panel-content').height(starting_height + 50);
		$('#panel-can-you-help-us .panel-content').height(starting_height + 50);
	}
	if ($.cookie('fontZoomStep') == 3){
		$('#panel-news .panel-content').height(starting_height + 100);
		$('#panel-can-you-help-us .panel-content').height(starting_height + 100);
	}

	$("a.increase").click(function() {

		if ($.cookie('fontZoomStep') == 2){
			$('#panel-news .panel-content').height(starting_height + 50);
			$('#panel-can-you-help-us .panel-content').height(starting_height + 50);
		}
		if ($.cookie('fontZoomStep') == 3){
			$('#panel-news .panel-content').height(starting_height + 100);
			$('#panel-can-you-help-us .panel-content').height(starting_height + 100);
		}
	
		equalHeight($(".equal-height"));
	
	});
		
	$("a.decrease").click(function() {

		
		if ($.cookie('fontZoomStep') == 1){
			$('#panel-news .panel-content').height(starting_height);
			$('#panel-can-you-help-us .panel-content').height(starting_height);
		}
		if ($.cookie('fontZoomStep') == 2){
			$('#panel-news .panel-content').height(starting_height + 50);
			$('#panel-can-you-help-us .panel-content').height(starting_height + 50);
		}
	
		equalHeight($(".equal-height"));
		
		
		
	});
	//Recruitment carousel
	if ($('#mycarousel').length) {
	jQuery("#mycarousel").removeClass("javascript-disabled").addClass("jcarousel-skin").jcarousel({
		scroll: 1
	});
	}
});
