// ALS MEDIA GROUP, LLC. - TWEEMIX
jQuery(function($) {				
$(function() {
  $('.error').hide();
  $(".button").click(function() {
    $('.error').hide();
	  	var songurl = $("input#songurl").val();
		if (songurl == "") {
      		$("label#songurl-error").fadeIn(500);
      		$("input#songurl").focus();
      	return false;
    	}
		var dataString = 'songurl='+ songurl;
		//alert (dataString);return false;
		//$('#tweemix-newurl').slideUp('slow');
		$('#submit').val('TweeMixing...').attr('disabled', 'disabled').css({background: '#0099cc', color: '#f1f1f1', border: '1px solid #0099cc'});	
	$.ajax({
      type: "POST",
      url: "tweemix.php",
      data: dataString,
	  cache: false,
	  error:function(x,e){
			if(x.status==0){
			alert('You are not online\n Please Contact your Network Administrator.');
			}else if(x.status==404){
			alert('Requested URL not found.');
			}else if(x.status==500){
			alert('Internel Server Error.');
			}else if(e=='parsererror'){
			alert('Error.\nParsing JSON Request failed.');
			}else if(e=='timeout'){
			alert('Request Time out.');
			}else {
			alert('Unknow Error.\n'+x.responseText);
			}
		},
      success: function(response) {		
        //$('#tweemix-submiturl').append("<div id='tweemix-newurl'></div>");
        $('#tweemix-newurl').html("<img id='alsmg_preloader' src='assets/images/ajax-loading.gif' /><br><br>")
        $('#tweemix-newurl').append("<span class='alsmg_green-statement'>Shortening your URL...</span>")
        .hide()
        .fadeIn(1111)
		.slideUp('slow', function() {
		  //$('#tweemix-newurl').html("<span class='alsmg_green-statement'>Your TweeMix URL is.</span><p></p>")
		  	$('#tweemix-newurl').html(response).slideDown('slow');
		  	$('#submit').attr('disabled', '').val('TweeMix it!').css({background: '#def0fd', color: '#0099cc', border: '1px solid #e7e7e7', background: '-webkit-gradient(linear, left top, left 25, from(#def0fd), color-stop(4%, #f7f7f7), to(#def0fd))'});
			//$('body').css({background: '#0099cc'});
		  	$("#songurl").val('');
			$('#submit').val('TweeMix it!');
			$('#tweemix-recent').load('tweemix-recent.php');
			// ALS MEDIA GROUP, LLC -> CLIPBOARD CHECK IF ELEMENT EXISTS
			if ($('#link').length > 0) {
				urllink = $('#link').val();
				clip.glue('copy');
				clip.setText(urllink);
				$('#buttons a[rel=tip]').tipsy({delayIn: 500, delayOut: 1000, fade: true, gravity: 's'});// TOOLTIP
			}	
        });
      }
     });
    return false;
	});  
});
});
// ALS MEDIA GROUP, LLC. - CLIPBOARD TWEEMIX LINK
var urllink;
var relink;
ZeroClipboard.setMoviePath('assets/flash/clipboard.swf');
var clip = new ZeroClipboard.Client();
clip.setHandCursor(true);
function changeFormat(type)
{
    type = jQuery.trim(type).toLowerCase();
	switch (type)
	{
		case 'forum':
	    relink = '[URL]' + urllink + '[/URL]';
		break;
		case 'html':
	    relink = '<a href="' + urllink + '" />' + urllink + '</a>';
		break;
	    default:
		relink = urllink;
	}
    $('#link').val(relink);
    clip.setText(relink);
}
// ALS MEDIA GROUP, LLC. - LOAD TWEEMIX LINKS
$(function() {
$('.more').live("click",function() 
{
var tmixID = $(this).attr("id");
if(tmixID)
{
$("#tweemix-more"+tmixID).html('<a class="more"><img src="assets/images/ajax-loading.gif" /></a>');
$.ajax({
type: "POST",
url: "tweemix-load.php",
data: "loadurl="+ tmixID, 
cache: false,
success: function(html){
$("ul#recent").append(html);
$("#tweemix-more"+tmixID).remove();
}
});
}
else
{
$(".more-container").html('<a class="more">Older TweeMix Links are unavailable at this time.</a>');
}
return false;
});
});
// ALS MEDIA GROUP, LLC. - RECENT TWEEMIX LINKS
$(window).ready(function() {
$("ul#recent li:first-child a").animate({ backgroundColor: "#def0fd" }, 500);
$("ul#recent li:first-child a").animate({ backgroundColor: "#f7f7f7"}, 3300);
});
// ALS MEDIA GROUP, LLC. - CHARACTER COUNT
$(document).ready(function() {
$('#counter').html($('#songurl').val().length );
$('#songurl').keyup(function() {
$('#counter').html($(this).val().length );
});
});