/* Author: 
	MINDGRUVE.COM
	TTenoever
	MStacy
*/

jQuery(document).ready(function() {


// TOP SLIDE PANEL FOR NEWSLETTER SIGNUP
	jQuery('.top-slide-controls-open').toggle(function() {
		jQuery('.top-slide').animate({'top': '0'}, 'fast');
  		jQuery('.open-top-slide').animate({'top': '99px'}, 'fast').css('background-position', '-214px 0');;
	}, function() {
		jQuery('.top-slide').animate({'top': '-100px'}, 'fast');
		jQuery('.open-top-slide').animate({'top': '-1px'}, 'fast').css('background-position', '0 0');
	});
	
	jQuery('#slider').jCarouselLite({
			circular: true,
			auto: 2500,
			visible:1,
			scroll: 1
		});
	
	
		
		window.onload = function(){
			jQuery("#carousel1").jCarouselLite({
				auto: 2500,	
				vertical: true,
				circular: true,
				visible:1,
				scroll: -1
			});
			
			setTimeout(function(){
				jQuery("#carousel2").jCarouselLite({
					auto: 2500,
					circular: true,
					vertical: true,
					visible:1,
					scroll: -1
				});
			}, 500);
			
			setTimeout(function(){
				jQuery("#carousel3").jCarouselLite({
					auto: 2500,
					circular: true,
					vertical: true,
					visible:1,
					scroll: -1
				});
			}, 1000);
			
			setTimeout(function(){
				jQuery("#carousel4").jCarouselLite({
					auto: 2500,
					circular: true,
					vertical: true,
					visible:1,
					scroll: -1
				});
			}, 1500);
			
			setTimeout(function(){
				jQuery("#carousel5").jCarouselLite({
					auto: 2500,
					circular: true,
					vertical: true,
					visible:1,
					scroll: -1
				});
			}, 2000);
			
		};
		
	
	
	//MODAL SETUP
	jQuery('#publishForm, #advertiseForm').bValidator();
	
	jQuery('#publishers').click(function () {
		jQuery('#publishWin').css({'display': 'block', 'top': popupPos(jQuery('#publishWin'))});
		jQuery('#modalBack').css({'display': 'block', 'height': jQuery.getDocHeight()});
	});	
	
	jQuery('.open-publish-window').click(function () {
		jQuery('#publishWin').css({'display': 'block', 'top': popupPos(jQuery('#publishWin'))});
		jQuery('#modalBack').css({'display': 'block', 'height': jQuery.getDocHeight()});
	});	
	
	jQuery('#advertisers').click(function () {
		jQuery('#advertiseWin').css({'display': 'block', 'top': popupPos(jQuery('#advertiseWin'))});
		jQuery('#modalBack').css({'display': 'block', 'height': jQuery.getDocHeight()});
	});	
	
	jQuery('.popupClose').each(function () {
		jQuery(this).click(function () {
			jQuery(this).parent('.popupWin').css('display', 'none');
			jQuery('#modalBack').css('display', 'none');
		});
	});
	
	function popupPos(elem) {
		var topPos = jQuery(window).scrollTop() + 108,
			maxPos = jQuery.getDocHeight() - elem.height() - 120,
			setPos;
		
		topPos > maxPos ? setPos = maxPos : setPos = topPos;
		//jQuery('html, body').animate({scrollTop: setPos}, 'slow');
		return setPos + "px";
	}
	
	jQuery.getDocHeight = function () {
		return Math.max(
			jQuery(document).height(),
			jQuery(window).height(),
			// For opera:
			document.documentElement.clientHeight
		);
	};
	
	
	
});


