/**
* Styleswitch stylesheet switcher built on jQuery
* Under an Attribution, Share Alike License
* By Kelvin Luck ( http://www.kelvinluck.com/ )
**/

(function($)
{
	$(document).ready(function() {

		$('.styleswitch').click(function()
		{
			switchStylestyle(this.getAttribute("rel"));
			return false;
		});

		$('#t7_search').bind('keypress', function(e) {
		        if(e.keyCode==13){
		                ten7.search.submit();
		        }
		});	
			
		$('#t7_flavor').hover(			
			function()
			{
				$('#t7_flavor').html('<a href="#" rel="green" class="styleswitch"><img height="29" width="29" border="0" alt="" title="" src="projects_files/flava.green.png" style="margin:8px 6px 0px 0px;padding:0px;"/></a><a href="#" rel="pink" class="styleswitch"><img height="29" width="29" border="0" alt="" title="" src="projects_files/flava.pink.png" style="margin:8px 6px 0px 0px;padding:0px;"/></a><a href="#" rel="blue" class="styleswitch"><img height="29" width="29" border="0" alt="" title="" src="projects_files/flava.blue.png" style="margin:8px 0px 0px 0px;padding:0px;"/></a>');
				$('.styleswitch').click(function()
				{
					switchStylestyle(this.getAttribute("rel"));
					return false;
				});			
			},
			function()
			{
				$('#t7_flavor').html('Flavor');
			}		
		);		
		
		// social media box
		if ( $.cookie('social_show') == 'hide3' ) {
		
		  // don't show it
		  //alert( 'dont show' );
      $.cookie('social_show', 'hide3', {path: '/', expires: 365 } );			

		} else {

      // show it
      $("#t7_hdr_bar").html('<div id="t7_social"></div>');
      $("#t7_social").toggle();
		  //$("#t7_social").html('<div id="eks">x</div>Social butterfly?<br>Stalk us on <a href="http://cli.gs/yB60XB">Facebook</a> & <a href="http://cli.gs/3yUgJq">Twitter</a>');
		  //$("#t7_social").html('<div id="eks">x</div>Ten Seven Web Design Workshop<br />in Minneapolis &ndash;  <a href="/register">Register now!</a>');
		  //$("#t7_social").html('<div id="eks">x</div>Friday Special 2-4pm (now!)<br />$20 off &ndash;  <a href="/register">Register now!</a> Coupon code "eks"');
		  
		  $("#t7_social").html('<div id="eks">x</div><form action="http://tenseveninteractive.createsend.com/t/y/s/diyuuk/" method="post">Sign up for updates <input id="diyuuk-diyuuk" name="cm-diyuuk-diyuuk" size="20" type="text" value="with your email address" onfocus="ten7.box.clear(this.value);" onblur="ten7.box.set(this.value);" /> & stalk us on <a href="http://cli.gs/yB60XB">Facebook</a> & <a href="http://cli.gs/3yUgJq">Twitter</a></form>');
		  
		  //onfocus="if(this.value==\'with your email\') this.value='';" onblur="if(this.value==\'\') this.value=\'with your email\';"
		  
		  $("#t7_social").fadeIn(3000);
		
		};

    // ability to click the x and stop the social media fade in :)
		$('#eks').click(function()
		{
		  $("#t7_social").fadeOut(500);
		  $.cookie('social_show', 'hide3', {path: '/', expires: 365 } );			
			return false;
		});

		$('#eks').hover(
  		function()
  		{
  		  $("#eks").css({cursor:'hand', cursor:'pointer'});
  		},
  		function()
  		{
  		}
		);			
		

	});


	function switchStylestyle(styleName)
	{
		$('link[@rel*=style][title]').each(function(i) 
		{
			this.disabled = true;
			if (this.getAttribute('title') == styleName) this.disabled = false;
		});
		
		$.cookie('style', styleName, {path: '/', expires: 365 } );	
		
		
			$('#t7_hdr_logo').html('<a href="/"><img src="projects_files/hdr_logo.'+styleName+'.png" height="45" width="518" border="0" alt="Ten Seven, Interactive | Home" title="Ten Seven, Interactive | Home" /></a>');
		
		
	}
})(jQuery);


ten7 = {};


ten7.search =
{
	submit: function()
	{
		window.location = "http://tenseveninteractive.com/search/node/" + $('#t7_search').val() ;
	}
};

ten7.box = 
{
  clear: function(curVal) {
    if (curVal == 'with your email address') {
      $('#diyuuk-diyuuk').val('');    
    }
  },
  set:  function(curVal) {
    if (curVal == '') {
      $('#diyuuk-diyuuk').val('with your email address');    
    }
  }
  

}




jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

