// JavaScript Document

function show_popup( save_fn, height, title ) {
		
		$("#dialog").dialog({
			bgiframe: true,
			width: 580,
			height: height,
			title : title,
			modal: true,
			buttons: {
				'Save': function() {
					if( save_fn != 'null' ) $('#'+save_fn).submit();
				},
				Cancel: function() {
					$('#dialog').html("");
					$(this).dialog('close');
				}
			},
			close: function() {
				$('#dialog').html("");
			}
		});
}


	$.fn.extend({
		Flipper: function(settings) {
			var obj = this;
			var intervalId = false;
			// default config 
			var defaults = jQuery.extend({
				autostart : true,
				timeDelay: 5000,
				fadeType: 'swing',
				itemClass : 'highlight'
			},settings);

			var options = $.extend(defaults, options);
			
			this.flipBack = function() {
				var current = obj.find("."+options.itemClass+":visible");
				var next = current.prev("."+options.itemClass);
				if ( next.length == 0 ) next = obj.find("."+options.itemClass+":last");
				current.find(".text")
					.animate({right:'-450px'}).
					parent().fadeOut();
				next.
					fadeIn().
					find(".text").animate({right:'0px'});
			}
			this.flipAhead = function() {
				var current = obj.find("."+options.itemClass+":visible");
				var next = current.next("."+options.itemClass);
				if ( next.length == 0 ) next = obj.find("."+options.itemClass+":first");
				current.find(".text")
					.animate({right:'-450px'}).
					parent().fadeOut();
				next.
					fadeIn().
					find(".text").animate({right:'0px'});
			}
			/// INIT FUNCTION
			return this.each(function () {
				obj.find( "."+options.itemClass ).each( function() { $(this).hide(); });
				obj.find( "."+options.itemClass+":first" ).show().find(".text").animate({right:'0px'},'slow');;
				obj.find( "#marqueePrev" ).bind('click',function(){ 
					clearInterval(obj.intervalId);
					obj.flipBack(); 
				});
				obj.find( "#marqueeNext" ).bind('click',function(){ 
					clearInterval(obj.intervalId);
					obj.flipAhead(); 
				});
				if ( options.autostart ) obj.intervalId = setInterval( function() { obj.flipAhead(); }, options.timeDelay );
			});
		}
	} );

	function validateBlogComment() {
		var ret = true;
		if ( $("#commentEmail").val() == '' ) {
			ret = false;
			$("#commentEmail").css('background-color','#fea2a2');
		} else {
			$("#commentEmail").css('background-color','#fff');
		}
		if ( $("#commentBody").val() == '' ) {
			ret = false;
			$("#commentBody").css('background-color','#fea2a2');
		} else {
			$("#commentBody").css('background-color','#fff');
		}
		if ( ret ) $('#blogCommentForm').submit();	
	}
	function submitVote() {
		var poll = $("#pollId").val();
		var vote = $("#pollContainer input:checked").val();
		var content = "<div style='text-align:center;padding:65px 0px;'><img src='/layout/ajax-loader2.gif' width='' /></div>";
		$("#pollContainer").html( content );
		$.ajax({
			url : '/ajax.php',
			type : 'post',
			data : 'action=submitVote&vote='+vote+'&poll='+poll,
			success : function( msg ) {
				$("#pollContainer").html( msg );
			}
		});
	}
	function viewPollResults() {
		var poll = $("#pollId").val();
		var content = "<div style='text-align:center;padding:65px 0px;'><img src='/layout/ajax-loader2.gif' width='' /></div>";
		$("#pollContainer").html( content );
		$.ajax({
			url : '/ajax.php',
			type : 'post',
			data : 'action=viewResults&poll='+poll,
			success : function( msg ) {
				$("#pollContainer").html( msg );
			}
		});
	}
///////////////////////////////
// ONLONAD FUNCTIONS
///////////////////////////////
	$(function() { 
			   
		$('#username_field').bind('change', function() { 
			$('#checkBtn').removeClass('ui-icon-check');
			$('#checkBtn').removeClass('ui-icon-notice');
			$('#checkBtn').addClass('ui-icon-help');
		} );
		$("button").each(function(){ $(this).button(); })
					.click(function() { return false; });
		
		$(".mybutton").live('mouseenter', function() { $(this).addClass('ui-state-hover'); } );
		$(".mybutton").live('mouseleave', function() { $(this).removeClass('ui-state-hover'); } );
		$(".mybutton").live('mousedown', function() { $(this).addClass('ui-state-active'); } );
		$(".mybutton").live('mouseup', function() { $(this).removeClass('ui-state-active'); } );
		
		$('img.rollover').live('mouseover',function(){ $(this).attr('src', $(this).attr('src').replace( ".", "_on." ) )});
		$('img.rollover').live('mouseout',function(){ $(this).attr('src', $(this).attr('src').replace( "_on.", "." ) )});
			
		$('span.rollover').live('mouseover',function(){ $(this).css('background-image', $(this).css('background-image').replace( ".png", "_on.png" ) ); $(this).css('color','#ffffff'); });
		$('span.rollover').live('mouseout',function(){ $(this).css('background-image', $(this).css('background-image').replace( "_on.png", ".png" ) ); $(this).css('color','#000000'); });
		
		$("#loginform input").keypress(function (e) {  
			if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {  
				$('#loginform').submit();
				return false;  
			} else {  
				return true;  
			}  
		});  
		// GET WEATHER 
		$.ajax( {
			  url : '/ajax.php' ,
			  type : 'post',
			  data : 'action=getWeather',
			  success: function( msg ) { $('#header_weather').html( msg ); }
	   } );
		
		$('.datepicker').datepicker({dateFormat:'yy-mm-dd'});
		
		$('.jqueryTabs').tabs();
		
		if ( $("#marqueeContainer div.highlight").length > 1 ) {
			$("#marqueeContainer").Flipper();
		} else if ( $("#marqueeContainer div.highlight").length == 1 ) {
			$("#marqueeContainer").Flipper({autostart:false});
		}
		//$('a[rel*=lightbox]').lightBox({maxHeight: 300,maxWidth: 500});

	} );
