function getTransformProperty(element) {
    var properties = [
        'transform',
        'WebkitTransform',
        'MozTransform',
        'msTransform',
        'OTransform'
    ];
    var p;
    while (p = properties.shift()) {
        if (typeof element.style[p] != 'undefined') {
            return p;
        }
    }
    return false;
}




$(document).ready(function(){


	/*
	Drop down functionality

	*/
	var content = $('#dropdown .content');
$('#dropdown-tab a').click(function()
	{
		content.slideToggle('medium');
		$(this).toggleClass('open');
		if($(this).attr("class") == 'open'){
			$("#slider_toggle").hide();
			$("#slider_toggle_open").show();
		}
		else{
			$("#slider_toggle").show();
			$("#slider_toggle_open").hide();
		}
		return false;
	});

	$('#dropdown form input:not(input.btn_submit)').focus(function()
	{
		$(this).parents('p').siblings('p').removeClass('sel');
		$(this).parents('p').addClass('sel');
		return false;
	});

	$('#dropdown form textarea').focus(function()
	{
		$(this).parents('p').siblings('p').removeClass('sel');
		$(this).parents('p').addClass('sel');
		return false;
	});


	$('#dropdown form input.btn_submit').click(function()
	{
		var form_text = $('p#form_text');

		var name = $('#form_name').val();
		var email = $('#form_email').val();
		var message = $('#form_message').val();
		if (name =='' || email =='' || message == '') {
			form_text.text('One or more of the fields was left blank - please try again.');
			return false;
		}
		$.post("http://www.flying-paramecia.net/brynnshepherd20/taketwo/include/mailer.php", { name: name, email: email, message: message } );
		$('#form_name').val('');
		$('#form_email').val('');
		$('#form_message').val('');
		form_text.text('Thanks!  You should receive a reply within a couple of days.');
		return false;

	});


  /*
  	Spinning functionality

   var div = document.getElementById('lime_nav');
   if(document.getElementById('lime_nav_folio')){
   		div = document.getElementById('lime_nav_folio');
   }
   if(document.getElementById('lime_nav_services')){
   		div = document.getElementById('lime_nav_services');
   }
   if(document.getElementById('lime_nav_contact')){
   		div = document.getElementById('lime_nav_contact');
   }
   if(document.getElementById('lime_nav_blog')){
   		div = document.getElementById('lime_nav_blog');
   }
      if(document.getElementById('lime_nav_edit')){
   		div = document.getElementById('lime_nav_edit');
   }
	var property = getTransformProperty(div);
	if (property) {
   	 var d = 0;
   	 setInterval(
        function () {
            div.style[property] = 'rotate(' + (d++ % 360) + 'deg)';
        },
        	400
    	);
	}

	*/
	$("#message_bubble").animate({width: "203px", height: "123px"}, "slow", function(){
		$(".text_bubble").fadeIn("slow");
	});


	$('.tag_list a').click(function() {
	    $('.tag_list a').removeClass('selected');
	    $(this).addClass('selected');
	    var myId = $(this).attr('id');
	    $('ul.thumb li').each(function(){
	  	if ($(this).hasClass(myId))
		{
		    $(this).show();
		}
		else
		{
		    $(this).hide();
		}
	    })
	});

	$('#map_provo').click(function(){$("#map_bubble").fadeIn("slow");});
	$('#map_tempe').click(function(){$("#map_bubble_tempe").fadeIn("slow");});
	$('#map_bubble').mouseleave(function(){
	  	//$("#map_bubble").fadeOut("slow");
	});
	$('#map_bubble_tempe').mouseleave(function(){
		$("#map_bubble_tempe").fadeOut("slow");
	});




	$('.map-loshermanos').mouseenter(function(){
		$('.map-loshermanos-over').fadeIn("slow");
	});
	$('.map-loshermanos-over').mouseleave(function(){
		$('.map-loshermanos-over').fadeOut("slow");
	});



	$('.map-playproject').mouseenter(function(){
		$('.map-playproject-over').fadeIn("slow");
	});
	$('.map-playproject-over').mouseleave(function(){
		$('.map-playproject-over').fadeOut("slow");
	});



	$('.map-provobakery').mouseenter(function(){
		$('.map-provobakery-over').fadeIn("slow");
	});
	$('.map-provobakery-over').mouseleave(function(){
		$('.map-provobakery-over').fadeOut("slow");
	});



	$('.map-comedysportz').mouseenter(function(){
		$('.map-comedysportz-over').fadeIn("slow");
	});
	$('.map-comedysportz-over').mouseleave(function(){
		$('.map-comedysportz-over').fadeOut("slow");
	});

    $('.map-beach, .map-montis, .map-marquee, .map-sushi').mouseenter(function() {
       var overlord = $("." + $(this).attr('class') + "-over");
       overlord.fadeIn('slow').mouseleave(function() {
                $(this).fadeOut('slow', function() {
                    $(this).unbind('mouseleave');
                });
           });;
    });

	$('#gallery ul li').mouseenter(function(){
		$(this).children('a').children('img').fadeTo("fast", 0.33);
		$(this).children('#licaption').fadeTo("fast", 100);
	});
	$('#gallery ul li').mouseleave(function(){
		$(this).children('a').children('img').fadeTo("fast", 100);
		$(this).children('#licaption').fadeTo("fast", 0);
	});



	//$('#map_bubble').mouseenter(function(){
	//	$("#map_bubble").fadeIn("slow");
	//})
	//$('#map_bubble_tempe').mouseenter(function(){
	//	$("#map_bubble_tempe").fadeIn("slow");
	//})

	// Add Twitter
	/*var username='getlimed'; // set user name
	var format='json'; // set format, you really don't have an option on this one
	var url='http://api.twitter.com/1/statuses/user_timeline/'+username+'.'+format+'?callback=?'; // make the url

		$.getJSON(url,function(tweet){ // get the tweets
			//Month array
			var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

			//Current Date
			var now = new Date();

			//JSON Date
			var d1 = tweet[0].created_at;




			var d2 = d1.split(' ');
			var day = d2[2];
			var month = d2[1];
			var year = d2[5];
			var time= d2[3];
			time = time.split(':');

			for(var x=0; x<12; x++){
				if(months[x] == month){
					month = x;
				}
			}



			//var twit_date = new Date(year, month, day, time[0], time[1], time[2]);

			//var date_diff = Math.ceil((now.getTime()+25200000)-twit_date.getTime())/1000/60/60;//Difference in seconds.

			var tweet = tweet[0].text;
			var output = "<div id='tweet'>" + tweet + "</div><div id='tweet_date'>TWEETED " + day + '/' + month + '/' + year + "</div>";
			$("#last-tweet").html(output); // get the first tweet in the response and place it inside the div
	});


	*/

	var randomnumber=Math.floor(Math.random()*8);
	var phrases = new Array("Hey! How's it going?","I'm down here!","Welcome back!", "Glad to see you again.", "Have you liked us on Facebook?", "Follow me on twitter!", "It's time to get limed!", "We make this look easy.");
	var selection = phrases[randomnumber];
	$('div.text_bubble').html(selection);


	var height = '-22.5px';
	if(randomnumber == 4){
		height ='-33.5px';
	}
	$('div.text_bubble').css('margin-top', height);
	$('span.checkbox').click(function() {
        $(this).toggleClass('checked').next('input:checkbox').click();
    });
    $('input:checkbox:checked').prev('span.checkbox').addClass('checked');
	$('input:text, textarea').focus(function() {
        if(!$(this).hasClass('not-default')) {
            var oldVal = $(this).val();
            $(this).addClass('not-default').data('oldVal', oldVal).val('');
        }
    }).focusout(function() {
        if($(this).val() == '') {
            $(this).val($(this).data('oldVal')).removeClass('not-default');
        }
    });
    $('a.nevermind, input.send-it').click(function() {
        $(this).addClass('press');
        $this = $(this);
        var T = function() {
            $this.removeClass('press')
        };
        setTimeout(T, 200);
    });
    $('.front_view').click(function() {
        $('#gallery-wrap').slideDown('slow');
    });
    $('#gallery-min').click(function() {
        $('#gallery-wrap').slideUp('slow');
    });
    $('.thumb-wrap').click(function() {
        $('#gallery-wrap').find('.big').attr('src', $(this).find('img').attr('src'));
    });
    $('#contact_form').submit(function(e) {
        e.preventDefault();
        $('.form-error').remove();
        var error = false;
        $(this).find('input:text, textarea').each(function() {
            if($(this).val() == '' || $(this).val() == false || !$(this).hasClass('not-default')) {
                error = true;
                var css = $(this).position();
                css.height = $(this).outerHeight();
                css.width = $(this).outerWidth();
                var idTag = 'form-error-' + $(this).attr('name');
                var err = $('<div id="' + idTag + '" class="form-error"><span>Required.</span></div>');
                $('#content').append(err);
                $('#' + idTag).css({
                    top     :       css.top + ((css.height - $("#" + idTag).outerHeight()) / 2),
                    left   :        (css.left + css.width) - 70
                });
            }
        });
        if(!error) {
            $.ajax({
                url     :   $(this).attr('action'),
                data    :   $(this).serializeArray(),
                success :   function(data) {
                    $('#pants').slideUp('slow', function() {
                        $(this).before('<div id="flash-msg-return" style="opacity: 0;"><span>' + data + '</span></div>').prev('#flash-msg-return').fadeTo('slow', 1, function() {
                            $(this).delay(1500).fadeTo('slow', 0);
                        });
                    });
                },
                type    :   "POST"
            });
        }
    });
    $('a.nevermind').click(function(e) {
        e.preventDefault();
        $('input:text').each(function() {
            var theVal = $(this).attr('name');
            $(this).val(theVal);
        });
        $('input:checkbox:checked').prev('span.checkbox').click();
        $('textarea').val('Tell us a little bit about what you do, or let us know when and how would be best to chat.');
    });
 });

