/*
	jQuery Friendly Common File
	---------------------------
*/

// Deactive Dummy "#" Links
var linkBreaker = function() { $('a[href=#]').click( function(){ return false; } ); }
//	$(document).ready(linkBreaker);


// Set Outbound Links by Class Name
var outLinks = function() { $('a.out').click( function(){ this.target = '_blank'; } ); }
$(document).ready(outLinks);


// Pop-up Windows by Size
var popWindows = function() { $('a.popup').popwindow(); }
jQuery.fn.popwindow = function() {
	return this.each(
		function(){
			var dimensions = this.className.match(/[0-9]{1,4}x[0-9]{1,4}/) + '';
			var width = eval(dimensions.split('x')[0]), height = eval(dimensions.split('x')[1]);
			$(this).bind('click',function() { window.open("" + this.href + "",null,'width=' + width + ', height=' + height); return false; })
		}
	)
}
$(document).ready(popWindows);


// Add jQ Lightbox on load
/*$(document).ready(function() {
	$('a[@href$=".jpg"]').lightBox();
});*/

// Post Links
$(document).ready(function(){
  $("div.post-content").mouseover(
    function() { 
      $(this).addClass("spotlinks").addClass("mouseIsOver");
    }
  ).mouseout(
    function() { 
      $(this).removeClass("spotlinks").removeClass("mouseIsOver");
    }
  );
});


// Correct PNG Images for IE 6
//var pngFix = {
//	init : function() {
//		var imgs = $("img[@src*=png]");
//		imgs.each(
//			function() {
//				var newSrc = $(this).attr('src'), newID = $(this).attr('id'), newClass = $(this).attr('class'), newTitle = $(this).attr('alt'), newStyle = $(this).attr('style'), newAlign = $(this).attr('align'), newW = $(this).attr('width'), newH = $(this).attr('height'), dfilter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,src='"+ newSrc +"',sizingMethod=image)";
//				
//				var span = document.createElement('span');
//				$(span).attr({ 'id':newID, 'class':newClass, 'title':newTitle, 'style':newStyle });
//				$(span).css({'display':'inline-block', 'background':'none', width:newW+'px', height:newH+'px', filter:dfilter});
//				if( newAlign ) $(span).css({'float':newAlign});
//				if( $(this).parent('a') ) $(span).css({'cursor':'hand'});
//				$(this).after(span).remove();
//			}
//		)
//	}
//}
//if( $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent) )
//	$(document).ready(pngFix.init);


// Image Rollovers
var rollovers = function(){ $('img.rollover').rollover(); }
jQuery.fn.rollover = function() {
	return this.each(
		function() {
			var srcString = this.src;
			var ext = srcString.substring(srcString.length - 4, srcString.length), name = srcString.substring(0, srcString.length - 4), overImage = name + '_over' + ext;
			var img = new Image();	img.src = overImage;
			$(this).bind('mouseover',function(){ this.src = overImage; } );
			$(this).bind('mouseout',function(){ this.src = srcString; } );
		}
	)
}
$(document).ready(rollovers);

	
// IE Image Rollovers
var IEroll = {
	init : function() {
		$("span.rollover").hover( IEroll.over, IEroll.out );
	},
	over : function() {
		var geturl = new RegExp(/src='([^ ]+)'/i);
		var filter = this.style.filter, src = geturl.exec(filter)[1];
		var ext = src.substring(src.length - 4, src.length), name = src.substring(0, src.length - 4), newSrc = name +'_over'+ ext;
		var image = new Image();
		image.src = newSrc;
		var dfilter = "progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + newSrc + "\', sizingMethod='image')";
		$(this).css({filter:dfilter});
	},
	out : function() {
		var geturl = new RegExp(/src='([^ ]+)'/i);
		var filter = this.style.filter, src = geturl.exec(filter)[1];
		var ext = src.substring(src.length - 4, src.length), name = src.substring(0, src.length - 9), newSrc = name + ext;
		var dfilter = "progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + newSrc + "\', sizingMethod='image')";
		$(this).css({filter:dfilter});

	}
}
if( $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent) )
	$(document).ready(IEroll.init);


// HREF Link
function goTo( url ) {
	location.href = url;
}

// Smooth Scroll Back to Top
var scrollToTop = function(){ $('a[href=#top]').click(function(){ backToTop(); return false;} ) };
function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;

    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}
$(document).ready(scrollToTop);

/*	| Tabbed Boxes
	---------------------------------	*/
var tabby = {
	init : function() {

		tabby.tabbed = $('.tabbed');
		tabby.tabbed.each( function() {
			$(this).find('.tabs a').click(tabby.toggle);
			$(this).find('.tabs a:first').click();
		});
	},

	toggle : function() {

		// Define Parents + Variables
		var tab_container = $(this).parents('.tabs'), container = $(this).parents('.tabbed'), tab = this, rel = $(this).attr('rel');
		var tabs = tab_container.find('a'), boxes = container.find('.box');

		// Find Tabs
		$(tab).addClass('active');
		tabs.each( function() { 
			if( this != tab )
				$(this).removeClass('active');
		} );

		// Toggle Boxes
		boxes.each( function() { 
			if( this.id == rel ) {
				$(this).show();
			} else {
				if( $(this).is(':visible') )
					$(this).hide();
			}
		} );

		return false;
	}
}
$(document).ready(tabby.init);


$(function() {

	$(".scroll-badges").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
		mouseWheel: true,
		beforeStart: function(a) {
			$( '.'+prev_badge_id ).removeClass('active-badge');
			
		},
		
		afterEnd: function(a) {
			var badge = { active: a[1] }
			active_badge_id = badge.active.className.substring(6);
			$( '#fv-'+active_badge_id).show();
			$( '#fv-'+prev_badge_id).hide();			
			$( '.'+active_badge_id ).addClass('active-badge');	
			prev_badge_id = active_badge_id;	
		}
		
    });
});



