/************************************************************/
	function lookup(inputString) {
		if(inputString.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
		} else {
			$.post("rpc.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup
	
	function fill(thisValue) {
		$('#inputString').val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
	}


$(document).ready(function() {
						   
/*	$("#tag-cloud").tagCloud({"direction":"vertical", "easein":"easeOutBack", "speed":2000});
*/						   
jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
}, "Please specify a valid phone number");



	$('#mini_cf').validate({submitHandler: function(form){
			
		var fname = $('#fname').val();
		var lname = $('#lname').val();
		var email = $('#email').val();
		var phone = $('#phone').val();
		var comments =  $('#comments').val();
	
		var datastr ='fname=' + fname + '&lname=' + lname + '&email=' + email + '&phone=' +phone+ '&comments=' +comments
				
		$('#mini_cf_cont').mask("Sending information...");
		$.post('includes/send_mail.php', datastr,  function() {
			  showResponse6('mini_cf_cont');
		});
		
		return false;
									 
		}
	});
	
		$('#contactus').validate({submitHandler: function(form){
			
		var fname = $('#fname').val();
		var lname = $('#lname').val();
		var email = $('#email').val();
		var phone = $('#phone').val();
		var company = $('#company').val();
		var city = $('#city').val()
		var website = $('#website').val();
		var comments =  $('#comments').val();
		
		/*var m1 =  $('#m1').val();
		var m2 =  $('#m2').val();
		var m3 =  $('#m3').val();*/
		
		var w1 =  $('#w1').val();
		var w2 =  $('#w2').val();
		var w3 =  $('#w3').val();
		var w4 =  $('#w4').val();
		
		var s1 =  $('#s1').val();
		var s2 =  $('#s2').val();
		var s3 =  $('#s3').val();
		var s4 =  $('#s4').val();
		
	
		var datastr = 'fname=' + fname + '&lname=' + lname + '&email=' + email + '&phone=' +phone+ '&company=' +company+ '&city=' +city+ '&website=' +website+ 
			'&comments=' +comments+ /*'&m1=' +m1+ '&m2=' +m2+ '&m3=' +m3+ */'&w1=' +w1+ '&w2=' +w2+ '&w3=' +w3+ '&w4=' +w4+ '&s1=' +s1+ '&s2=' +s2+ '&s3=' +s3+ '&s4=' +s4+
			
				
		$('#contactus_cont').mask("Sending information...");
		$.post('includes/send_mail_contactus.php', datastr,  function() {
			  showResponse1('contactus_cont');
		});
		
		return false;
									 
		}
	});
	
	function showResponse6(maskdiv) {
				$('#'+maskdiv).unmask();
				$('#'+maskdiv).mask("Your information was sent...");
				
				$('#fname').val("");
				$('#lname').val("");
				$('#email').val("");
				$('#phone').val("");
				$('#comments').val("");
				
				setTimeout("$('#"+maskdiv+"').unmask();", 3000);
	}
	
	function showResponse1(maskdiv) {
				$('#'+maskdiv).unmask();
				$('#'+maskdiv).mask("Your information was sent...");
				
				$('#fname').val("");
				$('#lname').val("");
				$('#email').val("");
				$('#phone').val("");
				$('#company').val("");
				$('#city').val("")
				$('#website').val("");
				$('#comments').val("");
				
				$('#m1').attr('checked', false);
				$('#m2').attr('checked', false);
				$('#m3').attr('checked', false);
				
				$('#w1').attr('checked', false);
				$('#w2').attr('checked', false);
				$('#w3').attr('checked', false);
				$('#w4').attr('checked', false);
				
				$('#s1').attr('checked', false);
				$('#s2').attr('checked', false);
				$('#s3').attr('checked', false);
				$('#s4').attr('checked', false);
				
				setTimeout("$('#"+maskdiv+"').unmask();", 3000);
	}
				

});



/************************************************************/
window.onerror=function(desc,page,line,chr){
/* alert('JavaScript error occurred! \n'
  +'\nError description: \t'+desc
  +'\nPage address:      \t'+page
  +'\nLine number:       \t'+line
 );*/
}

$(function(){
 $('a').focus(function(){this.blur();});
 SI.Files.stylizeAll();
 slider.init();

 $('input.text-default').each(function(){
  $(this).attr('default',$(this).val());
 }).focus(function(){
  if($(this).val()==$(this).attr('default'))
   $(this).val('');
 }).blur(function(){
  if($(this).val()=='')
   $(this).val($(this).attr('default'));
 });

 $('input.text,textarea.text').focus(function(){
  $(this).addClass('textfocus');
 }).blur(function(){
  $(this).removeClass('textfocus');
 });

 var popopenobj=0,popopenaobj=null;
 $('a.popup').click(function(){
  var pid=$(this).attr('rel').split('|')[0],_os=parseInt($(this).attr('rel').split('|')[1]);
  var pobj=$('#'+pid);
  if(!pobj.length)
   return false;
  if(typeof popopenobj=='object' && popopenobj.attr('id')!=pid){
   popopenobj.hide(50);
   $(popopenaobj).parent().removeClass(popopenobj.attr('id').split('-')[1]+'-open');
   popopenobj=null;
  }
  return false;
 });
 $('p.images img').click(function(){
  var newbg=$(this).attr('src').split('bg/bg')[1].split('-thumb')[0];
  $(document.body).css('backgroundImage','url('+_siteRoot+'images/bg/bg'+newbg+'.jpg)');
 
  $(this).parent().find('img').removeClass('on');
  $(this).addClass('on');
  return false;
 });

 $('div.sc-large div.img:has(div.tml)').each(function(){
  $('div.tml',this).hide();
  $(this).append('<a href="#" class="tml_open">&nbsp;</a>').find('a').css({
   left:parseInt($(this).offset().left)+864,top:parseInt($(this).offset().top)+1
  }).click(function(){
   $(this).siblings('div.tml').slideToggle();
   return false;
  }).focus(function(){this.blur();}); 
 });
});
var slider={
 num:-1,
 cur:0,
 cr:[],
 al:null,
 at:10*1000,
 ar:true,
 init:function(){
  if(!slider.data || !slider.data.length)
   return false;

  var d=slider.data;
  slider.num=d.length;
  var pos=Math.floor(Math.random()*1);//slider.num);
  for(var i=0;i<slider.num;i++){
   $('#'+d[i].id).css({left:((i-pos)*1000)});
   $('#slide-nav').append('<a id="slide-link-'+i+'" href="#" onclick="slider.slide('+i+');return false;" onfocus="this.blur();">'+(i+1)+'</a>');
  }

  $('img,div#slide-controls',$('div#slide-holder')).fadeIn('0');
  slider.text(d[pos]);
  slider.on(pos);
  slider.cur=pos;
  window.setTimeout('slider.auto();',slider.at);
 },
 auto:function(){
  if(!slider.ar)
   return false;

  var next=slider.cur+1;
  if(next>=slider.num) next=0;
  slider.slide(next);
 },
 slide:function(pos){
  if(pos<0 || pos>=slider.num || pos==slider.cur)
   return;

  window.clearTimeout(slider.al);
  slider.al=window.setTimeout('slider.auto();',slider.at);

  var d=slider.data;
  for(var i=0;i<slider.num;i++)
   $('#'+d[i].id).stop().animate({left:((i-pos)*1000)},1000,'swing');
  
  slider.on(pos);
  slider.text(d[pos]);
  slider.cur=pos;
 },
 on:function(pos){
  $('#slide-nav a').removeClass('on');
  $('#slide-nav a#slide-link-'+pos).addClass('on');
 },
 text:function(di){
  slider.cr['a']=di.client;
  slider.cr['b']=di.desc;
  slider.ticker('#slide-client span',di.client,0,'a');
  slider.ticker('#slide-desc',di.desc,0,'b');
 },
 ticker:function(el,text,pos,unique){
  if(slider.cr[unique]!=text)
   return false;

  ctext=text.substring(0,pos)+(pos%2?'-':'_');
  $(el).html(ctext);

  if(pos==text.length)
   $(el).html(text);
  else
   window.setTimeout('slider.ticker("'+el+'","'+text+'",'+(pos+1)+',"'+unique+'");',30);
 }
};
// STYLING FILE INPUTS 1.0 | Shaun Inman <http://www.shauninman.com/> | 2007-09-07
if(!window.SI){var SI={};};
SI.Files={
 htmlClass:'SI-FILES-STYLIZED',
 fileClass:'file',
 wrapClass:'cabinet',
 
 fini:false,
 able:false,
 init:function(){
  this.fini=true;
 },
 stylize:function(elem){
  if(!this.fini){this.init();};
  if(!this.able){return;};
  
  elem.parentNode.file=elem;
  elem.parentNode.onmousemove=function(e){
   if(typeof e=='undefined') e=window.event;
   if(typeof e.pageY=='undefined' &&  typeof e.clientX=='number' && document.documentElement){
    e.pageX=e.clientX+document.documentElement.scrollLeft;
    e.pageY=e.clientY+document.documentElement.scrollTop;
   };
   var ox=oy=0;
   var elem=this;
   if(elem.offsetParent){
    ox=elem.offsetLeft;
    oy=elem.offsetTop;
    while(elem=elem.offsetParent){
     ox+=elem.offsetLeft;
     oy+=elem.offsetTop;
    };
   };
  };
 },
 stylizeAll:function(){
  if(!this.fini){this.init();};
  if(!this.able){return;};
 }
};

/********************************************************************************************************************************/

/**
 * Copyright (c) 2009 Sergiy Kovalchuk (serg472@gmail.com)
 * 
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *  
 * Following code is based on Element.mask() implementation from ExtJS framework (http://extjs.com/)
 *
 */
;(function($){
	
	/**
	 * Displays loading mask over selected element(s). Accepts both single and multiple selectors.
	 *
	 * @param label Text message that will be displayed on top of the mask besides a spinner (optional). 
	 * 				If not provided only mask will be displayed without a label or a spinner.  	
	 * @param delay Delay in milliseconds before element is masked (optional). If unmask() is called 
	 *              before the delay times out, no mask is displayed. This can be used to prevent unnecessary 
	 *              mask display for quick processes.   	
	 */
	$.fn.mask = function(label, delay){
		$(this).each(function() {
			if(delay !== undefined && delay > 0) {
		        var element = $(this);
		        element.data("_mask_timeout", setTimeout(function() { $.maskElement(element, label)}, delay));
			} else {
				$.maskElement($(this), label);
			}
		});
	};
	
	/**
	 * Removes mask from the element(s). Accepts both single and multiple selectors.
	 */
	$.fn.unmask = function(){
		$(this).each(function() {
			$.unmaskElement($(this));
		});
	};
	
	/**
	 * Checks if a single element is masked. Returns false if mask is delayed or not displayed. 
	 */
	$.fn.isMasked = function(){
		return this.hasClass("masked");
	};

	$.maskElement = function(element, label){
	
		//if this element has delayed mask scheduled then remove it and display the new one
		if (element.data("_mask_timeout") !== undefined) {
			clearTimeout(element.data("_mask_timeout"));
			element.removeData("_mask_timeout");
		}

		if(element.isMasked()) {
			$.unmaskElement(element);
		}
		
		if(element.css("position") == "static") {
			element.addClass("masked-relative");
		}
		
		element.addClass("masked");
		
		var maskDiv = $('<div class="loadmask"></div>');
		
		//auto height fix for IE
		if(navigator.userAgent.toLowerCase().indexOf("msie") > -1){
			maskDiv.height(element.height() + parseInt(element.css("padding-top")) + parseInt(element.css("padding-bottom")));
			maskDiv.width(element.width() + parseInt(element.css("padding-left")) + parseInt(element.css("padding-right")));
		}
		
		//fix for z-index bug with selects in IE6
		if(navigator.userAgent.toLowerCase().indexOf("msie 6") > -1){
			element.find("select").addClass("masked-hidden");
		}
		
		element.append(maskDiv);
		
		if(label !== undefined) {
			var maskMsgDiv = $('<div class="loadmask-msg" style="display:none;"></div>');
			maskMsgDiv.append('<div>' + label + '</div>');
			element.append(maskMsgDiv);
			
			//calculate center position
			maskMsgDiv.css("top", Math.round(element.height() / 2 - (maskMsgDiv.height() - parseInt(maskMsgDiv.css("padding-top")) - parseInt(maskMsgDiv.css("padding-bottom"))) / 2)+"px");
			maskMsgDiv.css("left", Math.round(element.width() / 2 - (maskMsgDiv.width() - parseInt(maskMsgDiv.css("padding-left")) - parseInt(maskMsgDiv.css("padding-right"))) / 2)+"px");
			
			maskMsgDiv.show();
		}
		
	};
	
	$.unmaskElement = function(element){
		//if this element has delayed mask scheduled then remove it
		if (element.data("_mask_timeout") !== undefined) {
			clearTimeout(element.data("_mask_timeout"));
			element.removeData("_mask_timeout");
		}
		
		element.find(".loadmask-msg,.loadmask").remove();
		element.removeClass("masked");
		element.removeClass("masked-relative");
		element.find("select").removeClass("masked-hidden");
	};
 
})(jQuery);



$(document).ready(function(){
	
	var element = $('#list_tag a');;
	var offset = 0; 
	var stepping = 0.01;
	var list = $('#list_tag');
	var $list = $(list)
	
	$list.mousemove(function(e){
		var topOfList = $list.eq(0).offset().top
		var listHeight = $list.height()
		stepping = (e.clientY - topOfList) /  listHeight * 0.2 - 0.1;
		
	});
	

	for (var i = element.length - 1; i >= 0; i--)
	{
		element[i].elemAngle = i * Math.PI * 2 / element.length;
	}
	
	
	setInterval(render, 10);
	
	
	function render(){
		for (var i = element.length - 1; i >= 0; i--){
			
			var angle = element[i].elemAngle + offset;
			
			x = 120 + Math.sin(angle) * 40;
			y = 45 + Math.cos(angle) * 40;
			size = Math.round(10 - Math.sin(angle) * 4);
			
			var elementCenter = $(element[i]).width() / 2;
	
			var leftValue = (($list.width()/2) * x / 85 - elementCenter) + "px"
	
			$(element[i]).css("fontSize", size + "pt");
			$(element[i]).css("opacity",size/60);
			$(element[i]).css("zIndex" ,size);
			$(element[i]).css("left" ,leftValue);
			$(element[i]).css("top", y + "%");
		}
		
		offset += stepping;
	}
	
	
});


/// PAYMENT 

	$(document).ready(function(){
							   
			$("#paymentform").validate({ignore: ":hidden"});
			 
			$('.monthly').click(function(){
				if($(this).is(':checked')){
					updatemonthly();
				}else{
					if($(this).attr("id") == "seos_m"){
						$("#seo_hoursreq").val('')
						updatemonthly();
					}else{
						updatemonthly();
					}
				}
			});
			
			$("#seo_hoursreq").change( function() {
				if($("#seo_hoursreq").val() != ""){
					updatemonthly();
				}
			});
			$("#seo_hoursreq").keyup( function() {
				if($("#seo_hoursreq").val() != ""){
					updatemonthly();
				}
			});
		
			function updatemonthly(){
				var monthlytotal = 0;
				$(".monthly:checked").each(function () {
					if($(this).attr("id") == "seos_m"){
						if($("#seo_hoursreq").val() != ""){
							monthlytotal += parseInt($(this).val(), 10)*$("#seo_hoursreq").val();
						}
					} else {
						monthlytotal += parseInt($(this).val(), 10); 	
					}
				});
				
				if(monthlytotal > 0){
					$("#monthlytotal").html("$ "+formatCurrency(monthlytotal)+" Monthly");
					$("#mtotal").val(formatCurrency(monthlytotal))
				} else {
					$("#monthlytotal").html('');	
					$("#mtotal").val('')
				}
			}
			
			$('.annually').click(function(){
				if($(this).is(':checked')){
					updateannually();
				}else{
					updateannually();
				}
			});
			
			
			function updateannually(){
				var annuallytotal = 0;
				$(".annually:checked").each(function () {
					annuallytotal += parseInt($(this).val(), 10); 
				});
				
				if(annuallytotal > 0){
					$("#annuallytotal").html("$ "+formatCurrency(annuallytotal)+" Annually");
					$("#atotal").val(formatCurrency(annuallytotal));
				} else {
					$("#annuallytotal").html('');	
					$("#atotal").val('');
				}
			}
			
			
			$('#webhosting_basic_m').change(function(){
				if($(this).is(':checked')){
					$('#webhosting_basic_y').attr('disabled', true);
				}else{
					$('#webhosting_basic_y').removeAttr('disabled');
				}
			});
			
			$('#webhosting_basic_y').change(function(){
				if($(this).is(':checked')){
					$('#webhosting_basic_m').attr('disabled', true);
				}else{
					$('#webhosting_basic_m').removeAttr('disabled');
				}
			});
			
			$('#webhosting_plus_m').change(function(){
				if($(this).is(':checked')){
					$('#webhosting_plus_y').attr('disabled', true);
				}else{
					$('#webhosting_plus_y').removeAttr('disabled');
				}
			});
			
			$('#webhosting_plus_y').change(function(){
				if($(this).is(':checked')){
					$('#webhosting_plus_m').attr('disabled', true);
				}else{
					$('#webhosting_plus_m').removeAttr('disabled');
				}
			});
			
			$('#webhosting_intera_m').change(function(){
				if($(this).is(':checked')){
					$('#webhosting_intera_y').attr('disabled', true);
				}else{
					$('#webhosting_intera_y').removeAttr('disabled');
				}
			});
			
			$('#webhosting_intera_y').change(function(){
				if($(this).is(':checked')){
					$('#webhosting_intera_m').attr('disabled', true);
				}else{
					$('#webhosting_intera_m').removeAttr('disabled');
				}
			});
			
			$('#seos_m').change(function(){
				if($(this).is(':checked')){
					$('#seos_y').attr('disabled', true);
				}else{
					$('#seos_y').removeAttr('disabled');
				}
			});
			
			$('#seos_y').change(function(){
				if($(this).is(':checked')){
					$("#seo_hoursreq").attr('disabled', true);
					$('#seos_m').attr('disabled', true);
				}else{
					$("#seo_hoursreq").removeAttr('disabled');
					$('#seos_m').removeAttr('disabled');
				}
			});
			
			$(".payment_type").click(function() {
				
				if($("input[name=payment]:checked").val() == "cc"){
					$("#formpayment_cc").show();
					$("#formpayment_cc input").show();
					$("#formpayment_ec").hide();
					$("#formpayment_ec input").hide();
					$("#formpayment_ec input").val('');
					
				} else {
					$("#formpayment_cc").hide();
					$("#formpayment_cc input").hide();
					$("#formpayment_cc input").val('');
					$("#formpayment_ec").show();	
					$("#formpayment_ec input").show();
				}
				
			});
			
			
					$("#formpayment_ec").hide();
					$("#formpayment_ec input").hide();
					$("#formpayment_cc").hide();
					$("#formpayment_cc input").hide();
			
			
			
			
			$("#paymentform").submit( function(){
				if($("#seos_m").is(':checked')){
					if($("#seo_hoursreq").val() == ""){
						alert("Please enter a valid number on Hours Requested");	
						$("#seo_hoursreq").focus();
						return false;
					}
				}
			});
			

			
			
			
			
			function formatCurrency(num) {     num = isNaN(num) || num === '' || num === null ? 0.00 : num;     return parseFloat(num).toFixed(2); } 

	});					   
						  



