// ricability popup
function GoAndClose(url){
	$('#mod_rica').jqmHide(); 
	window.open(url, 'new');
	return true;
}

// !initalize popups
$(document).ready(function() {
	if (location.pathname.indexOf("/blog/") == -1 ) {
		$('#mod_aup').jqm({ajax:'popups/inc_usagepolicy.php',trigger:'a.pop_aup'});
		$('#mod_privacy').jqm({ajax:'popups/inc_privacystatement.php',trigger:'a.pop_privacy'});
		$('#mod_disclaimer').jqm({ajax:'popups/inc_disclaimer.php',trigger:'a.pop_disclaimer'});
		$('#mod_oldproducts').jqm({ajax:'popups/inc_oldproducts.php',trigger:'a.pop_oldproducts'});
		$('#mod_offers').jqm({ajax:'popups/inc_offers.php',trigger:'a.pop_offers'});
	}
});

// !slide header hint text	
$(document).bind('ready', function(event) {
	$('.placeholder').each(function(i) {
 
		var item = $(this);
		var hint_text = item.attr('rel'); // hint text
		var error_text = item.attr('alt'); // error text
		var empty_text = item.attr('longdesc'); // empty text
		var form = item.parents('form:first');

		if (item.val() === '') {
			item.val(hint_text);
			item.css('color', '#888');
		}
 
		item.bind('focus.placeholder', function(event) {
			if (item.val() === hint_text || item.val() === error_text || item.val() === empty_text) { 
				item.val('');
				item.removeClass("needsfilled");
			}
			item.css('color', '');
 		});
 
		item.bind('blur.placeholder', function(event) {
 			if (item.val() === '') {
 				item.val(hint_text);
 				item.css('color', '#888');
 			}
	 	});
 
		form.bind("submit.placeholder", function(event) {
 			if (item.val() === hint_text) {
				item.val("");
			}
		}); 
 
 	});
 
});

// !valid email
function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
};

// !fade side pics
$(document).ready(
	function(){
		$('.fade_pics').innerfade({
			animationtype: 'fade',
			speed: 1500,
			timeout: 4000,
			type: 'sequence',
			containerheight: '511'
			});
		}
);

// !header slider
$(document).ready(		
	function(){
		var bar = $('#headerSlideContainer');
		var top = bar.css('top');
		$(window).scroll(function() {
			if($(this).scrollTop() > 50) {
				bar.stop().animate({'top' : '0px'}, 500);
			} else {
				bar.stop().animate({'top' : top}, 500);
			}
		});
	}
);

// !validate email
$(document).ready(
	function(){
		var item = $('#sl_email');
		var hint_text = item.attr('rel'); // hint text
		var error_text = item.attr('alt'); // error text
		var empty_text = item.attr('longdesc'); // empty text
    	
    	// submit top form and load secondary form	
    	$('#sl_newsletter_form').submit(function(e) {
    			e.preventDefault();
				var input = $('#sl_email');
				if ((input.val() == "") || (input.val() == empty_text) || (input.val() == hint_text) )  {
					input.addClass("needsfilled");
					input.val(empty_text);
				} else {
					input.removeClass("needsfilled");
					var p_email = $('#sl_email').val();
    				if (isValidEmailAddress(p_email)) {
    					var url = location.pathname;
						if (url.indexOf("blog")) {
							path = "../";
						}
						$('.sl_newsletter_box').load(path + 'scripts/ajax_subscribe.php', { email: p_email });
					} else {
						input.val(error_text);
						input.addClass("needsfilled");
					}
				}

    	});
	});

// !validate hd_model search
$(document).ready(
	function(){
       	// check hd_find_form
    	$('#hd_find_form').submit(function(e) {
    		e.preventDefault();
    		var input = $('#hd_model');
    		var hint_text = input.attr('rel'); // hint text
			//var error_text = item.attr('alt'); // error text
			var empty_text = input.attr('longdesc'); // empty text
			
			if ((input.val() == "") || (input.val() == empty_text) || (input.val() == hint_text)  ) {
				input.addClass("needsfilled");
				input.val(empty_text);
			} else {
				input.removeClass("needsfilled");
				var url = location.pathname;
				if (url.indexOf("blog")) {
					path = "../";
				}
				location.href = path + 'find.php?' + $('#hd_find_form').serialize();
			}
    	});
    	
    	$('#sl_find_form').submit(function(e) {
    		e.preventDefault();
    		var input = $('#sl_model');
    		var hint_text = input.attr('rel'); // hint text
			//var error_text = item.attr('alt'); // error text
			var empty_text = input.attr('longdesc'); // empty text
    		
			if ((input.val() == "") || (input.val() == empty_text) || (input.val() == hint_text)  ) {
				input.addClass("needsfilled");
				input.val(empty_text);
			} else {
				input.removeClass("needsfilled");
				var url = location.pathname;
				if (url.indexOf("blog")) {
					path = "../";
				}

				location.href = path + 'find.php?' + $('#sl_find_form').serialize();
			}
    	});	
    	
    });

function openPopup(theURL,winName,features) {
	window.open(theURL,winName,features);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

var newwindow;
function popwin(url,w,h){
	window.open(url, "external", "width=" + w +",height=" + h + ",resizable=no,scrollbars=yes,status=no,location=no,toolbar=no,menubar=no");
}
