jQuery.noConflict();

Cufon.replace('#navigation a, #action-box dt a, #action-box dd, #content h1, #home h2, #sidebar-wrap h2, #splash-content h2, #splash-content h3, #splash-content p, #volunteer #pledge h2, #volunteer h3, #volunteer h4, #team-nfl-blog h3 a', {hover: true}, {fontFamily: 'Meta'});


function form_input_classes(){

    jQuery('input[type="text"]').addClass('text');
    jQuery('input[type="email"]').addClass('text');
    jQuery('input[type="tel"]').addClass('text');
    jQuery('input[type="password"]').addClass('text');
    jQuery('input[type="checkbox"]').addClass('checkbox');
    jQuery('input[type="radio"]').addClass('radiobutton');
    jQuery('input[type="submit"]').addClass('submit');
    jQuery('input[type="image"]').addClass('buttonImage');

}

function superfish(){
    jQuery('ul.sf-menu').superfish({ 
        delay:       500,                            // delay on mouseout 
        dropShadows: false                            // disable drop shadows 
    });
}

function cycle_lite(){
    jQuery('#rotator').cycle({ 
      timeout: 10000,
      pager: '#pager-nums'
});
}

function assign_fitted(){jQuery('.clickable').fitted();}

function form_labelize(){  jQuery(".labelize input:text").clearingInput(); }   

function lightbox (){ // this function does not run in (document).ready
    var modal = jQuery.cookie('mw');
    //get the page url
    var locationHref = document.location.href;
    var bsdFrameworkUrlStructure = /\/page\//;
 
    //conditional for the modal window
    if(modal != 'visited') {

        jQuery.cookie('mw', 'visited', { expires: 30, path: '/', domain: 'liveunited.org' });
        // jQuery("#lightbox").show();
        
        //jQuery.fn.colorbox({iframe: true, href:"http://liveunited.org/content/lightbox-dev", open:true, transition:"none", opacity: .75, height: 455, width: 1025}); 
        if(jQuery.support.changeBubbles){

                    //not ie
                    jQuery.fn.colorbox({
                        href: "http://liveunited.org/content/lightbox",
                        width: '1025px',
                        height: '455px',
                        iframe: true            
                    });

                } else {

                    //ie
                    jQuery.fn.colorbox({
                        href: "http://liveunited.org/content/lightbox",
                        width: '1055px',
                        height: '495px',
                        iframe: true            
                    });

                }
        
        jQuery("#skip-lb").click(function () { 
            jQuery.fn.colorbox.close(); return false;
        });
        // jQuery().bind('cbox_cleanup', function(){
        //             jQuery("#lightbox").hide();
        //         });
    }
}

function validation() {
	jQuery("#uww-local").validate();
	jQuery("#cse-search-box").validate();
	jQuery("#vol-pledge").validate();
	jQuery("#vol-side-share-form").validate();
        jQuery("#splash-form").validate();
        jQuery("#team-nfl-pledge").validate();
        jQuery("#zip-search").validate({
          rules: {
              zip: {
                    required: true,
                    digits: true
                   }
                 }
       });
}

// test for spud zip, then populate all for good gadget with zip if found
function spCallback(spud) {    
    var zipAppend = "";
    if (spud.zip) {
       zipAppend = '&up_prefLocation=' + spud.zip;
    }
    
   
    var iframe = '<iframe width="560" scrolling="no" height="300" frameborder="no" scrolling="no" src="http://www.gmodules.com/gadgets/ifr?synd=open&url=http://www.allforgood.org/gadget/gadget-liveunited.xml&view=home&up_category=education' + zipAppend + '"></iframe>';
    var fbiframe = '<iframe width="410" scrolling="no" height="264" frameborder="no" scrolling="no" src="http://www.gmodules.com/gadgets/ifr?synd=open&url=http://www.allforgood.org/gadget/gadget-liveunited.xml&view=home&up_category=education' + zipAppend + '"></iframe>';
    
//    console.log('zipAppend: ' + zipAppend);
    jQuery('#allforgood-widget').append(iframe); 
    jQuery('#allforgood-fbwidget').append(fbiframe); 
    jQuery('#allforgood-team-nfl-widget').append(fbiframe); 


}

function vol_side_tabs(){jQuery('#vol-side-tabs').tabs();}

jQuery(document).ready(function() {
    form_labelize();
    form_input_classes();
    assign_fitted();
    superfish();
    cycle_lite();
    validation();
    jQuery('.contribheader').first().parent('tr').after('<tr><td id="req-note">All fields are required.</td></tr>');
    if(jQuery('#vol-side-tabs').length > 0) {vol_side_tabs();}

    if(jQuery('#allforgood-widget').length > 0) { 
        var script = document.createElement("script");
        var jsonpurl = '//give.liveunited.org/page/spud?jsonp=spCallback&type=get&field=zip'
 
        script.src = jsonpurl; 
        script.type = "text/javascript"
 
        document.body.appendChild(script);
    }
});

/*
 * Url preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){screenshotPreview();});