jQuery.noConflict();
jQuery(document).ready(function() {

// Add pngfiximg class to required items (IE6)
jQuery('#wide-header img').addClass('pngfix');
jQuery('#wide-intro img').addClass('pngfix');
jQuery('#wide-primary img').addClass('pngfix');
jQuery('#wide-secondary img').addClass('pngfix');
jQuery('#wide-footer img').addClass('pngfix');
jQuery('.mic ul li').addClass('pngfix');
jQuery('.fbuttons li a').addClass('pngfix');
jQuery('.fbuttons li a span').addClass('pngfix');
jQuery('.thumb').addClass('pngfix');
jQuery('.maincarousel a').addClass('pngfix');
jQuery('.maincarousel img').addClass('pngfix');
jQuery('div.posttags').addClass('pngfix');

// min/max list items
jQuery(".sidebar ul ul").css({display: "none"}); // Opera Fix
jQuery('.sidebar li').each(function(){
	if (jQuery(this).children('ul').length > 0) {
	jQuery(this).children('ul').hide();
	jQuery(this).css("background","none");
	jQuery(this).prepend('<a href="#" class="listcontrol"></a>');
	jQuery(this).children('.listcontrol').click(function() {
		jQuery(this).parent().children('ul').slideToggle(500);
	});
	}
});

jQuery('.listcontrol').toggle(
	function() {
	jQuery(this).css({'background-position' : 'bottom'});
	},
	function() {
	jQuery(this).css({'background-position' : 'top'});
	}
);

// ajaxing comment listing
jQuery('.thread-even').each(function(){
if (jQuery(this).children().length > 1) {
	jQuery(this).children('div:first').before('<div class="subcomments"><a href="#subcomments">' + collapseText + '</a></div>');
	jQuery(this).children('div.subcomments').children('a').click(function() {
	jQuery(this).parent().parent().children('.children').slideToggle(500);
	jQuery(this).text(jQuery(this).text() == collapseText ? expandText : collapseText);
	});
}
});

jQuery('.thread-odd').each(function(){
if (jQuery(this).children().length > 1) {
	jQuery(this).children('div:first').before('<div class="subcomments"><a href="#subcomments">' + collapseText + '</a></div>');
	jQuery(this).children('div.subcomments').children('a').click(function() {
	jQuery(this).parent().parent().children('.children').slideToggle(500);
	jQuery(this).text(jQuery(this).text() == collapseText ? expandText : collapseText);
	});
}
});

// dropdown menu (unlimited sub-levels)
jQuery("#menu ul").css({display: "none"}); // Opera Fix
jQuery("#menu li").hover(function(){
if (jQuery(this).parent().attr("id") == 'menu') {
jQuery(this).removeClass('menu-top');
jQuery(this).addClass('menu-bottom');
}
jQuery(this).find('ul:first').css({visibility: "visible",display: "none"}).fadeIn(500);
},function(){
if (jQuery(this).parent().attr("id") == 'menu') {
jQuery(this).addClass('menu-top');
jQuery(this).removeClass('menu-bottom');
}
jQuery(this).find('ul:first').css({visibility: "hidden"});
});

// tabs generator script
function newTabs(contentdiv, tablist) {

jQuery(contentdiv).css({display: "none"}); // Opera Fix
jQuery(contentdiv + ':first').fadeIn(500);
jQuery(tablist + ' li:first').addClass('active');
jQuery(tablist + ' li a').click(function(){
	if (jQuery(this).parent().hasClass('active')) {
	} else {
	var currentTab = jQuery(this).attr('href');
	jQuery(tablist + ' li').removeClass('active');
	jQuery(this).parent().addClass('active');
	jQuery(contentdiv).hide();
	jQuery(currentTab).fadeIn(500);
	return false;
	}
});

}
newTabs('.main-intro', '.hometabs');
newTabs('.content', '.tabs');
newTabs('.newscontent', '.newtabs');

// switch next & prev buttons
jQuery('.fbuttons li a').click(function() {

if (jQuery(this).attr('href') == '#next') {
	var nextDIVlabel = '#' + jQuery('#' + jQuery(this).closest('div.main-intro').attr('id')).next('div').attr('id');
	jQuery('.hometabs li').removeClass('active');
	jQuery('li > a[href$=' + nextDIVlabel + ']').parent().addClass('active');
	jQuery('.main-intro').hide();
	jQuery(nextDIVlabel).fadeIn(500);
}

if (jQuery(this).attr('href') == '#prev') {
	var prevDIVlabel = '#' + jQuery('#' + jQuery(this).closest('div.main-intro').attr('id')).prev('div').attr('id');
	jQuery('.hometabs li').removeClass('active');
	jQuery('li > a[href$=' + prevDIVlabel + ']').parent().addClass('active');
	jQuery('.main-intro').hide();
	jQuery(prevDIVlabel).fadeIn(500);
}

});

// custom carousel
function newCarousel(divclass, nextclass, prevclass) {

	jQuery(divclass).css({display: "none"}); // Opera Fix
	jQuery(divclass + ':first').fadeIn(500);
	jQuery(nextclass + ',' + prevclass).click( function (ev) {
	ev.preventDefault();
	var $visibleItem = jQuery(divclass + ':visible');
	var total =  jQuery(divclass).length;
	var index = $visibleItem.prevAll().length;
	jQuery(this).attr('href') === '#next' ? index++ : index--;
	if (index === -1){
	index = total-1;
	}
	if (index === total){
	index = 0;
	}
	$visibleItem.hide();
	jQuery(divclass + ':eq(' + index + ')').fadeIn(500);
	});
	
}
newCarousel('.showarea', 'a.rightarrow', 'a.leftarrow');
newCarousel('.review', 'a.nextreview', 'a.prevreview');

// Clearing field inputs
function clearInput (cssClass) {
	// Get the input field and assign it to a variable
	var focusField = jQuery(cssClass);
	
	focusField.focus( function(){
		// Assign jQuery(this) to a variable, allowing DOM to do less lookup
		var el = jQuery(this);
		var val = el.val();
		
		// Using jQuery data object, check to see if value has been 
		// assigned to placeholder data object and if not it should be assigned a value.
		if (!el.data('placeholder')) {
			el.data('placeholder', val);
		}
		
		if(val === el.data('placeholder')) {
			el.val('');
		}
	});
	
	// Execute when user leaves the input field
	focusField.blur( function () {
		// Assign jQuery(this) to a variable, allowing DOM to do less lookup
		var el = jQuery(this);
		if (el.val() === '') {
			el.val(el.data('placeholder') || '');
		}
	});
}
clearInput('.email');

// Equal heights with jQuery
// make sure the $ is pointing to JQuery and not some other library
(function($){
    // add a new method to JQuery

    $.fn.equalHeight = function() {
       // find the tallest height in the collection
       // that was passed in (.column)
        tallest = 0;
        this.each(function(){
            thisHeight = $(this).height();
            if( thisHeight > tallest)
                tallest = thisHeight;
        });

        // set each items height to use the tallest value found
        this.each(function(){
            $(this).height(tallest);
        });
    }
})(jQuery);
jQuery('.equal').equalHeight();

// Gallery zoom-in page processing
jQuery("a.group").fancybox({
	'zoomSpeedIn': 300,
	'zoomSpeedOut': 300
});

});
