/* fuzzimo.com scripts */

jQuery(document).ready(function(){
								
	//rssoptions
	jQuery("#menu ul li a.subscriberss").hover(function() {
		jQuery(this).parent().find("ul.rssoptions").fadeIn('fast').show();
		jQuery(this).parent().hover(function() {
		}, function(){
			jQuery(this).parent().find("ul.rssoptions").fadeOut('slow');
		});	
	});
	//end rssoptions
	
	//popular recent panels
	jQuery(".panelcontent").hide();
	jQuery(".panelcontent:first").show();	
	jQuery("ul.tabs li").click(function() {
		jQuery("ul.tabs li").removeClass("active"); 
		jQuery(this).addClass("active"); 
		jQuery(".panelcontent").hide(); 

		var activeTab = jQuery(this).find("a").attr("href"); 
		jQuery(activeTab).fadeIn();
		return false;
	});
	//end recent panels
	
	//smooth scroll
	jQuery(function() {
	
		function filterPath(string) {
			return string
			.replace(/^\//,'')
			.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
			.replace(/\/$/,'');
		}
	
		var locationPath = filterPath(location.pathname);
		var scrollElem = scrollableElement('html', 'body');
	
		// Any links with hash tags in them (can't do ^= because of fully qualified URL potential)
		jQuery('a[href*=#]').not('a[href*=#panel1], a[href*=#panel2], a[href*=#respond], a[href*=.infoboxtitle1], a[href*=.infoboxtitle2], a[href*=.infoboxtitle3]').each(function() {
	
			// Ensure it's a same-page link
			var thisPath = filterPath(this.pathname) || locationPath;
			if (  locationPath == thisPath
				&& (location.hostname == this.hostname || !this.hostname)
				&& this.hash.replace(/#/,'') ) {
	
					// Ensure target exists
					var jQuerytarget = jQuery(this.hash), target = this.hash;
					if (target) {
	
						// Find location of target
						var targetOffset = jQuerytarget.offset().top;
						jQuery(this).click(function(event) {
	
							// Prevent jump-down
							event.preventDefault();
	
							// Animate to target
							jQuery(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
	
								// Set hash in URL after animation successful
								location.hash = target;
	
							});
						});
					}
			}
	
		});
	
		// Use the first element that is "scrollable"  (cross-browser fix?)
		function scrollableElement(els) {
			for (var i = 0, argLength = arguments.length; i <argLength; i++) {
				var el = arguments[i],
				jQueryscrollElement = jQuery(el);
				if (jQueryscrollElement.scrollTop()> 0) {
					return el;
				} else {
					jQueryscrollElement.scrollTop(1);
					var isScrollable = jQueryscrollElement.scrollTop()> 0;
					jQueryscrollElement.scrollTop(0);
					if (isScrollable) {
						return el;
					}
				}
			}
			return [];
		}
	
	});
	//end smooth scroll
	
	//form check
	jQuery('form#commentform').submit(function() {
		jQuery('form#commentform .fielderror1').remove();
		var hasError = false;
		jQuery('form#commentform .fielderror2').remove();
		var hasError = false;
		jQuery('form#commentform .fielderror3').remove();
		var hasError = false;
		jQuery('.requiredField1').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				var labelText = jQuery(this).prev('label').text().replace(' *','');
				jQuery(this).parent().append('<span class="fielderror1">required</span>');
				hasError = true;
			}
		});
		
		jQuery('.requiredField2').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				var labelText = jQuery(this).prev('label').text().replace(' *','');
				jQuery(this).parent().append('<span class="fielderror2">required</span>');
				hasError = true;
			}
		});
		
		jQuery('.requiredField3').each(function() {
			if(jQuery.trim(jQuery(this).val()) == '') {
				var labelText = jQuery(this).prev('label').text().replace(' *','');
				jQuery(this).parent().append('<span class="fielderror3">required</span>');
				hasError = true;
			}
		});
		
		if(hasError) {
			return false;
		}
	});
	
	jQuery('form#commentform .requiredField1').hover(function() {
            jQuery('form#commentform .fielderror1').fadeOut('fast');
		
	});
	
	jQuery('form#commentform .requiredField2').hover(function() {
            jQuery('form#commentform .fielderror2').fadeOut('fast');
		
	});
	
	jQuery('form#commentform .requiredField3').hover(function() {
            jQuery('form#commentform .fielderror3').fadeOut('fast');
		
	});
	//end form check
	
	//infoboxes
	jQuery("div.infobox1, div.infobox2, div.infobox3").hide();		
		jQuery("a.infoboxtitle1").click(function(){
			jQuery("div.infobox1").slideToggle(600);
			
			return false;
		});	
		jQuery("a.infoboxtitle2").click(function(){
			jQuery("div.infobox2").slideToggle(600);
			
			return false;
		});	
		jQuery("a.infoboxtitle3").click(function(){
			jQuery("div.infobox3").slideToggle(600);
			
			return false;
		});		
	//end infoboxes
	
});


/* Script by: www.jtricks.com
 * Version: 20070301
 * Latest version:
 * www.jtricks.com/javascript/window/box_alone.html
 */
// Moves the box object to be directly beneath an object.
function move_box(an, box)
{
    var cleft = 6;
    var ctop = 6;
    var obj = an;

    while (obj.offsetParent)
    {
        cleft += obj.offsetLeft;
        ctop += obj.offsetTop;
        obj = obj.offsetParent;
    }

    box.style.left = cleft + 'px';

    ctop += an.offsetHeight - 117;

    // Handle Internet Explorer body margins,
    // which affect normal document, but not
    // absolute-positioned stuff.
    if (document.body.currentStyle &&
        document.body.currentStyle['marginTop'])
    {
        ctop += parseInt(
            document.body.currentStyle['marginTop']);
    }

    box.style.top = ctop + 'px';
}

// Hides other alone popup boxes that might be displayed
function hide_other_alone(obj)
{
    if (!document.getElementsByTagName)
        return;

    var all_divs = document.body.getElementsByTagName("DIV");

    for (i = 0; i < all_divs.length; i++)
    {
        if (all_divs.item(i).style.position != 'absolute' ||
            all_divs.item(i) == obj ||
            !all_divs.item(i).alonePopupBox)
        {
            continue;
        }

        all_divs.item(i).style.display = 'none';
    }
    return;
}

// Shows a box if it wasn't shown yet or is hidden
// or hides it if it is currently shown
function show_hide_box(an, width, height, borderStyle)
{
    var href = an.href;
    var boxdiv = document.getElementById(href);

    if (boxdiv != null)
    {
        if (boxdiv.style.display=='none')
        {
            hide_other_alone(boxdiv);
            // Show existing box, move it
            // if document changed layout
            move_box(an, boxdiv);
            boxdiv.style.display='block';

            // Workaround for Konqueror/Safari
            if (!boxdiv.contents.contentWindow)
                boxdiv.contents.src = href;
        }
        else
            // Hide currently shown box.
            boxdiv.style.display='none';
        return false;
    }

    hide_other_alone(null);

    // Create box object through DOM
    boxdiv = document.createElement('div');

    // Assign id equalling to the document it will show
    boxdiv.setAttribute('id', href);
	boxdiv.setAttribute((document.all ? 'className' : 'class'), "emailthisbox")
	//boxdiv.setAttribute("class", 'emailthisbox');

    // Add object identification variable
    boxdiv.alonePopupBox = 1;

    boxdiv.style.display = 'block';
    boxdiv.style.position = 'absolute';
    boxdiv.style.width = width + 'px';
    boxdiv.style.height = height + 'px';
    boxdiv.style.textAlign = 'right';
    boxdiv.style.background = 'url(http://www.fuzzimo.com/wp-content/themes/fuzzimo/images/emailthisbox.jpg)';
	boxdiv.style.backgroundRepeat = 'no-repeat'
    document.body.appendChild(boxdiv);

    var offset = 0;

    // Remove the following code if 'Close' hyperlink
    // is not needed.
    var close_href = document.createElement('a');
	close_href.setAttribute('id', 'closebox');
    close_href.href = 'javascript:void(0);';
    close_href.onclick = function()
        { show_hide_box(an, width, height, borderStyle); }
    close_href.appendChild(document.createTextNode('Close'));
    boxdiv.appendChild(close_href);
    offset = close_href.offsetHeight;	
	
    // End of 'Close' hyperlink code.

    var contents = document.createElement('iframe');
	contents.allowTransparency = 'true';
    contents.scrolling = 'no';
    contents.overflowX = 'hidden';
    contents.overflowY = 'scroll';
    contents.frameBorder = '0';
    contents.style.width = width + 'px';
    contents.style.height = (height - offset) + 'px';

    boxdiv.contents = contents;
    boxdiv.appendChild(contents);

    move_box(an, boxdiv);

    if (contents.contentWindow)
        contents.contentWindow.document.location.replace(
            href);
    else
        contents.src = href;

    // The script has successfully shown the box,
    // prevent hyperlink navigation.
    return false;
}
/*End Script by: www.jtricks.com*/
