var currentLibrary = null;
var currentLanguage = null;
var myLibrary = "diner";
var scrolled = true;
var keywordsList='';
var currentPos = -894;
// set development mode. will add "dev" to currentLanguage URLs
var devmode = false;
if (devmode) {
	var devpath = "deva/";
} else {
	var devpath = "";
}
// DOCUMENT READY //
$(document).ready(function () {
	if (window.location.pathname.indexOf("forms") !== -1) {
		currentPos = -1788;
		$('#view-left').html('&laquo; Home').addClass('home').fadeIn();
		ShowForm();
	} else {
		$('#view-left').html('&laquo; Our Reel').removeClass('home').fadeIn();
		$('#view-right').html('Rates & Quotes &raquo;').removeClass('home').fadeIn();
	}
	console.log(currentPos);
	currentLanguage = $.url().param('lang');
	// checks url and sets global variable according to the language
	if (currentLanguage == undefined) {
		if (window.location.host == "lemystro.com" || window.location.host == "www.lemystro.com" || window.location.host == "lemystro.fr" || window.location.host == "www.lemystro.fr") {
			currentLanguage = 1;
		} else if (window.location.host == "ilmystro.com" || window.location.host == "www.ilmystro.com" || window.location.host == "ilmystro.it" || window.location.host == "www.ilmystro.it") {
			currentLanguage = 2;
		} else if (window.location.href == "http://mystromystro.com/portuguese") {
			currentLanguage = 3;
		} else if (window.location.href == "http://www.mystromystro.com/portuguese") {
			currentLanguage = 3;
		} else if (window.location.host == "elmystro.com" || window.location.host == "www.elmystro.com" || window.location.host == "elmystro.es" || window.location.host == "www.elmystro.es") {
			currentLanguage = 4;
		} else if (window.location.host == "herrmystro.com" || window.location.host == "www.herrmystro.com" || window.location.host == "herrmystro.de" || window.location.host == "www.herrmystro.de") {
			currentLanguage = 5;
		} else {
			currentLanguage = 0;
		}
	}
	translateMystro(currentLanguage);
	$('#selected-language').click(function () {
		$('#international-list').fadeToggle('fast');
	});
	// startup - ready for search and fade in the library choices
	$('#filter').focus();
	$('.choose-library').fadeIn();
	$('#international-list li').click(function () {
		var language = $(this).text();
		language = jQuery.trim(language);
		var newlanguage = ($(this).html());
		$('#selected-language').html(newlanguage);
		$('#international-list').fadeOut('fast');
		if (language == "English") {
			window.location = "http://mystromystro.com/" + devpath;
		}
		if (language == "Français") {
			window.location = "http://lemystro.com/" + devpath;
		}
		if (language == "Italiano") {
			window.location = "http://ilmystro.com/" + devpath;
		}
		if (language == "Português") {
			window.location = "http://mystromystro.com/" + devpath + "portuguese";
		}
		if (language == "Español") {
			window.location = "http://elmystro.com/" + devpath;
		}
		if (language == "Deutsch") {
			window.location = "http://herrmystro.com/" + devpath;
		}
	})
	$('#international-list').bind("mouseleave", function () {
		$(this).fadeOut();
	});
	$('.clicktocall').live('click',function () {
		resetClickToCall();
		$.blockUI({
			message: $('#call-form'),
			css: {
				border: 'none',
				padding: '15px',
				width: '500px',
				backgroundColor: '#222',
				'-webkit-border-radius': '5px',
				'-moz-border-radius': '5px',
				opacity: .98,
				color: '#fff',
				cursor: null
			},
			overlayCSS: {
				backgroundColor: '#000',
				opacity: 0.95
			},
		});
		$('.blockUI.blockMsg').center();
		$('.cancel-form').click($.unblockUI);
	})
	// home page logo rollover
	$('.mystro-logo img').hover(

	function () {
		$(this).attr("src", "mystrosearch/images/mystro-icon-RO.png");
	}, function () {
		$(this).attr("src", "mystrosearch/images/mystro-icon.png");
	})
	$('.downloadTC').click(function () {
		$.blockUI({
			message: TRNSLTTermsandConditionsText[currentLanguage],
			css: {
				border: 'none',
				padding: 30,
				width: '400px',
				backgroundColor: '#222',
				background: 'url(mystrosearch/images/tactile_noise.gif) repeat',
				'-webkit-border-radius': '3px',
				'-moz-border-radius': '3px',
				opacity: 1,
				color: '#fff',
				cursor: null,
			},
			overlayCSS: {
				backgroundColor: '#000',
				opacity: 0.95
			},
		});
		$('.blockUI.blockMsg').center(); /* 	$('.blockOverlay').attr('title','Click to unblock').click($.unblockUI); */
	})
	$('.get-mystro-button').click(function () { /* 	$('#registration').resetForm(); */
		$.blockUI({
			message: $('#mystro-form'),
			css: {
				border: 'none',
				padding: '15px',
				width: '500px',
				backgroundColor: '#222',
				'-webkit-border-radius': '5px',
				'-moz-border-radius': '5px',
				opacity: .98,
				color: '#fff',
				cursor: null,
				background: 'url(../mystrosearch/images/tactile_noise.gif) repeat',
			},
			overlayCSS: {
				backgroundColor: '#000',
				opacity: 0.95
			},
		});
		$('.blockUI.blockMsg').center();
		$('.cancel-form').click($.unblockUI);
	});
	// fades in choose library options
	$("#filter").focus(function () {
		$('.choose-library').fadeIn();
		return false;
	});
	// getURL button
	$('.getURL-button').click(function () {
		$('.showURL').fadeIn();
		if ($('.choose-musicplayground').hasClass('selected')) {
			var searchLibrary = "/2";
		} else {
			searchLibrary = ""
		}
		var searchableURL = "http://" + $.url().attr('host') + "/#/" + $('#filter').val().replace(/ /gi, '-') + searchLibrary;
		$('#theurl').val(searchableURL).focus().select();
	})
	//getURL close button
	$('.close-button').live('click', function () {
		$('#theurl').val('');
		$('.showURL').hide();
	})
	//////////////////////
	////// TRANSPORT /////
	//////////////////////
	$('.transport .previous').live('click', function () {
		pagePlayer.playPrevious();
	})
	$('.transport .pause').live('click', function () {
		pagePlayer.lastSound.togglePause();
	})
	$('.transport .play').live('click', function () {
		pagePlayer.lastSound.togglePause();
	})
	$('.transport .next').live('click', function () {
		pagePlayer.playNext();
	});
	//////////////////////
	///// KEYCOMANDS /////
	//////////////////////
	// Option-click to replace search field with whatever was clicked
	// Right/Left arrows for next/previous tracks
	$(document).keydown(function (e) {
		if (e.which == 39) {
			pagePlayer.playNext();
		}
		if (e.which == 37) {
			pagePlayer.playPrevious();
		} /*   if (e.which == 32) {pagePlayer.lastSound.togglePause();}  */
	});
	var optionPressed = false;
	$(window).keydown(function (evt) {
		if (evt.which == 18) {
			optionPressed = true;
		}
	}).keyup(function (evt) {
		if (evt.which == 18) {
			optionPressed = false;
		}
	});
	//If cursor is in the search field, enter key starts search
	$('#filter').bind('keypress', function (e) {
		if (e.keyCode == 13) {
			myLibrary = "diner";
			$('.choose-diner').addClass('selected');
			$('.choose-musicplayground').removeClass('selected');
			sendValue($('#filter').val());
			$('#filter').blur();
		}
	});
	////////////////////////
	////// SEARCH BAR //////
	////////////////////////
	$('.category').live('click', function () {
		myLibrary="diner";
		//Checks for option button
		if (optionPressed) {
			$('#filter').val($(this).html().replace(/&nbsp;/gi, ' ').replace(/&amp;/gi, '&'));
			sendValue($('#filter').val());
		} else {
			$('#filter').val($('#filter').val() + ' ' + ($(this).html()).replace(/&nbsp;/gi, ' ').replace(/&amp;/gi, '&'));
			sendValue($('#filter').val());
		}
	});
	// Main category used to automatically replace the entire search field
	$('.image-category').live('click', function () {
		var imgclick = $(this).parent().next('li').find('a.main-category').html();
		$('.related-albums').html('');
		myLibrary = "diner";
		$('.choose-diner').addClass('selected');
		$('.choose-musicplayground').removeClass('selected');
		$('#filter').val(imgclick);
		sendValue($('#filter').val());
	});
	$('.main-category').live('click', function () {
		console.log('search '+$(this).html());
		$('#filter').val($(this).html());
		$('.related-albums').html('');
		myLibrary = "diner";
		$('.choose-diner').addClass('selected');
		$('.choose-musicplayground').removeClass('selected');
		console.log($('#filter').val());
		sendValue($('#filter').val());
	});
	////////////////////////////////
	///// CHOOSE LIBRARY BUTTONS ///
	////////////////////////////////
	$('.choose-diner').click(function () {
		myLibrary = "diner";
		$(this).addClass('selected');
		$('.choose-musicplayground').removeClass('selected');
		// If search bar isn't empty, search
		if ($('#filter').val() != '') {
			sendValue($('#filter').val());
		}
	})
	$('.choose-musicplayground').click(function () {
		browseAllAlbums();
	})
	var browseAllAlbums = function () {
			$('#song-list').html('');
			$('#filter').val('');
			myLibrary = "browseAll";
			$(this).addClass('selected');
			$('.choose-diner').removeClass('selected');
			sendValue('all albums', true);
		}
	$('.search-button').click(function () {
		myLibrary = "diner";
		$(this).addClass('selected');
		$('.choose-musicplayground').removeClass('selected');
		sendValue($('#filter').val());
	});
	// Clear search bar, search for nothing
	$('.clear-search').click(function () {
		$('.getURL-button').fadeOut();
		$('#filter').val('');
		$('.choose-library').fadeOut();
		$('.related-albums').fadeOut();
		$('.now-playing-wrapper').fadeOut();
		$('.transport').fadeOut();
		soundManager.stopAll();
		$('#song-list').text('')
	})
	// URL Parser
	if ($.url().param('q')) {
		var myURLQuery = $.url().param('q').replace(/-/gi, ' ');
	}
	if ($.url().fsegment(1)) {
		var recID = $.url().fsegment(1);
	}
	if (myURLQuery) {
		soundManager.autoPlay = false;
		$('.related-albums').removeClass('full-screen');
		$('#filter').val(myURLQuery);
		$('.choose-diner').addClass('selected');
		$('.choose-musicplayground').removeClass('selected');
		sendValue($('#filter').val());
		myLibrary = "diner";
	} else if (recID) {
		myLibrary = "track";
		sendValue(recID);
		// 	myLibrary = "diner";
	} else {
		soundManager.autoPlay = false;
		browseAllAlbums();
	}
	//stick the footer at the bottom of the page if we're on an iPad/iPhone due to viewport/page bugs in mobile webkit
	if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
		$("#footer").css("position", "static");
	};
	// terms and conditions popup
	$('.terms-conditions').click(function () {
		$.blockUI({
			message: TRNSLTTermsandConditionsText[currentLanguage],
			css: {
				border: 'none',
				padding: 30,
				width: '400px',
				backgroundColor: '#222',
				background: 'url(mystrosearch/images/tactile_noise.gif) repeat',
				'-webkit-border-radius': '5px',
				'-moz-border-radius': '5px',
				opacity: 1,
				color: '#fff',
				cursor: null,
			},
			overlayCSS: {
				backgroundColor: '#000',
				opacity: 0.95
			},
		});
		$('.blockUI.blockMsg').center();
		$('.blockOverlay').attr('title', 'Click to unblock').click($.unblockUI);
	});
	$('a.blockui-close').live('click', function () {
		$.unblockUI();
	})
	//validate forms

/*
	$("#registration").validate({
		rules: {
			email: {
				required: true,
				email: true
			},
			email_again: {
				equalTo: "#email"
			},
			name: {
				required: true
			},
			company: {
				required: true
			},
			phone: {
				required: true,
				phoneUS: true
			}
		}
	});
*/

	$("#call-form").validate();
	// google voice
	$('[placeholder]').focus(function () {
		var input = $(this);
		if (input.val() == input.attr('placeholder')) {
			input.val('');
			input.removeClass('placeholder');
		}
	}).blur(function () {
		var input = $(this);
		if (input.val() == '' || input.val() == input.attr('placeholder')) {
			input.addClass('placeholder');
			input.val(input.attr('placeholder'));
		}
	}).blur();
	$('[placeholder]').parents('form').submit(function () {
		$(this).find('[placeholder]').each(function () {
			var input = $(this);
			if (input.val() == input.attr('placeholder')) {
				input.val('');
			}
		})
	});
	//call button script
	$('#call-submit').click(function () {
		$('#callme-form').validate();
		if ($('#callme-form').valid()) {
			var name = $("input#nameEdit").val();
			var phone = $("input#phoneNum").val();
			var dataString = 'name=' + name + '&phoneNum=' + phone;
			$("#call-submit").html(TRNSLTCallUsProcessing[currentLanguage]).css("background-color", "#ffb60f").fadeIn(100); /* $("#call-submit").delay(1500).fadeOut(1500); */
			$.ajax({
				type: "POST",
				url: "gvoice.php",
				data: dataString,
				success: function (returnData) {
					$("#call-submit").html(TRNSLTCallUsCalling[currentLanguage]).css("background-color", "#33FF00").fadeIn('slow');
					$("#call-submit").delay(3000).fadeOut(1500);
					var t = setTimeout("$.unblockUI()", 4500);
				}
			});
		};
	});
	// end google voice
	$('.share-button').live('click', function () {
		$(this).next('.display-url').hide(); /* 	var thisLib = ""; */
		var thisURL = "http://" + window.location.hostname;
		var thisSong = $(this).parent().find('a').attr('rel');
		var thisTitle = $(this).next().next('.song-details').find('.track').text().replace(/‑/gi, '-');
		var thisArtist = $(this).next().next('.song-details').find('.artist').text();
		fullLink = thisURL + "/" + devpath + "#" + thisSong;
		fullLink = fullLink.replace(/#/gi, '%23')
		$(this).next('.social-buttons').find('.share-twitter').attr('href', "http://twitter.com/?status=Check out " + thisTitle + " on The Diner! " + fullLink + " (via @dinermusic)");
		$(this).next('.social-buttons').find('.share-facebook').attr('href', "http://www.facebook.com/sharer.php?u=" + fullLink + "&t=Check out this song on The Diner: " + thisSong);
		$(this).next('.social-buttons').find('.share-email').attr('href', "mailto:?subject=Check out " + thisTitle + " on The Diner: " + thisSong + "&body=Check out " + thisTitle + " on The Diner: " + fullLink);
		$('.social-buttons .get-url').live('click', function () {
			thisURLLink = fullLink.replace("%23", "#");
			$(this).next('.display-url').val(thisURLLink);
			$(this).next('.display-url').show();
			$(this).next(".display-url").focus().select();
		})
		$(this).next('.social-buttons').show();
	});
	$('.download-button').live('click', function () {
		var d = $(this).prev('a').text();
		window.location = 'http://search.thedinermusic.com/login';
		_gaq.push(['_trackEvent', 'Download', 'Download Track', d]);
	});
	$('.social-buttons .share-twitter').live('click', function () {
		var d = $(this).parent().parent().find('.sm2_link').text();
		_gaq.push(['_trackEvent', 'Share', 'Twitter', d]);
	});
	$('.social-buttons .share-facebook').live('click', function () {
		var d = $(this).parent().parent().find('.sm2_link').text();
		_gaq.push(['_trackEvent', 'Share', 'Facebook', d]);
	});
	$('.social-buttons .share-email').live('click', function () {
		var d = $(this).parent().parent().find('.sm2_link').text();
		_gaq.push(['_trackEvent', 'Share', 'Email', d]);
	});
	$('.social-buttons .get-url').live('click', function () {
		var d = $(this).parent().parent().find('.sm2_link').text();
		_gaq.push(['_trackEvent', 'Share', 'Permalink', d]);
	});
	$('.share-button').live('mouseleave', function () {
		$('textarea.display-url').val('');
		$('textarea.display-url').hide();
		$(this).next('.social-buttons').fadeOut();
	});
	$('.social-buttons').live('mouseenter', function () {
		$(this).stop().animate({
			opacity: 100
		}, 1000);
	});
	$('.social-buttons').live('mouseleave', function () {
		$('textarea.display-url').val('');
		$('textarea.display-url').hide();
		$(this).fadeOut();
	});
	$('div#view-left').click(function () {
		ChangeBG('left');
	});
	$('div#view-right').click(function () {
		ChangeBG('right');
	});

	$("input[name=type]").change(function() {
		console.log("change");
		
		if ($("input[@name=type]:checked").attr("id") == "advertising") {

			$("#form-advertising").find("input#advert-post-no").attr("checked","checked");
			$("#form-advertising").show();
			$("#form-filmtv").hide();
/*
				$("#registration").validate({
					rules: {
						email: {
							required: true,
							email: true
						},
						email_again: {
							equalTo: "#email"
						},
						name: {
							required: true
						},
						company: {
							required: true
						},
						phone: {
							required: true,
							phoneUS: true
						},
						"advert-client": {
							required: true
						},
						"advert-product": {
							required: true
						},
						"advert-titles": {
							required: true
						},
						"advert-length": {
							required: true
						},
						"advert-numtracks": {
							required: true
						},
						"advert-territories": {
							required: true
						},
						"advert-media": {
							required: true
						},
						"advert-airdate": {
							required: true
						},
						"advert-duration": {
							required: true
						},
						"advert-direction": {
							required: true
						}					}
				});
*/

		} else if ($("input[@name=type]:checked").attr("id") == "filmtv") {

			$("#form-filmtv").find("input#filmtv-post-no").attr("checked","checked");
			$("#form-filmtv").show();
			$("#form-advertising").hide();
/*
				$("#registration").validate({
					rules: {
						email: {
							required: true,
							email: true
						},
						email_again: {
							equalTo: "#email"
						},
						name: {
							required: true
						},
						company: {
							required: true
						},
						phone: {
							required: true,
							phoneUS: true
						},
						"filmtv-client": {
							required: true
						},
						"filmtv-titles": {
							required: true
						},
						"filmtv-length": {
							required: true
						},
						"filmtv-numtracks": {
							required: true
						},
						"filmtv-territories": {
							required: true
						},
						"filmtv-media": {
							required: true
						},
						"filmtv-airdate": {
							required: true
						},
						"filmtv-duration": {
							required: true
						},
						"filmtv-direction": {
							required: true
						},
						"filmtv-description": {
							required: true
						}
					}
				});
*/

		}
		
		$("a#request-form-submit").show();
	});
	
	$("#request-form-submit").click(function() {
/* 		if ($('#registration').valid()) { */
		
			if($("input[@name=type]:checked").attr("id") == "advertising") {
			
				dataObj = $("div#form-advertising");
		
			} else if ($("input[@name=type]:checked").attr("id") == "filmtv") {
			
				dataObj = $("div#form-filmtv");
					
			}
			
			jsonObj = new Object();
			jsonObj.email = checkChars(CleanWordHTML($("input#email").val()));
			jsonObj.name = checkChars(CleanWordHTML($("input#name").val()));
			jsonObj.company = checkChars(CleanWordHTML($("input#company").val()));
			console.log(jsonObj.company);
			jsonObj.phone = checkChars(CleanWordHTML($("input#phone").val()));
			jsonObj.type = checkChars(CleanWordHTML($("input[name=type]:checked").val()));
		
			$.each(dataObj.children(), function(index, value) {
					if($(value).is("input") || $(value).is("textarea") || $(value).is("select")) {
						$(value).val($(value).val().replace(/\n\r/g, ', '));
						$(value).val($(value).val().replace(/\r/g, ', '));
						$(value).val($(value).val().replace(/\n/g, ', '));
						console.log($(value).attr('id') + ': "' + $(value).val() + '",');
						if ($(value).attr('name')=='tags') {
							if($(value).attr('checked')) {
								jsonObj['tags'] = "yes";
							} else {
								jsonObj['tags'] = "no";
							}
						} else {
							jsonObj[$(value).attr('id')] = checkChars(CleanWordHTML($(value).val()));
						}
	
					} else if ($(value).hasClass('audio-post')) {
						jsonObj['post'] = dataObj.find("input[name=post]:checked").val();
					}
	
			});
/* 			jsonString = $.toJSON(jsonObj); */
			jsonString = JSON.stringify(jsonObj);
			console.log(jsonString);
	
		
			$.ajax({
				type: "POST",
				url: "php-includes/test_smtp2.php",
				data: "data="+jsonString,
				success: function(retData){
					console.log(retData);
					if(retData == "success=1") {
						$('.message').remove();
						$('#view-forms').prepend('<p class="message success">Your request has been sent!  We will be in touch shortly.</p>');
					} else {
						$('.message').remove();
						$('#view-forms').prepend('<p class="message failure">There was an error with your request. Please call, chat, or email us for help!<br/>'+retData+'</p>');
					}
					dataObj.hide();
					$("a#request-form-submit").hide();
					$('html, body').animate({
						scrollTop: 0
					}, 0);
				}
			});
				
			return false;
/*
		} else {
			$('.message').remove();
			$('#view-forms').prepend('<p class="message failure">You are missing one or more required fields.  Please check below and try again!</p>');
			$('html, body').animate({
				scrollTop: 0
			}, 0);
		}
*/
	});
	
	console.log(window.location.search);
	
	$("input, textarea").keyup(function(event){
		if (event.which == "222" && event.shiftKey == true ) {
			$(this).val($(this).val().replace('"','\''));
		}
		if (event.which == "55" && event.shiftKey == true ) {
			$(this).val($(this).val().replace('&','and'));
		}
		if (event.which == "220") {
			$(this).val($(this).val().replace('\\','/'));
		}
	});
/*
	if (window.location.search == "?s=form") {
		ShowForm();
	}
*/


}); // END DOC READY

// if window is scrolls far, add class to now-playing
if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {} else {
	$(window).scroll(function () {
		var scrollAmount = $(window).scrollTop();
		var docheight = $(document).height();
		console.log(docheight);
		if (scrollAmount > 650 && docheight > 1800) {
			$('.now-playing-wrapper').addClass('stuck');
			$('.transport').addClass('stuck');
		} else {
			$('.now-playing-wrapper').removeClass('stuck');
			$('.transport').removeClass('stuck');
		}
	});
}

function sendValue(str, load) {
	if (!load) {
		scrolled = false;
	}
	if (myLibrary == 'diner' || myLibrary == "track") {
		$('.related-albums').removeClass('full-screen');
		_gaq.push(['_trackEvent', 'Search', 'Search bar search', str]);
	} else {
		soundManager.stopAll();
		$('.related-albums').addClass('full-screen');
		$('.now-playing-wrapper').fadeOut();
		$('.transport').fadeOut();
		_gaq.push(['_trackEvent', 'Browse', 'Browse Albums', 'Show Browse Albums']);
	}
	$('.choose-library').fadeIn();
	$.blockUI({
		message: '<img src="mystrosearch/images/ajax-spinner.gif">',
		css: {
			border: 'none',
			width: '100px',
			padding: '25px',
			backgroundColor: '#000',
			'-webkit-border-radius': '5px',
			'-moz-border-radius': '5px',
			opacity: .8,
			color: '#fff'
		},
		overlayCSS: {
			backgroundColor: '#000',
			opacity: 0.8
		},
	});
	$('.blockUI.blockMsg').center();
	$.post("mystrosearch/js/ajax-search.php", {
	    sendToValue: str,
	    language: currentLanguage,
	    library: myLibrary
	}, function(data) {
	    $('#song-list').html(data.returnFromValues);
	    if (myLibrary == "track") {
	       setUpSinglePage();
	    }else{
	    $('.searchingfor').html('');
	    }
	    if (data.returnFromValues == '') {
	        soundManager.stopAll();
	        $('#song-list').html('<div class="no-results"><h2>Zero search results!</h2><p>Can\'t find what you\'re looking for? We\'d be happy to help!<br>Call The Diner at 212-727-2959, email us at <a href="mailto:info@thedinermusic.com">info@thedinermusic.com</a>, <a href="javascript:;" onClick="window.open(\'http://www.google.com/talk/service/badge/Start?tk=z01q6amlq025086fts6sjkah1at7s456g88kht51rhir53ijaubp16rj49ai2qovp8btq2rtu5q0rokk03i14mlu4lk44bcdfpqv3s4vm24nnldsk7kbvug2injn0rppmd26jdiukbp33e3te8amb39dhl47v67rnsrplfo4oi2ha9op5j2spkpsu3ahmiio1io\',\'myWin\',\'scrollbars=yes,width=500,height=500\');" id="TRNSLTChatLive">Chat Live</a>, or <a name="clicktocall" class="clicktocall">Click to Call</a>.</p></div>');
	        $('.related-albums').fadeOut();
	        $('.now-playing-wrapper').fadeOut();
	        $('.transport').fadeOut();
	    } else {
	        $('.related-albums').html(data.returnCategories);
	        $('.related-albums').fadeIn('fast');
	    }
	    $.unblockUI();
	    if (!scrolled) {
	        $.scrollTo('.filter-section', 800, {
	            easing: 'easeOutQuad'
	        });
	    };
	    scrolled = true;

	}, "json");


	$('.getURL-button').fadeIn();
	}

// center blockui
$.fn.center = function () {
	this.css("position", "absolute");
	this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
	this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");
	return this;
}
// translate the page based on the lang variable in the url

function translateMystro(cl) {
	$('#trnslt-download-button').html(TRNSLTDownloadMystro[cl]);
	$('#selected-language').html(TRNSLTFlagChoice[cl]); /* 	$('#TRNSLTSearchMystro').html(TRNSLTSearchMystro[cl]); */
	$('#TRNSLTExamples').html(TRNSLTExamples[cl]); /* 	$('#TRNSLTSearchButton').html(TRNSLTSearchButton[cl]); */
	$('#TRNSLTChooseLibrary').html(TRNSLTChooseLibrary[cl]);
	$('#TRNSLTNowPlaying').html(TRNSLTNowPlaying[cl]);
	$('#TRNSLTChatLive').html(TRNSLTChatLive[cl]);
	$('#TRNSLTClickToCall').html(TRNSLTClickToCall[cl]);
	$('#TRNSLTRecordMessage').html(TRNSLTRecordMessage[cl]);
	$('#TRNSLTPhoneNumber').html(TRNSLTPhoneNumber[cl]);
	$('#TRNSLTRequestQuote').html(TRNSLTRequestQuote[cl]);
	$('#TRNSLTDownloadFormHeader').html(TRNSLTDownloadForm[cl][0]);
	$('#TRNSLTDownloadFormEmail').html(TRNSLTDownloadForm[cl][1]);
	$('#TRNSLTDownloadFormVerifyEmail').html(TRNSLTDownloadForm[cl][2]);
	$('#TRNSLTDownloadFormFirst').html(TRNSLTDownloadForm[cl][3]);
	$('#TRNSLTDownloadFormLast').html(TRNSLTDownloadForm[cl][4]);
	$('#TRNSLTDownloadFormCompany').html(TRNSLTDownloadForm[cl][5]);
	$('#TRNSLTDownloadFormTitle').html(TRNSLTDownloadForm[cl][6]);
	$('#TRNSLTDownloadFormEditor').html(TRNSLTDownloadForm[cl][7]);
	$('#TRNSLTDownloadFormMusicProducer').html(TRNSLTDownloadForm[cl][8]);
	$('#TRNSLTDownloadFormMusicSupervisor').html(TRNSLTDownloadForm[cl][9]);
	$('#TRNSLTDownloadFormProducer').html(TRNSLTDownloadForm[cl][10]);
	$('#TRNSLTDownloadFormCreativeDirector').html(TRNSLTDownloadForm[cl][11]);
	$('#TRNSLTDownloadFormDirector').html(TRNSLTDownloadForm[cl][12]);
	$('#TRNSLTDownloadFormSignup').html(TRNSLTDownloadForm[cl][13]);
	$('#TRNSLTDownloadFormAgreeToTC').html(TRNSLTDownloadForm[cl][14]);
	$('#registration-submit').html(TRNSLTDownloadForm[cl][15]);
	$('#TRNSLTDownloadFormCancel').html(TRNSLTDownloadForm[cl][16]);
	$('#TRNSLTTermsandConditionsButton').html(TRNSLTTermsandConditionsButton[cl]);
	$('#TRNSLTCallUsName').html(TRNSLTCallUsName[cl]);
	$('#TRNSLTCallUsNumber').html(TRNSLTCallUsNumber[cl]);
	$('#call-submit').html(TRNSLTCallUsSubmit[cl]);
	$('#TRNSLTCallUsCancel').html(TRNSLTCallUsCancel[cl]);
	$('#TRNSLTFeedbackbutton').html(TRNSLTFeedbackbutton[cl]);
}

function CloseForm() { /* 	document.getElementById('view-forms').style.display = 'none'; */
	$("#view-forms").hide();
	console.log("form-close");
}

function ShowForm() {
/* 	document.getElementById('view-forms').innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + 'width="550" height="580"' + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22">' + '<param name="movie" value="diner_forms_03222011.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" />' + '<embed src="diner_forms_03222011.swf" quality="high" wmode="transparent" ' + 'width="550" height="580" name="detectiontest" aligh="middle"' + 'play="true"' + 'loop="false"' + 'quality="high"' + 'allowScriptAccess="sameDomain"' + 'type="application/x-shockwave-flash"' + 'pluginspage="http://www.macromedia.com/go/getflashplayer">' + '<\/embed>' + '<\/object>'; */
/* 	document.getElementById('view-forms').style.display = 'block'; */
	$('#view-forms').show();
}

function ChangeBG(dir) {
	var xChange = 0;
	if (dir == "left") {
		xChange = 894;
	} else if (dir == "right") {
		xChange = -894;
	}
	t1 = new Tween(document.getElementById('view-content').style, 'backgroundPosition', Tween.regularEaseIn, currentPos, currentPos + xChange, .5, 'px');
	t2 = new Tween(document.getElementById('wrap-bottom').style, 'backgroundPosition', Tween.regularEaseIn, currentPos, currentPos + xChange, .5, 'px');
	if ((currentPos + xChange) > 0 || (currentPos + xChange) < -1788) {
		window.location = "http://search.thedinermusic.com";
	} else {
		currentPos += xChange;
		t1.onMotionStarted = function () {
			if (currentPos == -1788) {
				$('#view-player').hide();
				$('#view-ratequote').hide();
				$('#view-ratecard').hide();
				$('#container').hide();
				soundManager.pauseAll();
				CloseForm();
			} else if (currentPos == 0) {
				$('#view-player').hide();
				$('#view-ratequote').hide();
				$('#view-ratecard').hide();
				$('#container').hide();
				soundManager.pauseAll();
				CloseForm();
			} else if (currentPos == -894) {
				$('#view-player').hide();
				$('#view-ratequote').hide();
				$('#view-ratecard').hide();
				$('#container').hide();
				soundManager.pauseAll();
				CloseForm();
			}
		}
		t1.onMotionFinished = function () {
			console.log(currentPos + " AND hello");
			if (currentPos == 0) {
				resetHeader();
				$('#view-player').html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="547" height="580" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22"><param name="movie" value="diner_flashPlayer_07122010.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="diner_flashPlayer_07122010.swf" quality="high" wmode="transparent" width="547" height="580" name="detectiontest" aligh="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <\/embed><\/object>');
				$('#view-player').show();
				$('#view-right').html('Home &raquo;').addClass('home').fadeIn();
				$('#view-left').removeClass('home').hide();
				$('#container').hide();
			} else if (currentPos == -1788) {
				resetHeader();
				$('#view-right').removeClass('home').hide();
				$('#view-left').html('&laquo; Home').addClass('home').fadeIn();
				$('#view-ratequote').show();
				$('#view-ratecard').show();
				$('#container').hide();
				ShowForm();
				_gaq.push(['_trackEvent', 'Form', 'Navigate to form']);
			} else if (currentPos == -894) {
				resetHeader();
				$('#view-player').hide();
				$('#view-ratequote').hide();
				$('#view-ratecard').hide();
				$('#view-right').html('Rates & Quotes &raquo;').removeClass('home').fadeIn();
				$('#view-left').html('&laquo; Our Reel').removeClass('home').fadeIn();
				$('#container').show();
			}
		}
		t1.start();
		t2.start();
	}
	var resetHeader = function () {
			$('#view-phone').html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="270" height="50" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22"><param name="movie" value="gvoice_small.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="gvoice_small.swf" quality="high" wmode="transparent" width="270" height="50" name="detectiontest" aligh="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><\/embed><\/object>');
			$('#view-phone').show();
			$('#view-chat').show();
			$('#view-email').show();
			$('#view-contact').show();
		}
}

var setUpSinglePage = function(){
	var whatsplaying = $('#song-list li .song-details').html();
	$('.now-playing').html(whatsplaying);
	$('.transport .playpause').addClass('pause').removeClass('play');
	$('.transport').hide();
	$('.now-playing-wrapper h2').hide();
	$('.now-playing-wrapper').show();
	randWords();
	$('.searchingfor').html('You also may have been searching for: <i>stock music</i>, <i>production music</i>, <i>music library</i>, <i>music licensing</i>, '+keywordsList);
}

var randWords = function() {
    var inArray = null;
    var tempArray = [];
    keywordsList='';
    for (var i = 0; i < 10; i++) {
        var randomNumber = $.randomBetween(0, keywordsArray.length);
        inArray = ($.inArray(randomNumber, tempArray));
        if (inArray < 0) {
            tempArray.push(randomNumber);
        } else {
            i--;
        }
    }
    $.each(tempArray, function(index, value) {
    	keywordsList = keywordsList + '<i>'+keywordsArray[value]+'</i>, ';
    });

}

var resetClickToCall = function(){
	$("#call-submit").html('Call Us').css("background-color", "#399b08").show();
}

function checkChars(s) {
	return s;
}

function CleanWordHTML( str )
{
str = str.replace(/<o:p>\s*<\/o:p>/g, "") ;
str = str.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;
str = str.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;
str = str.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;
str = str.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;
str = str.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;
str = str.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;
str = str.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;
str = str.replace( /\s*tab-stops:[^;"]*;?/gi, "" ) ;
str = str.replace( /\s*tab-stops:[^"]*/gi, "" ) ;
str = str.replace( /\s*face="[^"]*"/gi, "" ) ;
str = str.replace( /\s*face=[^ >]*/gi, "" ) ;
str = str.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, "" ) ;
str = str.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
str = str.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
str = str.replace( /\s*style="\s*"/gi, '' ) ; 
str = str.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ; 
str = str.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ; 
str = str.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ; 
str = str.replace( /<SPAN\s*>(.*?)<\/SPAN>/gi, '$1' ) ; 
str = str.replace( /<FONT\s*>(.*?)<\/FONT>/gi, '$1' ) ;
str = str.replace(/<\\?\?xml[^>]*>/gi, "") ; 
str = str.replace(/<\/?\w+:[^>]*>/gi, "") ; 
str = str.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;
str = str.replace( /<H1([^>]*)>/gi, '' ) ;
str = str.replace( /<H2([^>]*)>/gi, '' ) ;
str = str.replace( /<H3([^>]*)>/gi, '' ) ;
str = str.replace( /<H4([^>]*)>/gi, '' ) ;
str = str.replace( /<H5([^>]*)>/gi, '' ) ;
str = str.replace( /<H6([^>]*)>/gi, '' ) ;
str = str.replace( /<\/H\d>/gi, '<br>' ) ; //remove this to take out breaks where Heading tags were 
str = str.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;
str = str.replace( /<(B|b)>&nbsp;<\/\b|B>/g, '' ) ;
str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
str = str.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
//some RegEx code for the picky browsers
var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;
str = str.replace( re, "<div$2</div>" ) ;
var re2 = new RegExp("(<font|<FONT)([^*>]*>.*?)(<\/FONT>|<\/font>)","gi") ; 
str = str.replace( re2, "<div$2</div>") ;
str = str.replace( /size|SIZE = ([\d]{1})/g, '' ) ;
str = str.replace(/\&/g, 'and');
str = str.replace(/\\/g, '/');
str = str.replace(/\"/g, "'");
str = str.replace(new RegExp("&ldquo;", "g"), "'");
str = str.replace(new RegExp("&rdquo;", "g"), "'");
str = str.replace(new RegExp(String.fromCharCode(8220), "g"), "'");
str = str.replace(new RegExp(String.fromCharCode(8221), "g"), "'");
str = str.replace(new RegExp("&lsquo;", "g"), "'");
str = str.replace(new RegExp("&rsquo;", "g"), "'");
str = str.replace(new RegExp(String.fromCharCode(8216), "g"), "'");
str = str.replace(new RegExp(String.fromCharCode(8217), "g"), "'");
return str ;
}

var keywordsArray = ["corporate training video","production library","video production music","commercial music","buy out music","sound effects library","corporate training videos","production music","stock music","music bed","music production","buyout music","film music","license music","website background music","music for film","music production library","corporate video production services","corporate video production","music supervisor","tv commercial production","corporate video production company","music for commercials","music for websites","music for films","movie trailer music","music beds","advertising music","production music library","music library","music licensing","music licensing company","music for television","on hold music","corporate music","online music library","advertising jingles","radio production music","music production house","hold audio","music for tv","production music libraries","stock footage library","music for hold","music libraries","music for video production","background music library","post production music","pre production music","music for advertising","licensing music","production music download","download production music","download stock music","music for ads","television commercial music","tv commercial music","sync licensing","music tracks","music production company","digital music library","buyout music library","background music download","stock music library","music libary","download music library","music licensing online","film production music","commercial production music","licensing commercial music","music licensing companies","hold music licensing","music production companies","music for video games","corporate video production companies","internet music library","online music libraries","stock photos library","film tv music","tv film music","public domain music library","needle drop music","tv production music","television advert music","commerical music","video background music","online music licensing","license music for film","commercial editor","music supervision companies","film and tv music","film trailer music","film score music","video game music online","tv music commercials","music for tv commercials","background music tracks","tv ad production","film music licensing","background music for video","trailer soundtracks","movie score music","production music tracks","network production music","music supervision company","music licensing services","productions music","libary music","world music library","movie trailer soundtracks","film music library","music for video game","internet music licensing","country music library","buy stock music","stock music for video","corporate music library","independent music licensing","music library download","music for tv ads","music on hold music","music for productions","tv ad production companies","broadcast music library","television music licensing","music library online","commercial music licensing","movie trailers music","tv background music","licensing for music","stock music download","stock music libraries","royalty music library","music for production","network music library","library music companies","music for commercial use","music from movie trailers","licensing music for film","buyout library music","tv advert soundtracks","rock music library","music library downloads","production music online","license for music","tv advert song","background music track","current advert music","background music royalty","television music library","video game background music","advertising production company","music for tv commercial","music for corporate video","tv music licensing","music for trailers","songs used in films","music licensing agencies","background music for film","music used in ads","music for jingles","audio licensing","commercial music tracks","background music for videos","tv advertisement songs","music for corporate videos","music for tv show","production music beds","audio production music","production libraries","stock music downloads","background buyout music","production music company","broadcast production music","music score library","music for advert","stock music licensing","stock music search","corporate video music","online production music library","broadcast production music library","licensing music for movies","best music library","production music licensing","music for licensing","music library licensing","jingles for commercials","background music for commercials","television production music","stock production music","buy production music","production music companies","list of music production companies","movie production music","find advert music","musical beds","stock music for websites","original production music","stock music tracks","music for television shows","music for radio commercials","digital licensing music","commercial music library","music library for video","tv trailer music","music for movie trailers","buyout music libraries","soundtracks for games","music for tv and film","music library website","music publishing licensing","commercial music beds","online classical music library","film music songs","stock music sites","music licensing sites","best music libraries","background music tv","best movie trailer music","music licensing website","licensed music library","video game music library","film music libraries","music for film tv","background music for site","music for car commercials","background commercial music","music licensing for movies","songs for tv commercials","stock music companies","stock music websites","licensing music for video games","top music licensing companies","license music library","background theme music","stock music site","stock music online","stock background music","music scores library","background film music","music for movie trailer","quality stock music","international music score library","best stock music","action movie trailer music","sell stock music","songs licensing","buy music for film","music clearance and licensing","music licensing for films","commercial stock music","music library companies","music licensing for websites","best production music","licensing music for tv","licensing music for website","internet radio music licensing","music licensing websites","advertising music library","background music score","trailers soundtrack","background music for tv shows","best stock music sites","best music licensing companies","stock music for games","music and sound library","premium production music library","premium production music","background music for game","trailer music library","stock music free download","video production music library","video music library","premium music library","premium stock music","film and tv music library","non exclusive music licensing","best library music","tv advertisements songs","music track library","intense music for movie trailers","scary movie trailer music","movie trailer background music","songs for movie trailers","good music for commercials","background music for ads","games background music","good movie trailer music","library music source","search music library","music licensing consultant"];
