var page_id = "";


/* ***********************
 * ***********************
 *
 *	jQuery Init File
 * 	Author: Lithyem Industries
 *	www.lithyem.net
 *
 * ***********************
 * *********************** */

$(document).ready(function(){
	
	/* ***********************
	 * ***********************
	 *
	 *	Contact Form Redirects
	 *
	 * ***********************
	 * *********************** */
	var contact_pages = new Array();
	contact_pages['general_information'] = 'contact.html';
	contact_pages['update_email_address'] = 'contact_email.html';
	contact_pages['newsletter'] = 'contact_newsletter.html';
	contact_pages['submit_testimonial'] = 'contact_testimonial.html';
	contact_pages['software_support'] = 'contact_support.html';
	contact_pages['website_feedback'] = 'contact_feedback.html';
	contact_pages['product_feedback'] = 'contact_product.html';
	
	$("#contact_reason").change(function(){
		var id = $(this).val();
		var page = contact_pages[id];
		document.location = page;
	});
	
	
	/* ***********************
	 * ***********************
	 *
	 *	Buy Section Auto Detection - that rhymes.
	 *
	 * ***********************
	 * *********************** */
	
	// Check OS
	var OSName="Unknown OS";
	if (navigator.appVersion.indexOf("Win")!=-1){
		OSName="win";
	}else{
		OSName="nix";	
	}
	
	// Redirect if no hash is found and user is on a mac
	if(page_id == "buypage" && OSName == "nix"){
		if(document.location.hash != "#noredirect"){
			document.location = "buy_server.html";
		}
	}
	
	
	/* ***********************
	 * ***********************
	 *
	 *	Accordion
	 *
	 * ***********************
	 * *********************** */
	
	$('.accordion_content div').hide();
	
	// Accordion
	$('.accordion_link').toggle(
		function(){
			$(this).addClass('open');
			var r = $(this).attr('rel');
			$('#'+r+' div').fadeIn();
			
		},
		
		function(){
			$(this).removeClass('open');
			var r = $(this).attr('rel');
			$('#'+r+' div').fadeOut();
		}
	);
	
	$('.accordion_link:first').click();
	
	
	/* ***********************
	 * ***********************
	 *
	 *	Round Corner Buttons
	 *
	 * ***********************
	 * *********************** */
	
	// update rounded buttons
	$('a.button').each(
		function(){
			var t = "<span>"+$(this).html()+"</span>";
			$(this).html(t);
			$(this).parent().addClass('clear');
		}
	);
	
	$('a.button_r').each(
		function(){
			var t = "<span>"+$(this).html()+"</span>";
			$(this).html(t);
			$(this).parent().addClass('clear');
		}
	);
		
	/* ***********************
	 * ***********************
	 *
	 *	In-Page Tabs
	 *
	 * ***********************
	 * *********************** */
	 
	 // hides / shows tabs
	$('ul.pagetabs li a').click(function(){
		var rel = $(this).parent().attr('title');
		$(this).parent().parent().find('li.current').removeClass('current');
		$(this).parent().addClass('current');
		$(this).parent().parent().next('div.tabs_content_block').find('.tab_content').hide();
		$("#"+rel).fadeIn('fast');
		return false;
	});
	
	// hide all blocks of tab content that are not the first one
	$(document).find('div.tabs_content_block').each(function(){
		$(this).find('.tab_content:not(:first)').hide();
	});
	
	// hide all subcontent on load
	$('.tab_content ul').each(function(){
		$(this).find('p').hide();
		$(this).find('ul').hide();
	});
	
	// assign click function to all links to toggle the siblings beneath them
	$('.tab_content ul li a').toggle(
		function(){
			$(this).siblings().slideDown('fast');
			$(this).addClass('open');
			return false;
		},
		function(){
			$(this).siblings().slideUp('fast');
			$(this).removeClass('open');
			return false;
		}
	);
	
	// unbind click events from standard links wrapped in p tags
	$('.tab_content ul li a').each(
		function(){
			var c = $(this).parent().is('li');
			if(!c){
				$(this).unbind('click');
			}
		}
	);
	
	// add a lastchild class to the last main ul in content
	$('.tab_content ul').children("li:has(ul):last").addClass('lastchild');
	$('.tab_content ul').each(function(){
		$(this).children("li:has(ul):last").addClass('lastchild');
	});
	
	
	
	
	
	
	/* ***********************
	 * ***********************
	 *
	 *	Misc
	 *
	 * ***********************
	 * *********************** */
	
	// add placeholders for forms
	$(":input[type='text']").not('#srchtxt').placehold();
	$(":input[type='textarea']").placehold();
	$("a[rel='external']").attr('target','blank');

	
});