 jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
 
 var Abas, Menu, Login;
 
 Abas= {
	init: function(){
		this._setEventHandlers();
	},
	
	_setEventHandlers: function(){
		$('a.menuitem').click(function(event){
			var alvo = $(event.target)[0], targets = {
				'link-casos-clinicos' : '#casos-clinicos',
				'link-noticias' : '#noticias'
			};
			
			if( $(targets[alvo.id] + ":visible").length == 0) {
				$('div.simpleTabsContent').hide();
				
				$(targets[alvo.id]).show('slow');
			}
						
			return false;
		});
	}
 };
 
Menu = {
 	init: function(){
		this._setEventHandlers();
	},
	
	_setEventHandlers: function(){				
		$('ol#menu li a').mouseover( function(event){
			var id = $(event.target).attr('name');
			if($('img#menu'+id).length == 1){	
				$('#imagem img:visible').hide();
				$('img#menu'+id).show();
			}
		});
	}
 };
 
Login = {
 	init: function(p){
		this._setEventHandlers(p);
	},
	
	_setEventHandlers: function(p){
		var cookie_hash= p['hash'], cookie_path = p['path'];		
		$('#submit').click(function(){
			var username =$('#username').val(), 
			password = $('#password').val();
			if(! username.match(/^\s*$/)){
				$.cookie('wp-postpass_' + cookie_hash, password, { expires: 10 , path : cookie_path });
				window.location="http://www.vetphysical.com.br" + cookie_path + escape(username) + "#content";
			}
			return false;
		});
	}
};	

Banner = {
 	init: function(){
		this._setEventHandlers();
	},
	
	_setEventHandlers: function(){
		var auto= true, 
			last = -1, 
			qtd  = $('#banner-images a').length,
			trocar = function(id){
			if(id != last && $('#banner-images a:eq('+ id+')').length == 1){
				$('#banner-images a:visible').hide();
				$('#seletor li a').removeClass('hover');
				$('#banner-images a:eq('+ id+')').show();
				$('#seletor li a:eq('+ id+')').addClass('hover');
				
				last = id;
			}					
		};
		trocar(0);
		
		$('#seletor li a').mouseover(function(event){
			auto = false;  
			var id = 1*$(event.target).text() -1;					
			trocar(id);	
		});
		
		$('#seletor li a').mouseout(function(event){
			auto = true;					
		});
		
		setInterval(function(){
			if(!auto) return;
			trocar((1+last) % qtd);
		},8000);		
	}	
};

$(document).ready(function() {
	jQuery.each(Images, function(i,val){
		if(val != null && val.length> 0){
			var img = $('<img>').attr('src',val).attr('id','menu'+i).hide();		
			$('#imagem').append(img);
		}
	});

	$('#imagem img:first').show();

	Nifty("h2","big");
	Nifty("div#imagem","big");
	Nifty("ol#menu","big");	
});