jQuery.noConflict();

jQuery(document).ready(function($) {		



$().ready( function () {

	$(function(){  
			$('#survey').dialog({
				bgiframe: true,
				autoOpen: false,
				modal: true,
				width: 358,
				height: 350,
				resizable: false,
				buttons: {
					Close: function(){
						$(this).dialog('close');
						}
					}
			});
		});
		
	$(function(){  
			$('#survey_thanks').dialog({
				bgiframe: true,
				autoOpen: false,
				modal: true,
				width: 358,
				height: 275,
				resizable: false,
				buttons: {
					Close: function(){
						$(this).dialog('close');
						}
					}
			});
		});

	$('.surveyCookieDelete').click(function() {		
		deleteCookie('POPsurvey');
		alert('Survey cookie cleared. Hit Refresh to see the survey again.');
	});
	
	$('p#surveyDenied a').click(function() {
		setCookie('POPsurvey','POPsurvey',30);
		//ajax to count denials??
		$('#survey').dialog('close');
	});
	
	$('#thanksClose').click(function() {
		$('#survey_thanks').dialog('close');
	});
	
	checkCookie('POPsurvey');	

});

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
} 
function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{
		c_start=c_start + c_name.length+1;
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		}
	  }
	return "";
}

function checkCookie(c_name)
{
	cookie_value=getCookie(c_name);
	if (cookie_value=="") {
		$('#survey').dialog('open');
	}
	  
}

function deleteCookie(c_name) {
	document.cookie = c_name +'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}





$(document).ready(function() {
	//On Hover Over
function megaHoverOver(){
    $(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        $(this).find(".sub").css({'width' :biggestRow}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub").css({'width' : rowWidth}); //Set Width

    }
}
//On Hover Out
function megaHoverOut(){
  $(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}

//Set custom configurations
var config = {
     sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
     interval: 0, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 0, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

$("ul#nav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
$("ul#nav li").hoverIntent(config); //Trigger Hover intent with custom configurations
});

































			$('#images').cycle({
        		fx:     'fade',
        		random:  1
      		});
      		
      		$('#images2').cycle({
        		fx:     'fade',
        		random:  1
      		});
			
			Cufon.replace('#main h2');
			
			$('INPUT.auto-hint').each(function(i, el){
			
			if($(this).val() == ''){
				$(this).val($(this).attr('title'));
			}
			
			$(el).focus(function(){
				if ($(this).val() == $(this).attr('title')) {
					$(this).val('');
				}       
			});
			
			$(el).blur(function(){
				if ($(this).val() == '') {
					$(this).val($(this).attr('title'));
					}
				});
			});
			
			
			
			$('#basicBoard').flightboard( {
			
				messages: ['3,412,382.82', '3,412,382.82'], 
				imagePath: '_images/',
				lettersImage: 'themes/bagitup/_images/flightBoardLarge.png',
				lettersSeq: '0123456789,.',
				maxLength: 12,
				lettersSize: [38,43]
			});
			
		});

jQuery(document).ready(function($) {
			jQuery('#partners-footer').jcarousel({
    		wrap: 'circular',
			scroll: 1,
			auto: 4
    		});
		});

jQuery(document).ready(function($) {

$('#twitter_update_list').tweet({
        username: "bag_it_up",
        join_text: "auto",
        avatar_size: null,
        count: 1,
        auto_join_text_default: "", 
        auto_join_text_ed: "",
        auto_join_text_ing: "",
        auto_join_text_reply: "",
        auto_join_text_url: "",
        loading_text: "loading tweet"
    });
		});
		
		
jQuery(document).ready(function($){
	// add a "rel" attrib if Opera 7+
	if(window.opera) {
		if ($("a.jqbookmark").attr("rel") != ""){
			$("a.jqbookmark").attr("rel","sidebar");
		} 
	}

	$("a.jqbookmark").click(function(event){
		event.preventDefault();
		var url = this.href;
		var title = this.title;
		
		if (window.sidebar) { // Mozilla Firefox Bookmark
			window.sidebar.addPanel(title, url,"");
		} else if( window.external ) { // IE Favorite
			window.external.AddFavorite( url, title);
		} else if(window.opera) { // Opera 7+
			return false; // do nothing
		} else { 
			 alert('Unfortunately, this browser does not support the requested action,'
			 + ' please bookmark this page manually.');
		}
	
	});
});

jQuery(document).ready(function($){

	$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=76708346@N08&format=json&jsoncallback=?", function(data) {
		var target = "#flickr-div"; // Name of div surrounding images.
		for (i = 0; i <= 8; i = i + 1) { // Loop through the 10 most recent, [0-9]
			var pic = data.items[i];
			var liNumber = i + 1; // Add class to each LI (1-10)
			$(target).append("<a title='" + pic.title + "' href='" + pic.link + "'><img width='90' height='90' src='" + pic.media.m + "' /></a>");
		}
	});
	
	$("#subFormCommunity").validate(); 
});

jQuery(document).ready(function($){
	
	$('a#demo-mouse').qtip({
		content: 'Like us on Facebook',
		position: {
			my: 'top left',
			target: 'mouse',
			viewport: $(window), // Keep it on-screen at all times if possible
			adjust: {
				x: 10,  y: 10
			}
		},
		hide: {
			fixed: true // Helps to prevent the tooltip from hiding ocassionally when tracking!
		},
		style: 'ui-tooltip-shadow'
	});
});


