$(document).ready(function () {
   // accordion like 1
	function initAcc1(){
		$('ul.accordion').accordion({
			active: ".active",
			autoHeight: false,
			header: ".open-close",
			collapsible: true,
			event: "click"
		});
	}

	// accordion like 2
	function initAcc2(){
		var _max = 590;
		var _cen = 333;
		var _min = 210;
		var _speed = 500;
		var _hold = $('#promo-hold');
		if(_hold.length){
			var _list = _hold.find('div.promo-box');
			var box_list = _list.find('.must-hide');
			var _a = _list.index(_list.filter('.active:eq(0)'));
			if(_a == -1) _list.width(_cen).removeClass('active');
			else _list.width(_min).removeClass('active').eq(_a).addClass('active').width(_max);
			
			_list.each(function(_i){
				var _el = $(this);
				var _box = _el.find('.must-hide');
				if(_i == _a){
					if($.browser.msie) _box.css({visibility:'visible'});
					else _box.css({visibility:'visible', opacity: 1});
				}
				else{
					if($.browser.msie) _box.css({visibility:'hidden'});
					else _box.css({visibility:'hidden', opacity: 0});
				}
				_el.mouseenter(function(){
					if($.browser.msie) box_list.not(_box).css('visibility', 'hidden');
					else box_list.not(_box).stop().animate({opacity: 0}, _speed/2, function(){$(this).css('visibility', 'hidden');});
					_list.stop().removeClass('active').animate({width: _min}, _speed);
					_el.stop().addClass('active').animate({width: _max}, _speed, function(){
						if($.browser.msie) _box.css('visibility', 'visible');
						else _box.stop().css('visibility', 'visible').animate({opacity: 1}, _speed/2);
					});
					_a = _i;
				});
			});
		}
	}

	// popups
	function initPopups(){
		var _list = $('#photo-list > div');
		var _a = -1;
		$('#photo-list > div').each(function(_i){
			var _el = this;
			_el._popup = $(_el).children('div.tooltip');
			_el._btn = $(_el).children('a.lnk-img');
			
			if($.browser.msie) _el._popup.hide();
			else _el._popup.css({opacity: 0, display:'none'});
			_el._btn.click(function(){
				if(_a != -1){
					_list.removeClass('opened');
					_list.get(_a)._btn.removeClass('active-img');
					if($.browser.msie) _list.get(_a)._popup.hide();
					else _list.get(_a)._popup.stop().animate({opacity: 0}, 300, function(){ $(this).hide();});
				}
				if(_a != _i){
					$(_el).addClass('opened');
					_el._btn.addClass('active-img');
					if($.browser.msie) _el._popup.show();
					else _el._popup.stop().show().animate({opacity: 1}, 300);
					_a = _i;
				}
				return false;
			});
			
		});
	}

	// slide animation
	function initSlide(){
		$('div.myths-container div.myths-box').each(function(){
			var _hold = $(this);
			var _box = _hold.find('.slide');
			var _btn = _hold.find('.myths-text');
			var _h = _box.height();
			if(_hold.hasClass('active')) _box.show();
			else _box.hide();
			
			_btn.click(function(){
				if(_hold.hasClass('active')){
					_hold.removeClass('active');
					_box.stop().animate({height:0}, 400, function(){ $(this).css({display:'none', height:'auto'});});
				}
				else{
					_hold.addClass('active');
					if(_box.is(':hidden')){
						_box.show();
						_h = _box.height();
						_box.height(0);
					}
					_box.stop().animate({height: _h}, 400, function(){ $(this).css({height:'auto'});});
				}
				return false;
			});
		});
	}

	// Init
   initAcc1();
	initAcc2();
	initPopups();
	initSlide();
	
	// FontSizer
	$.FontSizer.Init();

	// DropDown
	$('.dropNetwork li.title:eq(3)').appendTo('.dropNetwork ul.col2');
	$('.dropNetwork li.title:eq(3)').appendTo('.dropNetwork ul.col2');
	$('.dropNetwork li.title:eq(3)').appendTo('.dropNetwork ul.col2');
	$('.dropNetwork li.title:eq(3)').appendTo('.dropNetwork ul.col3');
	$('.dropNetwork li.title:eq(3)').appendTo('.dropNetwork ul.col3');
   
	$('.dropResources li.title:last').appendTo('.dropResources ul.col2');

	$('.dropAuthority li.title:eq(4)').appendTo('.dropAuthority ul.col2');
	$('.dropAuthority li.title:eq(4)').appendTo('.dropAuthority ul.col2');
	$('.dropAuthority li.title:eq(4)').appendTo('.dropAuthority ul.col2');
	$('.dropAuthority li.title:eq(4)').appendTo('.dropAuthority ul.col2');
	$('.dropAuthority li.title:eq(4)').appendTo('.dropAuthority ul.col3');
	$('.dropAuthority li.title:eq(4)').appendTo('.dropAuthority ul.col3');
	$('.dropAuthority li.title:eq(4)').appendTo('.dropAuthority ul.col3');
	$('.dropAuthority li.title:eq(4)').appendTo('.dropAuthority ul.col3');
	$('.dropAuthority li.title:eq(4)').appendTo('.dropAuthority ul.col3');
	$('.dropAuthority li.title:eq(4)').appendTo('.dropAuthority ul.col3');
	$('.dropAuthority li.title:eq(4)').appendTo('.dropAuthority ul.col3');
	
	// Google Analytics
	$('.medicareLink').click(function(){
      pageTracker._trackEvent('Outbound Links', 'medicareaustralia.gov.au/public/services/aodr', 'RegisterYourDecisionLinkExpanaBox');
      pageTracker._trackPageview('/Goal/Register-your-decision');
   });
   $('.medicareLink2').click(function(){
      pageTracker._trackPageview('/Goal/RegisterYourDecisionDecideExpand');
   });
	
	
});