	var last_qs = '';
	var last_params;
	var global_params = null;
	var ajax_req = null;
	var reload = false;
	
	var ie6;
	var scrollTop = 0;
	var scrollLeft = 0;

	var mod_qs = '';
	var win_qs = '';
	
	var format_box_ani = false;
	var autocompletes = {};
	var autocomplete_ajax;

	var pages_data = {home:{container:"#page_body"},
					  categories:{container:"#page_container"},
					  search:{container:"#page_container"},
					  profile:{container:"#page_container"},
					  listen:{container:"#page_container"},
					  rating_up:{nohash:true},
					  rating_down:{nohash:true},
					  singer:{container:'#page_container'},
					  polls:{container:'#page_container'},
					  polls_window:{new_modal:true},
					  email_share:{new_modal:true},
					  do_emailshare:{nohash:true,modal_form_submit:true,new_modal: true,confirmation:true},
					  do_pollvote_window:{nohash:true,modal_form_submit:true,new_modal: true,confirmation:true},
					  login:{container:"#menu_holder", nohash:true},
					  logout:{container:"#menu_holder", nohash:true},
					  do_register:{nohash:true,modal_form_submit:true,new_modal: true,confirmation:true},
					  do_editaccount:{nohash:true,modal_form_submit:true,new_modal: true,confirmation:true},
					  do_addsong:{nohash:true,modal_form_submit:true,new_modal: true,confirmation:true},
					  do_contact:{nohash:true,modal_form_submit:true,new_modal: true,confirmation:true},
					  do_pollvote_home:{container:'#polls_home_container',nohash: true},
					  do_feedback:{nohash:true,modal_form_submit:true,new_modal: true,confirmation:true},
					  do_fpass:{nohash:true,modal_form_submit:true,new_modal: true,confirmation:true},
					  do_report:{nohash:true,modal_form_submit:true,new_modal: true,confirmation:true},
					  about:{new_modal:true},
					  contact:{new_modal:true},
					  register:{new_modal:true},
					  tos:{new_modal:true,stack:true},
					  editaccount:{new_modal:true},
					  add_song:{new_modal:true},
					  signin:{new_modal:true},
					  guide:{new_modal:true},
					  advertise:{new_modal:true,init_js:"init_advertise()"},
					  privacy:{new_modal:true,init_js:"init_privacy()"},
					  report:{new_modal:true},
					  feedback:{new_modal:true},
					  forgot_pass:{new_modal:true},
					  do_comment:{container:'#comments_holder',nohash:true},
					  remove_comment:{container:'#comments_holder',nohash:true},
					  comments:{container:'#comments_holder',nohash:true},
					  report_broken_link:{nohash:true},
					  copyright:{new_modal:true,init_js:"init_copyright()"},
					  report_song_description:{nohash:true,modal_form_submit:true,new_modal: true,confirmation:true},
					  report_description:{new_modal:true},
					  download_options:{container:'#box_holder',nohash:true},
						menu_login:{new_modal:true},
						convert:{container:'#hide_overlay', nohash:true},
						get_link:{new_modal:true},
						send_on_mail:{new_modal:true},
						cut_mp3:{container:'#hide_overlay', nohash:true},
						give_options:{container:'#hide_overlay', nohash:true}};
	
//PAGE RENDERER	
	function render_page(page_data) {
		if(page_data.confirmation == true) {
			$('#modal_window_overlay').width($(document).width()).height($(document).height()).css("top",0).css("left",0);
		}
		
		if(page_data.exit) {
      stop_ajax();
			return;
		}
		ajax_req = null;
		
		if(page_data.new_modal == true) {
			if($('.modal_window:visible').length > 0 && page_data.stack == true) {
				var new_modal = $('.modal_window').clone();
				new_modal.find('.modal_inner').html(page_data.content);
				new_modal.hide();
				$('body').append(new_modal);
				new_modal.fadeIn('300', reset_modal_events());
//				$('.modal_select', '.modal_select li a', '.radios_holder a[class^=m_radio_but]', 'a.close_modal, a.mi_close_link').unbind('click');
			} else {
				if($('.modal_window:visible').length > 0) {
					if($('.modal_window:visible').length > 1) {
						$('.modal_window:first').siblings('.modal_window:last').fadeOut('300',function(){$(this).remove();});
						document.location.hash = mod_qs;
						last_qs = mod_qs;
					}
					if(document.location.hash.substr(1) != mod_qs || page_data.confirmation == true) {
						$('.modal_window').fadeOut('300',function(){
							if(page_data.nohash == true) {
								document.location.hash = mod_qs;
								if(document.location.hash.indexOf("/") != -1) {
									var del_qs = document.location.hash.indexOf("/");
								}
								if(del_qs == undefined) { 
									last_qs = document.location.hash.substr(1);
								} else {
									last_qs = document.location.hash.substr(1,del_qs-1);
								}
							} else {
								mod_qs = document.location.hash.substr(1);
							}							
							$('.modal_window').find('.modal_inner').html(page_data.content);
							$('.modal_window:first').fadeIn('300', reset_modal_events());
						});
					}
				} else {
					if(page_data.nohash == true) {
						document.location.hash = win_qs;
						if(document.location.hash.indexOf("/") != -1) {
							var del_qs = document.location.hash.indexOf("/");
						}
						if(del_qs == undefined) { 
							last_qs = document.location.hash.substr(1);
						} else {
							last_qs = document.location.hash.substr(1,del_qs-1);
						}
					} else {
						mod_qs = document.location.hash.substr(1);
					}

					$('.modal_window:first').find('.modal_inner').html(page_data.content);
					$('.modal_window:first').fadeIn('300', reset_modal_events());
				}
			}
						
		} else {
			win_qs = document.location.hash.substr(1);
			$('.modal_window:first').siblings('.modal_window:last').fadeOut('300',function(){$(this).remove();});
			$('.modal_window').fadeOut('300');
			$('#modal_window_overlay').fadeOut('300');
			$(page_data.container).html(page_data.content);
		}
		
		
		if(page_data.init_js) {
			eval(page_data.init_js);
		}
		
		qschange();
		$('#overlay_spinner').hide();
		
		if(typeof(page_data.redirect) == 'string') {
			document.location = page_data.redirect;
		}
	}

	function reset_modal_events() {
			//MODAL EVENTS
			$('.modal_select').unbind('click').each(function(){
				$(this).click(function(e){
					e.stopPropagation();
					$('> ul', this).slideDown();
					$('.modal_select > ul:not(:animated)').each(function(){
						 $(this).fadeOut(300);
					});
				});
			});

			$('.modal_select li a').unbind('click').click(function(e) {
				e.preventDefault();
				e.stopPropagation();
				$(this).parents('ul').fadeOut('300');
				$(this).parents('.modal_select').find('.modal_select_text').html($(this).html());
				$(this).parents('.modal_select').find('select option[text="'+$(this).html()+'"]').attr('selected', true);
			});

			$('.radios_holder a[class^="m_radio_but"]').unbind('click').click(function(e) {
				e.preventDefault();
				$(this).parents('.radios_holder').find('a.m_radio_but_selected').removeClass('m_radio_but_selected').addClass('m_radio_but');
				$(this).addClass('m_radio_but_selected');
				$(this).siblings('input[type="radio"]').attr('checked',true);
			});
			
			$('.m_checkbox a[class^="m_checkbox_but"]').unbind('click').click(function(e) {
				e.preventDefault();
				if($(this).hasClass("m_checkbox_but")) {
					$(this).removeClass("m_checkbox_but").addClass('m_checkbox_but_selected');
					$(this).siblings('input[type="checkbox"]').attr('checked',true);
				} else {
					$(this).removeClass("m_checkbox_but_selected").addClass('m_checkbox_but');
					$(this).siblings('input[type="checkbox"]').attr('checked',false);
				}
			});

			$('a.close_modal, a.mi_close_link').unbind('click').click(function(e) {
				e.preventDefault();
				if($('.modal_window').length > 1) {
					$(this).parents('.modal_window').fadeOut('300',function() { 
						$(this).remove();
						document.location.hash = mod_qs;
						
						if(mod_qs.indexOf("/") != -1) {
							var del_qs = mod_qs.indexOf("/");
						}
						if(del_qs == undefined) {
							last_qs = mod_qs;
						} else {
							last_qs = mod_qs.substr(0,del_qs);
						}
						
						
						qschange();
					});
					var revert = true;
				} else {
					$(this).parents('.modal_window').fadeOut('300');
					$('#modal_window_overlay').fadeOut('300');
					if(win_qs != "") {
						document.location.hash = win_qs;
						last_qs = win_qs;
						var revert = true;
					} else {
						document.location.hash = 'home';
					}
				}

				if(document.location.hash.indexOf("/") != -1) {
					var del_qs = document.location.hash.indexOf("/");
				}
				
				if(revert != undefined) {
					if(del_qs == undefined) { 
						last_qs = document.location.hash.substr(1);
						last_params = '';
					} else {
						last_qs = document.location.hash.substr(1,del_qs-1);
						last_params = document.location.hash.substr(del_qs+1);
					}
				}
				
				qschange();
			});
			
			/*$('.modal_but_bg').mouseover(function(){
				$(this).css('background-image','url("images/modal_but_bg_over.jpg")');
				$(this).siblings('.modal_but_end').css('background-image','url("images/modal_but_end_over.jpg")');
			}).mouseout(function(){
				$(this).css('background-image','url("images/modal_but_bg.jpg")');
				$(this).siblings('.modal_but_end').css('background-image','url("images/modal_but_end.jpg")');
			});*/
			
			rearrange_modals();

			//END MODAL EVENTS
	}
	
// HASH POLLER && DOM READY 
	$(function() {
		window['qs_getter'] = setInterval(function(){
			if(document.location.hash.indexOf("/") != -1) {
				var del_qs = document.location.hash.indexOf("/");
			}
			if(del_qs == undefined) { 
				var qs = document.location.hash.substr(1);
				var params = "";
			} else {
				var qs = document.location.hash.substr(1,del_qs-1);
				var params = document.location.hash.substr(del_qs+1);
			}

			if(qs == "") { 
				qs = "home";
				document.location.hash = "home";
			}
			
			if(qs != last_qs || params != last_params || reload == true) {
				reload = false;
				last_qs = qs;
				last_params = params;

				send_data = {};
				send_data.ajax = true;
				send_data.qs = qs;
				send_data.params = params;
				start_ajax(send_data);
			}
		}, 100);
		
		//SET SEARCH OPTION INIT AND TRIGGERS
		$('#search_options a#search_option_'+$('#search_box').find('select#search_option option:selected').val()).addClass('selected').siblings('a').removeClass('selected');
		$('#search_options a#search_option_'+$('#search_box').find('select#search_av option:selected').val()).addClass('selected').siblings('a').removeClass('selected');

		$('#search_options a').click(function(){
			if(!$(this).hasClass('selected')) {
				$(this).addClass('selected').siblings('a').removeClass('selected');
				$(this).parents('#search_box').find('select option[value="'+$(this).attr("id").substr("search_option_".length)+'"]').attr('selected', true);
			}
		});
		
		$('#ft_search_song, #ft_search_artist').click(function(e){
			window.scroll(0,0);
			$('#search_options a#search_option_'+$(this).attr('id').substr("ft_search_".length)).trigger('click');
			search_box_flasher();
		});
		
		//AJAX OVERLAY CLICK TRIGGER
		$('#modal_window_overlay, #overlay_spinner').click(function(){
                    stop_ajax();
		});
		
		//INIT MODALS
		rearrange_modals();
		
		//PRELOADER
		
		var total_marquee_width = 0;
		$('#marquee_ul').children('li').each(function(){
				total_marquee_width += $(this).width()+20;
			});
		$('#marquee_ul').width(total_marquee_width*2+30);
		$('#marquee_ul').append($('#marquee_ul').html());
		window['marquee_interval'] = setInterval(function(){
			if(parseInt($('#marquee_ul').css("marginRight")) > (parseInt(total_marquee_width)*(-1))) {
				$('#marquee_ul').css("marginRight",parseInt($('#marquee_ul').css("marginRight"))-1);
			} else {
				$('#marquee_ul').css("marginRight",0);
			}
		},50);
		
		$(document).keyup(function(e) {
		if (e.keyCode == 27) { $('.modal_window:visible:last a.close_modal').click(); }
		}).click(function(e){
			$('#error_holder:visible').fadeOut('300');
		});
		
		$('#search_container_left').mouseover(function(){
			$(this).css('background-image','url("images/search_but_over.png")');
		}).mouseout(function(){
			$(this).css('background-image','url("images/search_but.png")');
		});
	});


	function share(network) {
		if(network!=undefined) {
			switch(network) {
				case 'fb':
					u=location.href;
					t=document.title;
					var network_url = 'http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t);
				break;
				case 'twitter':
					var network_url = 'http://twitter.com/home?status='+encodeURIComponent('Currently listening to music on '+location.href);
				break;
			}
			
			window.open(network_url,'sharer','toolbar=0,status=0,width=730,height=436');
		}
	}
	
//SEARCH BOX FLASHER
	function search_box_flasher() {
		var cnt = 0;
		if(window['search_box_flasher_to'] != undefined) {
			window.clearInterval(window['search_box_flasher_to']);
		}
		window['search_box_flasher_to'] = setInterval(function(){
			if($('#search_box').css('background-color') == 'rgb(161, 0, 0)') {
				$('#search_box').css('background-color','#333333');
			} else {
				$('#search_box').css('background-color','#a10000');
			}
			if(cnt == 5) {
				window.clearInterval(window['search_box_flasher_to']);
				$('#search_box').css('background-color','#333333');
			}
			cnt++;
		}, 300);
	}
	
	function start_ajax(send_data) {
		if(pages_data[send_data.qs] == undefined) {
			if($('.modal_window:visible').length == 0) {
			    $('#modal_window_overlay').hide();
			    document.location.hash = win_qs;
			    last_qs = win_qs;
			} else {
			    document.location.hash = mod_qs;
			    last_qs = mod_qs;
			}
			return;
		}

		var over_container = ((pages_data[send_data.qs] != undefined && pages_data[send_data.qs].container != undefined) ? pages_data[send_data.qs].container : document); 
		$('#modal_window_overlay').width($(over_container).width()).height($(over_container).height());
		
		if(typeof(over_container) == 'string') {
			$('#modal_window_overlay').css("top",$(over_container).offset().top).css("left",$(over_container).offset().left);
		} else {
			if(pages_data[send_data.qs] != undefined && pages_data[send_data.qs].modal_form_submit == true) {
				$('.modal_window').each(function(){
					$(this).css('z-index',parseInt($(this).css('z-index'))-100);
				});
			}
			$('#modal_window_overlay').css("top",0).css("left",0);
		}
		
		$('#modal_window_overlay').fadeIn('100', function() {
			$(this).css('filter','alpha(opacity=60)');
			if (send_data.qs != 'convert' && send_data.qs != 'cut_mp3') {
				if(typeof(over_container) == 'string') {
					$('#overlay_spinner').css("top",$('#modal_window_overlay').offset().top+$('#modal_window_overlay').height()/2-$('#overlay_spinner').height()/2).css("left",$('#modal_window_overlay').offset().left+$('#modal_window_overlay').width()/2-$('#overlay_spinner').width()/2).show();
				} else {
					$('#overlay_spinner').css("top",$(window).scrollTop()+$(window).height()/2-$('#overlay_spinner').height()/2).css("left",$(window).scrollLeft()+$(window).width()/2-$('#overlay_spinner').width()/2).show();					
				}
			}

			if(ajax_req) {
				if (navigator.appName != 'Microsoft Internet Explorer') {
					ajax_req.abort();
				}
				ajax_req = null;
			}

			if(pages_data[send_data.qs].nohash == true) {
				
			}
			ajax_req = $.ajax({
			    type: "POST",
			    url: "index.php",
			    data: send_data,
			    success: function(json){
					if(pages_data[send_data.qs] != undefined && pages_data[send_data.qs].modal_form_submit == true) {
						$('.modal_window').each(function(){
							$(this).css('z-index',parseInt($(this).css('z-index'))+100);
						});
					}

					var page_data = $.parseJSON(json);

					if(typeof(pages_data[send_data.qs]) == 'object') {
						for (prop in pages_data[send_data.qs]) {
							if(page_data[prop] == undefined) {
								page_data[prop] = pages_data[send_data.qs][prop];
							}
						}
					}
					
					if(page_data.error) {
						document.location.hash = "home";
						alert(page_data.error);
						return false;
					}
					
					if(page_data.download_options == true) {
						if(page_data.download_error != undefined) {
							$('#error_holder').html(page_data.download_error).fadeIn('300');
						} else if(page_data.options != undefined && typeof(page_data.options) == 'object') {
							//$('#format_select option').remove();
							//$('#down_link').remove();
							$('#progres_bar').hide();
							$('#progres_percent').hide();
							$('#progres_percent').css('width', 0);
							$('#progres_value').text('0%');
							$('#progres_value').hide();
							//$('#option_holder').hide();
							//$('#format_wrapper').show();
							//$('#go_but').show();
							/*for(format in page_data.options) {
								var option = $('<option>').val(page_data.options[format]).html(format);
								$('#format_select').append(option);								
							}*/
							var url;
							for (format in page_data.options) {
								url = page_data.options[format];
							}
							if(url.length > 0) {
								send_data.convert_param = 'MP3';
								send_data.qs = 'convert';
								send_data.ajax = true;
								send_data.url_download = url;
								send_data.type = url.substring(0, 4);
								$('#type').attr('href', send_data.type);
								start_ajax(send_data);
							}							
						}
						
						$('.modal_window').fadeOut('300');
						$('#modal_window_overlay').fadeOut('300');
						$('#overlay_spinner').fadeOut('300');
						
						/*if(page_data.options != undefined && typeof(page_data.options) == 'object' && format_box_ani != true) {
							$('#format_box').animate({
								marginTop: '+=60'
							},1300);
							format_box_ani = true;
						}*/
					} else if (page_data.convert == true) {
						//$('.modal_window').fadeOut('300');
						//$('#modal_window_overlay').fadeOut('300');
						//$('#overlay_spinner').fadeOut('300');
						$('#type').attr('href', page_data.type);
						//$('#format_wrapper').hide();
						//$('#go_but').hide();
						$('#input_boxes').hide();
						$('#progres_box').show();
						$('#progres_bar').show();
						$('#progres_bar').css('display', 'block');
						$('#progres_percent').css('width', 0).show();
						$('#progres_percent').css('display', 'block');
						$('#progres_value').show();
						var t = setTimeout(asd, 1000);
						if (page_data.progres != undefined) {
							$('#progres_percent').css('width', 415*page_data.progres/100);
							$('#progres_value').text(page_data.progres + '%');
							$('#type').attr('href', page_data.type);
						}
					} else if (page_data.finished_convert) {
						$('#progres_percent').css('width', 415);
						$('#progres_value').text('100%');
						$('#progres_bar').hide();
						$('#progres_box').hide();
						$('#flashcontent').show();
						var so = new SWFObject("main_v2.swf", "main_v2", "700", "340", "8", "#000000");
						so.addVariable("maxTime", "");
						so.addVariable("mp3Path", "http://217.23.4.61/ringtonim/temp/" + page_data.filename + "." + page_data.type);
						so.addVariable("sourcePath", "http://217.23.4.61/ringtonim/temp/" + page_data.filename + "." + page_data.type);
						so.addVariable("songartist", "");
						so.addVariable("songtitle", "");
						so.addVariable("songalbum", "");
						so.addVariable("wmode","transparent");
						so.write("flashcontent");
					} else if (page_data.is_cut) {						
						$('#input_boxes').hide();
						$('#options_box').show();
						var down_link = 'http://217.23.4.61/ringtonim/' + page_data.dest;
						$('#down_now').attr('href', down_link);
						send_data.qs = 'give_options';
						send_data.ajax = true;
						document.location.hash = 'options';
						last_qs = 'options';
						start_ajax(send_data);
					} else {
						render_page(page_data);
					}
					return true;
			    }
			});
		});
	}
	
//MODALS REARRANGER
	function rearrange_modals() {
		if(ie6 == true) {
			scrollTop = $(window).scrollTop();
			scrollLeft = $(window).scrollLeft();
		}
		
		$('.modal_window').each(function(){
			$(this).css('top',(scrollTop + ($(window).height()-$(this).height())/2));
			});
		$('.modal_window').each(function(){
			$(this).css('left',(scrollLeft  + ($(window).width()-$(this).width())/2));
			});
	}

//DOCUMENT CLICK EVENT
	$(document).click(function(e) {
		$('.modal_select > ul:not(:animated)').each(function(){
			$(this).fadeOut(300);
		});
		
		$('div [class^=tm_menu_holder]').fadeOut('300');
		$('.autocomplete_holder').fadeOut('300');
	});

//QS CHANGE
	function qschange() {

	}
	
	function submit_search() {
		var src_str = $('#src_str').val();
		var option = $('#search_option').val();
		var av = $('#search_av').val();
		if(src_str != "" && option != "") {
			document.location.hash = '#search/'+encodeURIComponent(encodeURIComponent(src_str))+'/'+option+'/////'+av;
		}

		return false;
	}
	
	function submit_form(form) {
		var send_data = {};
		send_data.ajax = true;
		send_data.qs = $(form).attr('action');
		$(form).find('input[name], textarea[name], select[name]').each(function(){
			var val = null;
			if(this.nodeName.toLowerCase() == 'input') {
				switch($(this).attr('type')) {
					case 'checkbox':
					case 'radio':
						if($(this).attr('checked') == true) val = $(this).val();
					break;
					case 'file':
						
					break;
					default:
						val = $(this).val();
					break;
				}
			} else {
				val = $(this).val();
			}

			if(val != null && val != "") {
			    send_data[$(this).attr('name')] = val;
			}
		});

		start_ajax(send_data);
		
		return false;
	}
        
  function stop_ajax() {
    if(ajax_req != null) {
		ajax_req.abort();
		ajax_req = null;
		send_data = {};
		$('#overlay_spinner').hide();
		if($('.modal_window:visible').length == 0) {
                    $('#modal_window_overlay').hide();
                    document.location.hash = win_qs;
                    last_qs = win_qs;
		} else {
                    document.location.hash = mod_qs;
                    last_qs = mod_qs;
		}
            }
  }
	
	function upload_file(form) {
		var holder = $(form).find('.file_upload_holder');
		if(holder.find('input[type=file]').val() == "") {
			return false;
		}
		holder.siblings('.m_label_holder').find('img').remove();
		var overlay = $('<div>');
		overlay.css('position','absolute').css("opacity","0.5").css("background-color","#000").width(holder.width()).height(holder.height());
		overlay.insertBefore(holder);
		var spinner = $('<img>').attr("src","images/overlay_spinner.gif").attr("alt","spinner");
		spinner.css('position','absolute')
		spinner.insertAfter(overlay).css('margin-top',(overlay.height()-spinner.height())/2);
		var iframe = $('<iframe>');
		iframe.attr("name","upload_iframe").hide().insertAfter($(form));
		window['upload_interval'] = setInterval(function(){
				var response_json = $(form).siblings('iframe[name=upload_iframe]').contents().find('body').html();
				if(response_json != null && response_json != "") {
					response = $.parseJSON(response_json);
					response = $.parseJSON(response.content);
					status_el = $('<img>').addClass("checked_pic");
					if(response.status == "complete") {
						overlay.remove();
						spinner.remove();
						iframe.remove();
						clearInterval(window['upload_interval']);
						status_el.attr("src","images/checked.gif").attr("alt","complete").attr("title",response.msg);
						holder.siblings('.m_label_holder').append(status_el);
					} else if(response.status == "failed") {
						overlay.remove();
						spinner.remove();
						iframe.remove();
						clearInterval(window['upload_interval']);
						status_el.attr("src","images/unchecked.gif").attr("alt","failed").attr("title",response.msg);
						holder.siblings('.m_label_holder').append(status_el);
					}
					if(response.js != undefined) {
						eval(response.js);
					}
				}
		}, 1000);
		
		$(form).submit();
		
		return true;
		
	}
	
	function autocomplete(el, params) {
		if($(el).val() == "") {
			if(autocomplete_ajax != null) autocomplete_ajax.abort();
			autocomplete_ajax = null;
			$(el).siblings('.autocomplete_holder:visible').hide();
			autocompletes[$(el).attr("id")] = "";
		} else if($(el).val() != autocompletes[$(el).attr("id")] ||  autocompletes[$(el).attr("id")] == undefined) {
			var autocomplete_data = {};
			if(params != null) {
				for(i in params) {
					autocomplete_data[i] = params[i];
				}
			}
			if(autocomplete_ajax != null) autocomplete_ajax.abort();
			autocompletes[$(el).attr("id")] = $(el).val();
			autocomplete_data.qs = 'autocomplete';
			autocomplete_data.id = $(el).attr("id");
			autocomplete_data.val = $(el).val();
			autocomplete_ajax = $.ajax({
			    type: "POST",
			    url: "index.php",
			    data: autocomplete_data,
			    success: function(response){

				if(response != "error") {
					$(el).siblings('.autocomplete_holder').find('ul').html(response);
					$(el).siblings('.autocomplete_holder:not(:visible)').show();
					autocomplete_ajax = null;
				} else {
					$(el).siblings('.autocomplete_holder:visible').hide();
					autocomplete_ajax = null;
				}
				return true;
			  }
			});
		}
	}
	
	function download_action() {
		var url = $('#url_input').val();
		var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
		if(!regexp.test(url)) {
		} else {
			send_data.qs = 'download_options';
			send_data.ajax = true;
			send_data.url_input = url;
			if(format_box_ani == true) {
				$('#format_box').animate({
					marginTop: '-=60'
				},1300,function(){start_ajax(send_data);});
				format_box_ani = false;
			} else {
				start_ajax(send_data);
			}
		}
		return false;
	}
	
	function download_rec(url) {
		send_data.qs = 'download_options';
		send_data.ajax = true;
		send_data.url_input = url;
		$('#flashcontent').hide();
		start_ajax(send_data);	
	}

	function hideReferer (url)
	{
		hide_referer = window.open('', 'video_popup', 'width=640,height=480,left='+(screen.width/2-320)+',top='+(screen.height/2-240));
		hide_referer.document.open();
		hide_referer.document.writeln('<html>');
		hide_referer.document.writeln('<head>');
		hide_referer.document.writeln('<meta http-equiv="refresh" content="0;url='+url+'">');
		hide_referer.document.writeln('</head>');
		hide_referer.document.writeln('<body>');
		hide_referer.document.writeln('</body>');
		hide_referer.document.writeln('</html>');
		hide_referer.document.close();
	}

	function download_go() {
		var url = $('#format_select').val();
		if(url.length > 0) {
			var convert_param = $('#format_select option:selected').text();
			send_data.qs = 'convert';
			send_data.ajax = true;
			send_data.url_download = url;
			send_data.type = url.substring(0, 4);
			$('#type').attr('href', send_data.type);
			send_data.convert_param = convert_param;
			start_ajax(send_data);
		}
	}
	
	function asd() {
		send_data.qs = 'convert';
		send_data.ajax = true;
		send_data.convert_param = 'MP3';
		send_data.type = $('#type').attr('href');
		start_ajax(send_data);
	}
	
	function get_link() {
		send_data.qs = 'get_link';
		send_data.ajax = true;
		send_data.link = $('#down_now').attr('href');
		start_ajax(send_data);
	}
	
	function send_on_mail() {
		send_data.qs = 'send_on_mail';
		send_data.ajax = true;
		send_data.link = $('#down_now').attr('href');
		start_ajax(send_data);		
	}
	
	function cut_mp3(start, end, path) {
		send_data = {};
		send_data.qs = 'cut_mp3';
		send_data.ajax = true;
		send_data.startTime = start;
		send_data.endTime = end;
		send_data.sourcePath = path;
		start_ajax(send_data);
	}
	
	/*function get_pct() {
		 $.ajax({
			    type: "POST",
			    url: "index.php",
			    data: send_data,
			    success: function(json){
						alert('a');
						if(pct == 100) {
							return false;
						} else {
							window['download_pct_to'] = setTimeout(get_pct,1000);
						}
					}
		 })
	}*/
	
	function refresh_captcha(el,action) {
		$(el).parent().parent().find('img[alt=security_code]').attr('src','tpl/captcha.php?action='+action+'&refresh_captcha=1&rand='+Math.floor(Math.random()*100000000));
	}
	
	function appletLoaded() {
	}
	
	function getURL(id)
	{
	  document.getElementById('applet').innerHTML = '<applet code="VidownzApplet.class" archive="VidownzApplet1.jar" height="0" width="0" align="center" MAYSCRIPT>\
	  <param name="v" value="' + id + '"/>\
	  <param name="ua" value="Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/9.10 (karmic) Firefox/3.5.3"/>\
	  It appears you do not have Java installed or it is disabled on your system.<br>\
	  You can get Java <a href="http://www.java.com/getjava/" class="link" target="_blank">here</a>.<br><br>\
	  If you are still having difficulty with Java, <a href="http://www.java.com/en/download/help/index_installing.xml" class="link" target="_blank">check here</a> for installing Java, or <a href="http://www.java.com/en/download/help/enable_browser.xml" class="link" target="_blank">here</a> for detailed instructions on enabling Java in your browser.\
		</applet>';
	}
	
	function sendUrl()
	{
		var quality = new Array;
		quality[5] = 'FLV 240p';
		quality[13] = '3GP low';
		quality[17] = '3GP high';
		quality[18] = 'MP4 360p';
		quality[22] = 'MP4 720p';
		quality[34] = 'FLV 360p';
		quality[35] = 'FLV 480p';
		quality[37] = 'MP4 1080p'
		$('#format_select option').remove();
		for (i = 0; i < arguments.length; i = i + 2) {
			var option = $('<option>').val(arguments[i + 1]).html(quality[arguments[i]]);
			$('#format_select').append(option);			
		}		
		if(format_box_ani != true) {
			$('#format_box').animate({
			marginTop: '+=60'
			},1300);
			format_box_ani = true;
		}
	}
	
	function change_to_upload()
	{
		$('#upload_box').hide();
		$('#online_download_box').hide();
		$('#download_box').show();
		$('#upload_file_box').show();
	}
	
	function change_to_download()
	{
		$('#download_box').hide();
		$('#upload_file_box').hide();		
		$('#upload_box').show();
		$('#online_download_box').show();
	}
	
	function LimitAttach(file) {
		if (file) {
		  dots = file.split(".")
		  ext = "." + dots[dots.length-1];
			if (ext == ".mp3" ) {
				ajaxFileUpload();
				return true;
			} else {
				$("#error_holder_2").html("Please Select Only Mp3 Format.").fadeIn('300');
				return false;
			}
		} else {
			$("#error_holder_2").html("Please select a file.").fadeIn('300');
			return false;
		}
	}
	
	function ajaxFileUpload() {
		$("#input_boxes").hide();
		$("#loading_box").show();
		$('#loading').show();
		$.ajaxFileUpload
		(
			{
				url: 'doajaxfileupload.php',
				secureuri: false,
				fileElementId: 'url_input_2',
				dataType: 'json',
				success: function (data, status)
				{
					$('#loading').hide();
					$("#loading_box").hide();
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{							
							if (data.error == 'no_user') {
								$("#input_boxes").show();
								$("#error_holder_2").html(data.error_m).fadeIn('300');
							} else {
								alert(data.error);
							}
						} else {
							var so = new SWFObject("main_v2.swf", "main_v2", "700", "340", "8", "#000000");
							so.addVariable("maxTime", "");
							so.addVariable("mp3Path", "http://217.23.4.61/ringtonim/temp/" + data.randomname);
							so.addVariable("sourcePath", "http://217.23.4.61/ringtonim/temp/"+ data.randomname);
							so.addVariable("songartist", "");
							so.addVariable("songtitle", "");
							so.addVariable("songalbum", "");
							so.addVariable("wmode", "transparent");
							so.write("flashcontent");
							$("#flashcontent").show();
						}
					}
				},
				error: function (data, status, e)
				{
					alert(e);
				}
			}
		);
		return false;
	}
