jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		shim: 'x.gif',
		apply_positioning: true
	}, settings);

	return this.each(function(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
					self.css('position', 'relative');
				};
			});
		};
	});
};

$(document).ready(function() {
	
	//hide child page
	$('#nav li.page_item ul').hide();
	//when navigate to a child page show all pages
	$('#nav li.current_page_item').parent("ul").show();
	//show page list when toggle
	$('#nav li.active ul').show();
	//show cerrent page's child page
	$('#nav li.current_page_item ul').show();

	$('#nav .page-item-13 a:not(ul ul li a), #nav .page-item-7 a:not(ul ul li a)').click(function() { 

		//$(this).addClass("active");
		$(this).next('ul').slideToggle("slow"); 

		return false;
	});


	
	
	
	if (bgsrc == "") {
		$('#bgimg').attr("src",'/wp-content/themes/fallenfruit/images/bg.jpg');
		
	} else {
		$('#bgimg').attr("src",bgsrc);
	}
	
	$('body').supersleight({shim: '/wp-content/themes/fallenfruit/images/spacer.gif'});
	
	 //find all accordions
	 $(".accordion .header").click( function() {
		if ($(this).next().hasClass('showing')) {
			$(this).next().slideUp(500).removeClass('showing')
		} else{
		$('.showing').slideUp(500).removeClass('showing');
		$(this).next().slideDown(500).addClass('showing');
									}
		return false;
	});
	
	$(".tweet").tweet({
	            username: "fallenfruit",
	            count: 10,
	            auto_join_text_default: null,
	            auto_join_text_ed: null,
	            auto_join_text_ing: null,
	            auto_join_text_reply: null,
	            auto_join_text_url: null,
	            loading_text: "loading tweets..."
	        });
	
	
	function windowwidth() {
						var windowwidth = "";
						if ($(window).width() < 2400) { return $(window).width(); } else { return 2400; }
					}

					$('#bgimg').width(windowwidth());

					$(window).resize(function(){
						$('#bgimg').width(windowwidth());
					});

	

	
	
});


