$(document).ready(function(){


    $('.block_wrap:first').addClass('first');


        var flash = $('#movie_src').html();


        if(flash.length > 5) {

		    var flash_w = $('#movie_w').html();
		    var flash_h = $('#movie_h').html();

			if(!flash_w)
				flash_w = 668;
			if(!flash_h)
				flash_h = 345;

			$('#movie_w').remove();
			$('#movie_h').remove();			

            $('#movie_wrap img').remove();
            $('#movie_wrap').flash(
                { src: flash,
                  width: flash_w,
                  height: flash_h },
                { version: 8 }
            );
        }


	var cite = '<p class="cite">'+$("#box-speech-grey em").html()+'</p>';
	$("#box-speech-grey em").remove();
	$("#box-speech-grey .close-quote").after(cite);
	

	$("ul.folio li a").hover(
    function()
    {
        var id = '#logo_' + $(this).attr("id");
		$(id).removeClass("hidden");
		console.log('IN-'+id);
		console.log($(id).attr("src"));
    },
    function()
    {
        var id = '#logo_' + $(this).attr("id");
		$(id).addClass("hidden");
		console.log('OUT-'+id);
	});




  $("a[@href^=http]").each(
    function(){
            if(this.href.indexOf(location.hostname) == -1) {
        $(this).attr('target', '_blank');
      }
    }
  )


	var msrc = $('#movie_src').html();
	if(msrc.length > 10) {
		$('#boxes div:first').addClass('restrict_vid');
	}
	else {
		if(!$('#boxes div:first').hasClass('no_restrict'))
		{
			$('#boxes div:first').addClass('restrict');
		}
	}



$('#box-form input.button').click(function() {
    var first_name = $("input#first_name").val();
    var last_name = $("input#last_name").val();
    var phone = $("input#phone").val();
    var email = $("input#email").val();
    var post = $("#post").val();
    var experience = $("#experience").val();
    var status = $("#status").val();
    var newsletter = $("input#newsletter").val();


    var dataString = 'first_name='+first_name+'&last_name='+last_name+'&phone='+phone+'&email='+email+'&post='+post+'&experience='+experience+'&status='+status+'&newsletter='+newsletter;


    $.ajax({  
        type: "POST",  
        url: "/register",  
        data: dataString,  
        success: function(feedback) { 
            if(feedback.indexOf('<div class="error">') !=-1) {
                $('#reg_form .error').remove();
                $('#reg_form').append(feedback);
                $('#reg_form .error').hide()
                .fadeIn(1500);
            }
            else {
                $('#box-form strong').remove();
                $('#box-form p').remove();
                $('#reg_form').html("<div id='message'></div>");  
                $('#message').html("")   
                .append(""+feedback+"")  
                .hide()  
                .fadeIn(1500);  
            }
        }  
    });  
    return false;
});


function flash2(div, w, h, movie) {

    var flash = '<object type="application/x-shockwave-flash" data="'+movie+'" height="'+h+'" width="'+w+'"><param name="movie" value="'+movie+'"><param name="wmode" value="transparent"><param name="play" value="true"><param name="loop" value="false"></object>';

    $('#'+div).html(flash);


}



});


