<!--
// TKI BAR //
//
// TODO: * store the announcements in the user's cookie?
//			- server polled less
//			- only display if user has cookie? (if cookies disabled, no display)
//		 * create global bar object (a la pods)

var tkibar = {
		announce : {
					selectors : {
							wrapper:'.announcement',
							name:	'.announce'
						},
					domain: 'tki.org.nz',
					cookieName: 'tkibar'
		},
		session : {
			cookieName: 'eZSESSID',
			cookieDomain: 'tki.org.nz',
			cookieExpire: 1
		}
};

function hidedropdown(lists){
	jQuery.each(lists, function(index, item) { 
		switch(item){
			case 'register':
				if( jQuery("#bar-reg").hasClass('close') )
					jQuery("#bar-reg").click();
				break;
			case 'bookmark':
				if( jQuery("#bar-bookmark").hasClass('close') )
					jQuery("#bar-bookmark").click();
				break;
			case 'search':
				if( jQuery(".slideup-searchresult").hasClass('close') )
					jQuery(".slideup-searchresult").click();
				break;
		}
	});

}

jQuery(document).ready( function(jQuery){
		
	//Create slide fade effect
	jQuery.fn.slideFadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle', height: 'toggle'}, speed, easing, callback);
	};
	
	// close announcement
	jQuery(tkibar.announce.selectors.wrapper)
		.slideDown("slow")
		.find('.close').click(function (event){
			event.preventDefault();
			jQuery(this).parents(tkibar.announce.selectors.wrapper).slideFadeToggle("slow");
			var closedID = jQuery(this).parents(tkibar.announce.selectors.name).attr("id").replace('announce','');
			//alert("closedID:" + closedID);
			
			//get expiry date			
			var announceExpireDate = parseInt( jQuery(this).parent().prev().html() );
			//alert(announceExpireDate);
					
			//format variable to set in the cookie 
		    var announceCookie = jQuery.cookie(tkibar.announce.cookieName);
			if (announceCookie == null){
				announceCookie = [];
			} else {			
				announceCookie = jQuery.parseJSON(announceCookie);
				if (typeof announceCookie == 'number') announceCookie = [announceCookie];
			}
			announceCookie.push(closedID);
			
			//set cookie
			jQuery.cookie(tkibar.announce.cookieName,jQuery.toJSON(announceCookie),{
	            expires: announceExpireDate,
	            //domain: tkibar.announce.domain,
	            path: '/'
	        });
			return false;		
	});
	
	// hover functionality
	jQuery('#bar-bookmark,#bar-bookmark-home').hover(function() {
			jQuery(this).addClass('bookmarkover');
		}, function() {
			jQuery(this).removeClass('bookmarkover');
	});

	//OVERLAYS
	//Show arrows
	jQuery("#bar-reg,#bar-bookmark").addClass('switch open');
	//show overlays
	jQuery(".register-dropdown-general,.tkidrop-wrapper-bookmark").show();
	
	//set the height of the register overlay since this content can change
	var regOverlayHeight = jQuery(".register-dropdown-general").height();				
	regOverlayHeight = regOverlayHeight + 60;
	regOverlayHeight = '-' + regOverlayHeight + 'px';
	jQuery(".register-dropdown-general").css("marginTop", regOverlayHeight);
	
	var bookmarkOverlayHeight = jQuery(".tkidrop-wrapper-bookmark").height();				
	bookmarkOverlayHeight = bookmarkOverlayHeight + 60;
	bookmarkOverlayHeight = '-' + bookmarkOverlayHeight + 'px';
	jQuery(".tkidrop-wrapper-bookmark").css("marginTop", bookmarkOverlayHeight);
	
	//register overlay
	jQuery("#bar-reg").click(function(event){
		event.preventDefault();
		if( jQuery(this).hasClass('open') ){
			hidedropdown(['search']);
			jQuery(".register-dropdown-general").animate({
				marginTop: "0"			
			});
			jQuery(this).removeClass('open').addClass('close');
			return false;
		}else{
			jQuery(".register-dropdown-general").animate({
				marginTop: regOverlayHeight
			});
			jQuery(this).removeClass('close').addClass('open');
			return false;
		}
	});		
	jQuery(".slideup-reg").click(function(){
		jQuery(".register-dropdown-general").animate({
			marginTop: regOverlayHeight
		});
		jQuery("#bar-reg").removeClass('close').addClass('open');
		return false;
	});	

	// bookmark overlay
	jQuery("#bar-bookmark").click(function(event){
			event.preventDefault();
			if( jQuery(this).hasClass('open') ){
				hidedropdown(['search']);
				jQuery(".tkidrop-wrapper-bookmark").animate({
					marginTop: "0"			
				});
				jQuery(this).removeClass('open').addClass('close');
				return false;
			}else{
				jQuery(".tkidrop-wrapper-bookmark").animate({
					marginTop: bookmarkOverlayHeight
				});
				jQuery(this).removeClass('close').addClass('open');
				return false;
			}
	});
	jQuery(".slideup-bookmark").click(function(){
		jQuery(".tkidrop-wrapper-bookmark").animate({
			marginTop: bookmarkOverlayHeight
		});
		jQuery("#bar-bookmark").removeClass('close').addClass('open');
		return false;
	});	
	
	// Bookmark name
	jQuery(".tkidrop-wrapper-bookmark input[name='name']").val( document.title );
	
	
	// Bookmark hovers for IE6
	//jQuery(".open").hover(function(){
    //this.style.color = "#fff";
	//this.style.background = 'transparent url(../images/tki/tkibar-open-green.gif) no-repeat right 6px';
    // }, function() {
    //this.style.color = "#bfd4d7";
	//this.style.background = 'url(../images/tki/tkibar-open-hover.gif) no-repeat right 6px';
   // });
    // end of bookmark hovers for IE6
	
	//jQuery('.general-page-bookmarks-form .open').hover(function() {
        //jQuery(this).addClass('bar-bookmark-open-hover');
        //}, function() {
        //jQuery(this).removeClass('bar-bookmark-open-hover');
   // });

	
			
});
//-->
