/* 
*	JS Template for jquery
*	Copyright Chris J. Lee 2007
*/

$(document).ready(function(){
	//	Setup Tabs
	//	Bind next tab buttons
	$('#client-left-nav').tabs();

	
	$('#bottom-tab-nav > ul').tabs({ fx: { opacity: 'toggle' } });
	//$('#left-nav > ul').tabs({ fx: { opacity: 'toggle' } });

  $('#f-request-for-proposal').bind('click',function(){
	location.href="http://www.ottawaydigital.com/contact/";
  });
	
	// Form reset then set
	$('input.text').bind('focus', function() {
	if($(this)[0].value == this.defaultValue) $(this)[0].value='';
	$(this).css('border-color', '#000000');
	});
	$('input.text').bind('blur', function() {
	if($(this)[0].value =='') $(this)[0].value=this.defaultValue;	
	$(this).css('border-color', '#eeeeee')
	});
	$('input.text').hover( 
	function() {  // onmouseover
		$(this).css('border-color', '#BA381E'); 	
		},
	function() { // onmouseout
		$(this).css('border-color', '#eeeeee');
	});
	
	$('.sub #sub-nav ul li:gt(6)').addClass('mt-10');
	
	
	
	

	$('#next-tab').click(function() {
		//$('#left-nav > ul').tabsClick(  $('#left-nav > ul').tabsSelected() + 1 );
		console.log($('#left-nav > ul').tabsClick(  $('#left-nav > ul').tabsSelected() ) );
	});
	//$('#prev-tab').click(function() {
//		$('#left-nav > ul').tabsClick(  $('#left-nav > ul').tabsSelected() - 1 );								
//	});
	//$('#left-nav > ul').tabsClick(  $('#prev-tab').tabsSelected() - 1 );	
	
/*UI 1.5:

$('#example').tabs('select', $('#example').data('selected.ui-tabs') +
1); */

    
      /* Coupon stuff */
	  // prepare the form when the DOM is ready 

	  
        // form submit stuff
		// prepare the form when the DOM is ready 
		// bind form using ajaxForm 
// prepare the form when the DOM is ready 
    // bind form using ajaxForm 
    $('#contact').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#myForm', 
 
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() { 
            $('#coup').css("visibility", "hidden"); 
        } 
    }); 
    $('#quick').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#quickto', 
 
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() {  
        } 
    }); 
		
    $('#imn').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#imnto', 
 
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() {  
        } 
    }); 
					
	$('#radio').ajaxForm({ 
		// target identifies the element(s) to update with the server response 
		target: '#links', 
 
		// success identifies the function to invoke when the server response 
		// has been received; here we apply a fade-in effect to the new content 
		success: function() {  
		} 
	}); 
	
   /* $('#newsletter').ajaxForm({ 
        // target identifies the element(s) to update with the server response 
        target: '#newsto', 
 
        // success identifies the function to invoke when the server response 
        // has been received; here we apply a fade-in effect to the new content 
        success: function() {  
        } 
    }); */
		function elementToString(n, useRefs) {
			var attr = "", nest = "", a = n.attributes;
			for (var i=0; a && i < a.length; i++)
				attr += ' ' + a[i].nodeName + '="' + a[i].nodeValue + '"';
		
			if (n.hasChildNodes == false)
				return "<" + n.nodeName + "\/>";
		
			for (var i=0; i < n.childNodes.length; i++) {
				var c = n.childNodes.item(i);
				if (c.nodeType == 1)       nest += elementToString(c);
				else if (c.nodeType == 2)  attr += " " + c.nodeName + "=\"" + c.nodeValue + "\" ";
				else if (c.nodeType == 3)  nest += c.nodeValue;
			}
			var s = "<" + n.nodeName + attr + ">" + nest + "<\/" + n.nodeName + ">";
			return useRefs ? s.replace(/</g,'&lt;').replace(/>/g,'&gt;') : s;
		};

      var oh = $("#myForm").height()+30;
      var ow = $("#myForm").width()+30; 
      var fow = $("#everything").width();
      var foh = $("#everything").outerHeight();
      var w = $(window).height();
      var wd = $(window).width();
      var h = (w / 2) - (oh /2); 
      var ww = (wd / 2) - (ow /2);
      
    $("#overlay").css("visibility","hidden").css("width",fow+"px").css("height",foh+"px").css("opacity","0");
    $("#go").click(function(){
    jQuery.easing.def = "easeOutBounce";
      $("#go").animate({ 
        opacity: 0
      }, 850 );
      $("#overlay").css("visibility", "visible").animate({ 
        opacity: 0.25
      }, 850 );
      $("#close").animate({ 
        opacity: 1
      }, 850 );
      $("#myForm").animate({ 
        opacity: 1,
        top: h+'px',
        left: ww+'px'
      }, 850 ); 
    });
    
    $("#close").click(function(){
    jQuery.easing.def = "easeInOutCirc";
      $("#go").animate({ 
        opacity: 1
      }, 850 );
      $("#overlay").animate({ 
        opacity: 0
      }, 850 ).css("visibility", "hidden");
      $("#close").animate({ 
        opacity: 0
      }, 850 );
      $("#myForm").animate({ 
        opacity: 0, 
        top: "0px",
        left: "-"+ow+"px"
      }, 375 );
    });
    
    $("#overlay").click(function(){
    jQuery.easing.def = "easeInOutCirc"; 
      $("#go").animate({ 
        opacity: 1
      }, 850 );
      $("#overlay").animate({ 
        opacity: 0
      }, 850 ).css("visibility", "hidden");
      $("#close").animate({ 
        opacity: 0
      }, 850 );
      $("#myForm").animate({ 
        opacity: 0,
        top: "0px",
        left: "-"+ow+"px"
      }, 375 );
    });

});
