jQuery(document).ready(function($) {
	
	$("a.anchorLink").anchorAnimate();
	
	$('#slider').nivoSlider({
		pauseTime:5000,
		pauseOnHover:true,
		effect: 'random'
	});
	
	$("#panel img").lazyload({
		effect: "fadeIn"
	});
	
	if (jQuery('#contactTexts').length > 0) {
		jQuery('#topForm').hide();
		jQuery('#middleForm').hide();
		jQuery('#bottomForm').hide();
	}
	
	jQuery('.infiniteCarousel').each(function () {
		jQuery(this).css('visibility', 'hidden');
	});
	
	
	// CLIENTS, PARTNERS ...
	
	// Client Checkboxs
	
	jQuery('.clientTypeCheckbox').click(function () {
		jQuery('#clientTypesForm').submit();
	});
	
	$(".hide").css({
        "position": "relative",
        "top": 0,
        "left": 0,
        "display": "none"
    }); 
	
	 jQuery("#explore-nav li a").click(function() {
		 
        // Figure out current list via CSS class
        var curList = jQuery("#explore-nav li a.current").attr("rel");
 
        // List moving to
        var $newList = jQuery(this);
 
        // Set outer wrapper height to height of current inner list
        var curListHeight = jQuery("#all-list-wrap").height();
        jQuery("#all-list-wrap").height(curListHeight);
 
        // Remove highlighting - Add to just-clicked tab
        jQuery("#explore-nav li a").removeClass("current");
        $newList.addClass("current");
 
        // Figure out ID of new list
        var listID = $newList.attr("rel");
 
        if (listID != curList) {
 
            // Fade out current list
            jQuery("#"+curList).fadeOut(300, function() {
 
                // Fade in new list on callback
                jQuery("#"+listID).fadeIn();
 
                // Adjust outer wrapper to fit new list snuggly
                var newHeight = jQuery("#"+listID).height();
                jQuery("#all-list-wrap").animate({
                    height: newHeight
                });
 
            });
 
        }       
 
        // Don't behave like a regular link
        return false;
    });
	
	/*
	if ($("#carouselClientwrapper").length > 0) {
	    $.querySort = {
	        path_to_template: 'http://www.seinet.com/website/wp-content/themes/seinet/',
	        number_of_posts: 100,
	        default_category: 'clientCarousel'
	    }
	 
	    // do the initial load.
	    var query = $.querySort.path_to_template + 'clientCarousel.php?showposts=' + $.querySort.number_of_posts + '&category_name=' + $.querySort.default_category;
	    
	    $("#carouselClientwrapper").load(query);
	    
	    //functions for the sorter
	    jQuery('.clientTypeCheckbox').click(function () {
	        var thecat;
	        var query;
	        
	        jQuery('.clientTypeCheckbox').each(function () {
				if (jQuery(this).attr('checked') == 'checked') {
					 query = '?query=showposts=' + $.querySort.number_of_posts + '&category_name=' + $.querySort.default_category;
				} else {
					 //query = '?query=showposts=' + $.querySort.number_of_posts + '&category_name=' + thecat;
				}
	        });
	        
	        $("#carouselClientwrapper").animate({opacity: 0}, function() {
	            $("#carouselClientwrapper").load($.querySort.path_to_template + 'clientCarousel.php' + query, function() {
	                height = $("#queryContainer").height() + 'px';
	                $("#carouselClientwrapper").animate({opacity: 1, height:height});
	            });
	        });
	        
	    });
	    
	    /*
		jQuery('input[name="clientTypeCheckbox"]').click(function () {
			jQuery('input[name="clientTypeCheckbox"]').each(function () {
				if (jQuery(this).attr('checked') == 'checked') {
					jQuery('li[name="carouselClient"][clientType=' + jQuery(this).attr('clientType') + ']').slideDown();
				} else {
					jQuery('li[name="carouselClient"][clientType=' + jQuery(this).attr('clientType') + ']').slideUp();
				}
			});
		});
		*/
	//}
});

jQuery(window).load(function($) {
	var diff = 0;
	var height = 0;
	var biggestColumn;
	var smallestColumn;
	var max = 0;
	
	// XTENT
	
	if (jQuery('#xtentFeatures1').length > 0) {
		biggestColumn = jQuery('#xtentFeatures2');
		smallestColumn = jQuery('#xtentFeatures1');
		
		if (jQuery('#xtentFeatures1').outerHeight(true) > jQuery('#xtentFeatures2').outerHeight(true)) {
			biggestColumn = jQuery('#xtentFeatures1');
			smallesetColumn = jQuery('#xtentFeatures2');			
			
			diff = biggestColumn.outerHeight(true) - smallestColumn.outerHeight(true)
			
			jQuery('#xtentFeatures2LastItem').height(diff);
			jQuery('div[id="xtentFeatures2LastItemCheckEmpty"]').height(diff);
			
			height = parseInt(biggestColumn.css('padding-top')) + parseInt(biggestColumn.css('padding-bottom'));
		} else {
			jQuery('div[id="xtentFeatures2LastItemCheckEmpty"]').remove();
			jQuery('#xtentFeatures2LastItem').remove();
			height = - (parseInt(smallestColumn.css('padding-top')) + parseInt(smallestColumn.css('padding-bottom')));
		}
		
		height += biggestColumn.outerHeight(true);
		smallestColumn.height(height);
		
		var padding = (height - jQuery('#xtentFeatures1 div:first-child').outerHeight(true)) / 2;
		jQuery('#xtentFeatures1 div:first-child').css('margin-top', padding);
		jQuery('#xtentFeatures1 div:first-child').css('margin-bottom', padding);
	}
	
	// XPAD
	
	if (jQuery('#xpadFeatures2').length > 0) {
		diff = 0;
		height = 0;
		biggestColumn = jQuery('#xpadFeatures2');
		smallestColumn = jQuery('#xpadFeatures1');
		
		if (jQuery('#xpadFeatures1').outerHeight(true) > jQuery('#xpadFeatures2').outerHeight(true)) {
			biggestColumn = jQuery('#xpadFeatures1');
			smallestColumn = jQuery('#xpadFeatures2');
		}
		
		diff = biggestColumn.outerHeight(true) - smallestColumn.outerHeight(true)
		smallestColumn.height(biggestColumn.outerHeight(true));
		
		jQuery('#xpadFeaturesSheetLink').css('margin-top', parseInt(diff) + 'px');
	}
	
	//CAROUSELS
	
	var carousels = new Array('homeClient', 'carouselClient', 'carouselCaseStudies', 'carouselOems', 'carouselSoftware', 'carouselAdmon');
	
	jQuery.each(carousels, function (index, value) {
		if (jQuery('li[name="' + value + '"]').length > 0) {
			max = 0;
			
			jQuery('li[name="' + value + '"]').each( function(index) {
				if (jQuery(this).height() > max)
					max = jQuery(this).height();
			});
			
			jQuery('li[name="' + value + '"]').each( function(index) {
				jQuery(this).height(max + 20);
			});
			
			maxImage = 0;
			
			jQuery('.' + value + 'Img').each( function(index) {
				if (jQuery(this).height() > maxImage)
					maxImage = jQuery(this).height();
			});
			
			jQuery('.' + value + 'Img').each( function(index) {
				jQuery(this).height(maxImage);
			});
			
			jQuery('#' + value).height(jQuery('#' + value + 'wrapper').outerHeight());
			
			jQuery('#' + value + ' > a').css('top', (jQuery('#' + value).height() / 2) - 18);
		}
	});
	
	//CONTACT
	
	if (jQuery('#contactTexts').length > 0) {
		jQuery('p[id="contact_p"]').click (
			function () {
				if (jQuery(this).attr('name') == 'false') {
					jQuery('p[name="true"]').siblings().slideUp();
					jQuery('p[name="true"]').attr('name', 'false');
					jQuery(this).siblings().slideDown();
					jQuery(this).attr('name', 'true');
				} else {
					jQuery(this).siblings().slideUp();
					jQuery(this).attr('name', 'false');
				}
			}
		);
		
		jQuery('p[id="contact_p_2"]').click (function () {
			jQuery('p[id="contact_p"]').siblings().slideUp();
			jQuery('p[id="contact_p"]').attr('name', 'false');
		})
	}
	
	jQuery('.infiniteCarousel').each(function () {
		jQuery(this).css('visibility', 'visible');
	});
	
});
