$(document).ready(function(){

	

/* Set up IHC stock feed widget */
	
	
var ihcurl = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%3D'ihc'%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=?";

$.getJSON(ihcurl,function(data){
		
$('#topbar .stock').html('');
		
		
var html = '<div class="tick">';
		
html += 'NYSE: ';
		
html += '<strong>' + data.query.results.quote.Symbol + '</strong> - ';
	
html += 'Last Trade: <span class="item">$' + Math.round(data.query.results.quote.LastTradePriceOnly*100)/100 + '</span> ';
		
html += 'Change: <span class="item">' + data.query.results.quote.Change_PercentChange + '</span> ';
		
html += 'Avg. Daily Vol: <span class="item">' + data.query.results.quote.AverageDailyVolume + '</span> ';
				
html += '</div>';
		
		

$('#topbar .stock').html(html);
	
});

	
	
var amicurl = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20%3D%20'amic'&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=?";

$.getJSON(amicurl,function(data){
		
		
var html = '<div class="tick">';
		
html += 'NASDAQ: ';
		
html += '<strong>' + data.query.results.quote.Symbol + '</strong> - ';
	
html += 'Last Trade: <span class="item">$' + Math.round(data.query.results.quote.LastTradePriceOnly*100)/100 + '</span> ';
		
html += 'Change: <span class="item">' + data.query.results.quote.Change_PercentChange + '</span> ';
		
html += 'Avg. Daily Vol: <span class="item">' + data.query.results.quote.AverageDailyVolume + '</span> ';
				
html += '</div>';
		
		

$('#topbar .stock').append(html);
	
});
	
	
	

$('#feature .play').click(function(e){
		
e.preventDefault();
		
		
var vID = $(this).attr('rel');
		
var vHTML = '';
		
vHTML += '<object width="500" height="349">';
		
vHTML += '<param name="movie" value="http://www.youtube.com/v/'+ vID +'?fs=1&amp;hl=en_US&amp;showinfo=0&amp;rel=0&amp;controls=0&amp;autohide=1&amp;hd=1&amp;autoplay=1">';
		
vHTML += '<param name="allowscriptaccess" value="always"><param name="wmode" value="transparent">';
		
vHTML += '<embed width="500" height="349" src="http://www.youtube.com/v/'+ vID +'?fs=1&amp;hl=en_US&amp;showinfo=0&amp;rel=0&amp;controls=0&amp;autohide=1&amp;hd=1&amp;autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" wmode="transparent">';
		
vHTML += '</object>';
		
		

$('#feature .first').html('').html(vHTML);
		
		
$('#feature .menu li.active').removeClass('active');
		
		
$(this).parent().parent().addClass('active');
	
});
	
	

$("#navigation li").hover(
function(){
$("ul.children", this).fadeIn("fast");},function() {$("ul.children", this).fadeOut("fast");});

$('#video-form-submit').live('click', function(e){
    e.preventDefault();
    var valid = true;

    var button = $(this);
    var form = $(this).parent().parent();
    if(form.encoding)
    {
	    $(form).attr('encoding', 'multipart/form-data');      			
    }
    else
    {   	
	    $(form).attr('enctype', 'multipart/form-data');			
    }			


    if($('#name').val() == '') valid = false;
    if($('#email').val() == '') valid = false;
    if($('#phone').val() == '') valid = false;
    if($('#city').val() == '') valid = false;
    if($('#state').val() == '') valid = false;
    if($('#zip').val() == '') valid = false;

    if(valid == false)
    {
	    alert('All fields are required. Please enter all fields before submitting.');
	    $(button).attr('disabled', false);
	    return false;
    }

    $(button).attr('value', 'Submitting, please wait...').attr('disabled', true);
    
    /*
    console.log($(form).attr('target'));
    $(form).submit();
    
    $("#postframe").load(
        function(){
            res = $('#postframe').contents().find('body').html();
            console.log(res);
            if(res == 'Sent')
            {
                $(form).html('').html('<div class="form-success">Thank You. We will respond as soon as possible.</div>');
            }
            else
            {
                alert('There was an error processing your form. Please try again');
                $(button).attr('value', 'Submit').attr('disabled', false);
            }
        }
    );
    */

    $.ajax({
        url: 'http://'+ window.location.hostname +'/wp-content/themes/ipafamily/processVideo.php',
        data: $(form).serialize(),
        type:'POST',
        success: function(res)
        {
            if(res == 'Sent')
            {
                $(form).html('').html('<div class="form-success">Thank You. We will respond as soon as possible.</div>');
            }
            else
            {
                alert('Sorry, we could not send your message at this time. Please try again');
                $(button).attr('value', 'Submit').attr('disabled', false);
            }
        },
        error: function() {
            alert('There was an error processing your form. Please try again');
            $(button).attr('value', 'Submit').attr('disabled', false);   
        }
    });
    
    });

});
