// JavaScript Document

/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

$.fn.equals = function(compareTo) {
        if (!compareTo || !compareTo.length || this.length!=compareTo.length) 
{ 
                return false; 
        } 
        for (var i=0; i<this.length; i++) { 
                if (this[i]!==compareTo[i]) { 
                        return false; 
                } 
        } 
        return true; 



} 

$.fn.overlabel = function( options ) {
 
        // build main options before element iteration
        var opts = $.extend( {}, $.fn.overlabel.defaults, options );
 
        var selection = this.filter( 'label[for]' ).map( function() {
 
            var label = $( this );
            var id = label.attr( 'for' );
            var field = document.getElementById( id );
 
            if ( !field ) return;
 
            // build element specific options
            var o = $.meta ? $.extend( {}, opts, label.data() ) : opts;
 
            label.addClass( o.label_class );
 
            var hide_label = function() { label.css( o.hide_css ) };
            var show_label = function() { this.value || label.css( o.show_css ) };
 
            $( field )
                 .parent().addClass( o.wrapper_class ).end()
                 .focus( hide_label ).blur( show_label ).each( hide_label ).each( show_label );
 
            return this;
 
        } );
 
        return opts.filter ? selection : selection.end();
    };
 
    // publicly accessible defaults
    $.fn.overlabel.defaults = {
 
        label_class:   'overlabel-apply',
        wrapper_class: 'overlabel-wrapper',
        hide_css:      { 'text-indent': '-10000px' },
        show_css:      { 'text-indent': '0px', 'cursor': 'text' },
        filter:        false
 
    };


function slideSwitch() {
    var $active = $('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow DIV:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    if ( !$active.equals($next)) {
    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
        }
}

$(document).ready(function() {
		var availableTags = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl"];
		    var dates_allowed = {
		  '2011-03-15': "apple",
          '2011-04-01': "banana",
          '2011-04-25': "orange",
          '2011-04-28': "Birthday"
    };

		$("#tags").autocomplete({
                  minLength: 3,
			source: "search/autocomplete.php"
		});
		   $("label.overlabel").overlabel();
//    $('#Content').jScrollPane();
				// Tabs
				$('#tabs').tabs();
	
    $('ul#lavamenu').lavaLamp(	{
	fx: 'easeInExpo',
	speed: 1000,
	returnHome:true,
	homeLeft: 300,
	homeTop: -200,
	homeWidth:0,
	homeHeight:0
	}); 

 

 // set up the options to be used for jqDock...
//  var dockOptions =
//   { align: 'center' // vertical menu, with expansion LEFT/RIGHT from the center
//  , size: 152 // size
//    , labels: 'tc'  // add labels (override the 'tc' default)
//    , inactivity: 4000 // set inactivity timeout to 4 seconds
//    };
  // ...and apply...
//  $('#menu').jqDock(dockOptions);
    jQuery(".megamenu").megamenu();
 

    // this could be a static hash, generated by the server, or loaded via ajax
    // if via ajax, make sure to put the remaining code in a callback instead.

    $('#datepicker').datepicker({
        // these aren't necessary, but if you happen to know them, why not
        //minDate: new Date(2011, 12-1, 1),
        //maxDate: new Date(2011, 9-1, 28),

        // called for every date before it is displayed
        beforeShowDay: function(date) {
     var month = (date.getMonth() + 1).toString();
    var dom = date.getDate().toString();
    if (month.length == 1) month = "0" + month;
    if (dom.length == 1) dom = "0" + dom;
    var date_str = date.getFullYear() + "-" + month + "-" + dom;


            if (dates_allowed[date_str]!=undefined) {
                return [true, 'good_date', dates_allowed[date_str]];
            } else {
                return [false, 'bad_date', 'This date is NOT selectable'];
            }
        }
    });


	jQuery("ul#ticker").liScroll({travelocity: 0.03});

   jQuery('#mycarousel').jcarousel({
       scroll: 1,
       animation: 'slow',
   	wrap: 'circular'
   });
      $(".tweet").tweet({
        join_text: "auto",
        username: "cheezwhse",
        avatar_size: 20,
        count: 3,
        auto_join_text_default: "cheezwhse said:",
        auto_join_text_ed: "cheezwhse",
        auto_join_text_ing: "cheezwhse were",
        auto_join_text_reply: "cheezwhse replied",
        auto_join_text_url: "cheezwhse were checking out",
        loading_text: "loading tweets..."
      });


    var options = { 
        target:        '#output1',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success:       showResponse  // post-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 
 
    // bind form using 'ajaxForm' 
    $('#myForm1').ajaxForm(options); 

// invoke the check all checkbox
$('.checkall').click(function () {
     $(this).closest('fieldset').find(':checkbox').attr('checked', this.checked);
});



// choose text for the show/hide link - can contain HTML (e.g. an image)
var showText='http://nbeacon.com/cheezwhse/images/left_arrow.png';
var hideText='http://nbeacon.com/cheezwhse/images/down_arrow.png';

// append show/hide links to the element directly preceding the element with a class of "toggle"
$('.toggle').prev().append('<a href="#" class="toggleLink"><img src="'+showText+'"></a>');

// hide all of the elements with a class of 'toggle'
$('.toggle').hide();

// capture clicks on the toggle links
$('a.toggleLink>img').click(function() {

// change the link depending on whether the element is shown or hidden
var src = ($(this).attr("src") === hideText) ? showText : hideText;
$(this).attr("src",src);

// toggle the display - uncomment the next line for a basic "accordion" style
//$('.toggle').hide();$('a.toggleLink').html(showText);
$(this).parent().parent().next('.toggle').toggle();

// return false so any link destination is not followed
return false;
});

// pre-submit callback 
function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString =  $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
    // for normal html responses, the first argument to the success callback 
    // is the XMLHttpRequest object's responseText property 

    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
 
    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.'); 
}
   initialize();

});

