isIE = false;
$(document).ready(function () {
	jQuery.each(jQuery.browser, function(i, val) {
		if(i=="msie"){
			isIE = true;
		}
	
	});
	
	setBGImgSize();
	if(!isIE){
		DD_roundies.addRule('.round-2', 2, true);
		DD_roundies.addRule('.round-4', 4, true);
		DD_roundies.addRule('.round-4-no-bottom', "4px 4px 0px 0px", true);
		DD_roundies.addRule('.round-4-no-top', "0px 0px 4px 4px", true);
		DD_roundies.addRule('.round-4-no-left-corner', "0px 4px 4px 4px", true);
		DD_roundies.addRule('.round-4-no-left-side', "0px 4px 4px 0px", true);
		DD_roundies.addRule('.round-4-no-right-side', "4px 0px 0px 4px", true);
		DD_roundies.addRule('.round-6', 6, true);
		DD_roundies.addRule('.round-8', 8, true);
		DD_roundies.addRule('.round-4-swatch', 4, true);
	}
	
	$("a").filter(function() {
    	return this.hostname && this.hostname !== location.hostname;
	}).attr('target', '_blank').attr("title", "Opens in a new window");;

	setupOverlay();
	
	/*
	$('#mainnav a:not(.products), #logo').mouseover(function(){
		$('#product-rollover').mouseleave();	
	});
	
	$('#mainnav a.products').mouseover(function(){
		$('#product-rollover').slideDown(300); 
		$('#mainnav li a.products').parent().addClass("selected");
		
	}); 
	$('#product-rollover').mouseleave(function(){
		$('#product-rollover').slideUp(300); 
		$('#mainnav li a.products').parent().removeClass("selected");
	}); 
	*/

	var productNav = 2;
	$('#mainnav a.products').click(function(){
		if(productNav == 2){
			$('#product-rollover').slideDown(300); 
			$('#mainnav li a.products').parent().addClass("selected");
			productNav = 1;
		}else{
			$('#product-rollover').slideUp(300); 
			$('#mainnav li a.products').parent().removeClass("selected");
			productNav = 2;
		}
		
	}); 
	 
	$('.product-item .xa-pricing').hover(function(){
		$(this).html("CLICK TO ENROLL");
	}, function(){
		$(this).html("ACADEMY MEMBER PRICE "+$(this).attr("rel"));
	});

	$('.product-item .xa-pricing').click(function(){
		$('#header-enroll-link').trigger('click');
	});

	 
	$('#mailing-list-email').click(function(){
		if($('#mailing-list-email').val() == "Your Email"){
			$('#mailing-list-email').val("");
		}
	});
	$('#mailing-list-email').keypress(function(e) {
		if (e.which == 13) {
			submitMailingList();	
		}
		return true;
	});

	
	$('#mailing-list-submit').click(function() {
		submitMailingList();
		return false;
	});


	$('#xa-search-field').click(function(){
		if($(this).val() == "Search Members"){
			$(this).val("");
		}
	});
	$('#xa-search-field').keypress(function(e) {
		if (e.which == 13) {
			submitSearch();	
		}
		return true;
	});

	
	$('#xa-search-submit').click(function() {
		submitSearch();
		return false;
	});
/*	
	$('#loginform .submit').click(function() {
		alert('got me');
		$('#loginform').submit();
		return false;
	});
*/
	
	$('.add-ajax').each(function(){
		$(this).attr('href', $(this).attr('href') + "&a=1");
	});
});

function addslashes(str){
    return (str + '').replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
}

function stripslashes(str){
    return (str + '').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
        case '\\':
            return '\\';
        case '0':
            return '\u0000';
        case '':
            return '';
        default:
            return n1;
        }
    });
}

function setupOverlay(){
	$(".page-overlay").overlay({effect: 'apple', autoResize:true, expose: '#151515', onBeforeLoad: function() { 
            var wrap = this.getContent().find(".contentWrap"); 
            wrap.load(this.getTrigger().attr("href")); 
       }, closeOnClick: false, closeOnEsc: false,
            onClose: function(content) {
                if (jQuery.browser.msie) {
					if ($f()) {
						$f().stop();
					}
                }
    }});
}

window.onresize = function() {
    setBGImgSize();
}

setBGImgSize = function(){
	/*
	if($('#container .box-inside').height() < $(document).height()){
		$('#container .box-inside').css({
			height: $(document).height()
		});
	}*/
	
	newHeight = $(document).height()-$('#nav').height()-$('#middle').height()-45;
	if(newHeight > $('#footer').height()){
		$('#container .box-inside').css({
			height: newHeight
		});
	}
	
}

function submitMailingList(){
	if (checkEmail($('#mailing-list-email').val())) {
		$.post('?action=mailingSignUp&a=1&', {
			email: $('#mailing-list-email').val()
		}, function(data){
			if (data != 'error') {
				$('#mailing-list-form').html("<div class='left m-t-7'>&nbsp;&nbsp;&nbsp;&nbsp;Thank You!</div>");
			}
			else {
				alert("Unable to add you to the mailing list at this time.  Please wait a few minutes and try again.");
			}
		});
	}else{
		alert("Please check your input.  A valid email address was not detected.");
	}
	return false;
}

function dealerSelectState(){
	$.post(SERVER_URL+'/dealer-locator/?&a=1&', {
		country: $('#dealer_country').val(),
		state: $('#dealer_state').val()
	}, function(data){
		if (data != 'error') {
			
			$('#dealerLocatorInline').html(data);
			$('#dealerLocatorContainer').html(data);
		}
		else {
			//alert("Unable to add you to the mailing list at this time.  Please wait a few minutes and try again.");
		}
	});
}

function dealerSelectCountry(){
	$.post(SERVER_URL+'/dealer-locator/?&a=1&', {
		country: $('#dealer_country').val()
	}, function(data){
		if (data != 'error') {
			
			$('#dealerLocatorInline').html(data);
			$('#dealerLocatorContainer').html(data);
		}
		else {
			//alert("Unable to add you to the mailing list at this time.  Please wait a few minutes and try again.");
		}
	});
}


function checkEmail(email){
    if (email == "") return false;
    var expression = /^[a-zA-Z0-9\-\_\.\@]+$/;
    if (expression.test(email) && email.match(/@{1}/)) {
        return true;
    }
    return false;
}

function submitSearch(){
	window.location = SERVER_URL+"/users/search/?keyword="+$('#xa-search-field').val();
	return false;
}

function getVideoPlayer(width_, height_, target_id){
	if(height_ <= 400){height_ = 30;}else{height_=60;}
		$f(target_id, SERVER_URL+"/images/flowplayer-3.2.1.swf", {plugins: {
			controls:{
				bottom:20, 
        		height:height_, 
				width:width_-100,
				opacity:0.6,
				scrubberHeightRatio: 0.2,
				volumeSliderHeightRatio: 0.2,
				timeBgHeightRatio: 0.4,
        		backgroundColor: '#151515',
				buttonColor: '#252525',
				bufferColor: '#252525', 
        		backgroundGradient: 'none', 
		        fontColor: '#999999',
				progressColor: '#FFFFFF', 
        		timeColor: '#FFFFFF',
				timeBgColor: '#151515', 
        		autoHide: 'always', 
		        play:true, 
        		volume:true, 
        		mute:true, 
        		time:true, 
        		stop:false, 
        		playlist:false, 
		        fullscreen:true, 
		        scrubber: true 
			}
		}
	});
}

function getVideoPlayerStop(width_, height_, target_id){
	if(height_ <= 400){height_ = 30;}else{height_=60;}
		$f(target_id, SERVER_URL+"/images/flowplayer-3.2.1.swf", {clip:{autoPlay:false,autoBuffering:false},plugins: {
			controls:{
				bottom:20, 
        		height:height_, 
				width:width_-100,
				opacity:0.6,
				scrubberHeightRatio: 0.2,
				volumeSliderHeightRatio: 0.2,
				timeBgHeightRatio: 0.4,
        		backgroundColor: '#151515',
				buttonColor: '#252525',
				bufferColor: '#252525', 
        		backgroundGradient: 'none', 
		        fontColor: '#999999',
				progressColor: '#FFFFFF', 
        		timeColor: '#FFFFFF',
				timeBgColor: '#151515', 
        		autoHide: 'always', 
		        play:true, 
        		volume:true, 
        		mute:true, 
        		time:true, 
        		stop:false, 
        		playlist:false, 
		        fullscreen:true, 
		        scrubber: true 
			}
		}
	});
}

