/**
 * @HTML Embed Code Generator
 * @author Jason Lau
 * @website http://jasonlau.biz
 * @email jason_lau@live.com
 * @copyright 2000-2010 all rights reserved
 * @license Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.
 * Based on a work by Jason Lau originally published in 2000.
 * Permissions beyond the scope of this license may be requested at the email address above. 
 * http://jasonlau.biz/main/index.php?p=pages&title=Contact-Me. 
 * http://jasonlau.biz/public/mixdown.mp3
 * http://dotcom.name/random-funpic-280x280.swf
 */
<!--
$(function(){
    var url = $("#url"),
    width = $("#width"),
    height = $("#height"),
    plugin = $("#plugin"),
    autoplay = $("#autoplay"),
    loop = $("#loop"),
    format = $("#format"),
    allFields = $([]).add(url).add(width).add(height);
    
    function updateTips(t) {
        $("#error").html('Error: '+t);
        $("#error").show('slow');
    }

    function checkLength(o,n,min,max) {       
        if ( o.val().length > max || o.val().length < min ) {
            o.addClass('ui-state-error');
            updateTips("Length of " + n + " must be between "+min+" and "+max+".");
            return false;
            } else {
                return true;
            }
		}
		
    function checkRequired(o,n) {
        if ( o.val().length < 1 ) {
            o.addClass('ui-state-error');
            updateTips(n);
            return false;
            } else {
                return true;
			}
		}

    function checkRegexp(o,regexp,n) {        
        if ( !( regexp.test( o.val() ) ) ) {
            o.addClass('ui-state-error');
            updateTips(n);
            return false;
            } else {
				return true;
			}
		}
		
		$("#submit").click(function() {
		  var bValid = true;
          bValid = bValid && checkLength(url,"url",6,255);
          bValid = bValid && checkRequired(width,"Width has to be at least 0!");
          bValid = bValid && checkRequired(height,"Height has to be at least 0!");
          var link = $("#url").val()
          var test = link.split(".");
          var ext = test.length-1;
          var extension = test[ext].toLowerCase()
          var bad_extensions = ["com","net","ru","cn","name","uk","biz","org"];
          for(i in bad_extensions){
            if(bad_extensions[i] == extension){
                bValid = false;
                $("#url").addClass('ui-state-error');
                updateTips('Invalid URL. Enter a vaild URL eg. http://dotcom.name/musicfile.mp3. Your URL must link directly to your music or video file and not to a webpage. If you enter your link into the browser address bar, does it open a webpage? If so, your link is not valid.')
                }
            }
            
            bValid = bValid && checkRegexp(url,/^(https?|ftp|mms):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i,"Enter a vaild URL eg. http://dotcom.name/musicfile.mp3");
            
            if(bValid){
                allFields.removeClass('ui-state-error');
                if($("#error").css('display') != 'none'){
                    $("#error").hide('slow');
                }
                       
                var theurl = $('#url').val(),
                theformat = $('#format').val(),
                theplugin = $('#plugin').val(),
                theautoplay = ($('#autoplay').val() == 'false')?false:true,
                theloop = ($('#loop').val() == 'false')?false:true,
                thewidth = parseInt($('#width').val()),
                theheight = parseInt($('#height').val());
                theparams = $('#params').val();
                var preview = ($('#preview').val()=='yes')?true:false;
                if(theformat == 'swfobject' && theplugin != 'adobeflash'){
                    $('#format').addClass('ui-state-error');
                    updateTips('SWFObject is for Adobe Flash plugin only!');
                    return;
                    } else if(theformat == 'swfobject'){
                        prompt('SWFObject requires swfobject.js! For more information go to the address below.','http://code.google.com/p/swfobject/');
                        $("#swfobjectcode").jlEmbed({
                            id : 'jasonlau_dot_biz',
                            url : theurl,
                            plugin : theplugin,
                            format : theformat,
                            autoplay : theautoplay,
                            loop : theloop,
                            width : thewidth,
                            height : theheight,
                            params : theparams,
                            value : true
                        });
                        
                        var theHTMLcode = $("#swfobjectcode").val();
                        tc = theHTMLcode.split('jlembed_');
                        var newcode = '';
                        for(var i in tc){
                            newcode += tc[i]
                        }
                        if(preview){
                           $("#ec-preview-body").jlEmbed({
                            id : 'jasonlau_dot_biz',
                            url : theurl,
                            plugin : theplugin,
                            format : theformat,                       
                            autoplay : theautoplay,
                            loop : theloop,
                            width : thewidth,
                            height : theheight,
                            params : theparams
                          }); 
                        }
                        
                        var newHTML = newcode;
                       
                    } else {
                        
                        $("#ec-preview-body").jlEmbed({
                            id : 'jasonlau_dot_biz',
                            url : theurl,
                            plugin : theplugin,
                            format : theformat,                       
                            autoplay : theautoplay,
                            loop : theloop,
                            width : thewidth,
                            height : theheight,
                            params : theparams
                        });
                        var newHTML = $("#ec-preview-body").html();
                        if(!preview){
                            $("#ec-preview-body").html('Nothing to display.');
                        }
                        
                    }
                    
                    if(theformat == 'objectembed'){
                        var f = newHTML.split('</object>');
                        var fixedHTML = f[0] + '</embed></object>';
                        } else if(theformat == 'embed'){
                            var f = newHTML.split('>');
                            var fixedHTML = f[0] + '></embed>';
                        } else {
                            var fixedHTML = newHTML;
                        }
                        
                        $("#ec-html-body").html('<textarea onclick="this.focus();this.select()" id="htmlcode" cols="40" rows="5">' + fixedHTML + '</textarea>');

            }
		});
        
        $('#urlhelpicon').click(function(){
            if($('#urlhelp').css('display') == 'none'){
                $(this).addClass('ui-icon-circle-minus');
                $('#urlhelp').show('slow');
            } else {
                $(this).removeClass('ui-icon-circle-minus');
                $('#urlhelp').hide('slow');
            }
            
          	$('#urlhelp').html('Insert the URL address for your file. This is the internet link or web address to your file, which should begin with http:// or mms://.');
        });
		
		$('#widthhelpicon').click(function(){
		  if($('#widthhelp').css('display') == 'none'){
		      $(this).addClass('ui-icon-circle-minus');
		      $('#widthhelp').show('slow');
		  } else {
		      $(this).removeClass('ui-icon-circle-minus');
		      $('#widthhelp').hide('slow');
		  }
          $('#widthhelp').html('This is the player width. 300 is a good width for Quicktime, Real Player, and Windows Media Player if your file is not video. Otherwise, the width should be set to whatever the actual movie width is.');  
		});
		
		$('#heighthelpicon').click(function(){		 
		  if($('#heighthelp').css('display') == 'none'){ 
		      $(this).addClass('ui-icon-circle-minus');
		      $('#heighthelp').show('slow');
		  } else {
		      $(this).removeClass('ui-icon-circle-minus');
		      $('#heighthelp').hide('slow');
		  }
          $('#heighthelp').html('This is the player height. For audio files, 50 is a good height for Windows Media Player or 80 for Real Player. For video, the height should be set much higher to accomodate the picture window. The Quicktime interface does not require as much height as the other plugins do except when using a video file.');
			});
		
		$('#pluginhelpicon').click(function(){
		  if($('#pluginhelp').css('display') == 'none'){
		      $(this).addClass('ui-icon-circle-minus');
		      $('#pluginhelp').show('slow');
		  } else {
		      $(this).removeClass('ui-icon-circle-minus');
		      $('#pluginhelp').hide('slow');
		  }
          $('#pluginhelp').html('This is the browser player plugin which will play your file. Not all computers have the same plugins installed, so it is best measure to offer your webpage visitors a range of options to choose from. The type of file you are using can also help determine which plugin to use. Look at the file extension (the last letters after the last dot in the filename) .mp3 will work with Real Player(RP), Windows Media Player(WMP), or Quicktime(QT). Do not use Flash unless the file has .swf or .flv file extension. Do not use QT unless the file extension is .mov. WMP is the most popular plugin, is preinstalled on most Windows systems, and will make your file available to most users. Use WMP for most media file types except .ra, .rm, and .rpm, which require RP.');
			});
		
		$('#autoplayhelpicon').click(function(){
		  if($('#autoplayhelp').css('display') == 'none'){
		      $(this).addClass('ui-icon-circle-minus');
		      $('#autoplayhelp').show('slow');
		  } else {
		      $(this).removeClass('ui-icon-circle-minus');
		      $('#autoplayhelp').hide('slow');
		  }
          $('#autoplayhelp').html('Set this to yes if you want your file to automatically play when the page opens. Flash does not use this feature.');
			});
		
		$('#loophelpicon').click(function(){
		  if($('#loophelp').css('display') == 'none'){
		      $(this).addClass('ui-icon-circle-minus');
		      $('#loophelp').show('slow');
		  } else {
		      $(this).removeClass('ui-icon-circle-minus');
		      $('#loophelp').hide('slow');
		  }
          $('#loophelp').html('Set this to yes if you want your file to automatically play again when it has completed playing. Flash does not use this feature.');
			});
		
		$('#formathelpicon').click(function(){
		  if($('#formathelp').css('display') == 'none'){
		      $(this).addClass('ui-icon-circle-minus');
		      $('#formathelp').show('slow');
		  } else {
		      $(this).removeClass('ui-icon-circle-minus');
		      $('#formathelp').hide('slow');
		  }
          $('#formathelp').html('MySpace users and others in similar situations should use Object Only. Otherwise, in all other cases, whenever possible, use Object With Embed. Do not use Embed Only unless you absolutely have to. Object With Embed is the format which is most compatible with all web browsers. If you are able to use javascript, I highly recommend SWFObject while using Adobe Flash. For more information on SWFObject, go to <a style="color:#000000;" href="http://code.google.com/p/swfobject/" target="_blank">http://code.google.com/p/swfobject/</a>'); 
			});
            
            $('#paramshelpicon').click(function(){
                
                if($('#paramshelp').css('display') == 'none'){
                    $(this).addClass('ui-icon-circle-minus');
                    $('#paramshelp').show('slow');
                } else {
                    $(this).removeClass('ui-icon-circle-minus');
                    $('#paramshelp').hide('slow');
                }
                $('#paramshelp').html('You can pass any additional parameters here in the following format -<br><em>wmode=transparent quality=high console=cons</em><br>Separate each parameter with a space and do not enclose the parameter values with quotes.');
            
            });
            
            $('#previewhelpicon').click(function(){
                
                if($('#previewhelp').css('display') == 'none'){
                    $(this).addClass('ui-icon-circle-minus');
                    $('#previewhelp').show('slow');
                } else {
                    $(this).removeClass('ui-icon-circle-minus');
                    $('#previewhelp').hide('slow');
                }
                $('#previewhelp').html('Do you want to preview the HTML code result?');
            
            });
            
            $('#urlhelp').click(function(){ 
                $(this).hide('slow');
                $('#urlhelpicon').removeClass('ui-icon-circle-minus');
			});
            
            $('#widthhelp').click(function(){ 
                $(this).hide('slow');
                $('#widthhelpicon').removeClass('ui-icon-circle-minus');
			});
            
            $('#heighthelp').click(function(){ 
                $(this).hide('slow');
                $('#heighthelpicon').removeClass('ui-icon-circle-minus');
			});
            
            $('#autoplayhelp').click(function(){ 
                $(this).hide('slow');
                $('#autoplayhelpicon').removeClass('ui-icon-circle-minus');
			});
            
            $('#loophelp').click(function(){ 
                $(this).hide('slow');
                $('#loophelpicon').removeClass('ui-icon-circle-minus');
			});
            
            $('#formathelp').click(function(){ 
                $(this).hide('slow');
                $('#formathelpicon').removeClass('ui-icon-circle-minus');
			});
            
            $('#paramshelp').click(function(){ 
                $(this).hide('slow');
                $('#paramshelpicon').removeClass('ui-icon-circle-minus');
			});
            
            $('#previewhelp').click(function(){ 
                $(this).hide('slow');
                $('#previewhelpicon').removeClass('ui-icon-circle-minus');
			});
	});
// -->