$(document).ready(function() { 
	
	
	/* Auto-fill URLs for product links based on the text of 'a' elements */
	var products = {
		"BootSkin" : "http://www.stardock.com/products/bootskin/",
		"CursorFX" : "http://www.stardock.com/products/cursorfx/",
		"DesktopX" : "http://www.stardock.com/products/desktopx/",
		"DeskScapes" : "http://www.stardock.com/products/deskscapes/",
		"Fences" : "http://www.stardock.com/products/fences/",
		"Fences Pro" : "http://www.stardock.com/products/fencespro/",
		"IconDeveloper" : "http://www.stardock.com/products/icondeveloper/",
		"IconPackager" : "http://www.stardock.com/products/iconpackager/",
		"LogonStudio" : "http://www.stardock.com/products/logonstudio/",
		"KeepSafe" : "http://www.stardock.com/products/keepsafe/",
		"Keyboard Launchpad" : "http://www.stardock.com/products/klp/",
		"Multiplicity" : "http://www.stardock.com/products/multiplicity/",
		"Multiplicity Pro" : "http://www.stardock.com/products/multiplicitypro/",
		"Object Desktop" : "http://www.stardock.com/products/odnt/",
		"Complete Suite" : "http://stardock.com/products/odnt/",
		"ObjectDock" : "http://www.stardock.com/products/objectdock/",
		"ObjectDock Plus" : "http://www.stardock.com/products/objectdock/information_plus.asp",
		"Premium Themes" : "http://www.stardock.com/products/themes/",
		"SkinStudio" : "http://www.stardock.com/products/skinstudio/",
		"SoundPackager" : "http://www.stardock.com/products/soundpackager/",
		"Tiles" : "http://www.stardock.com/products/tiles/",
		"Theme Manager" : "http://www.stardock.com/products/thememanager/",
		"Tweak7" : "http://www.stardock.com/products/tweak7/",
		"WindowBlinds" : "http://www.stardock.com/products/windowblinds/",
		"WindowFX" : "http://www.stardock.com/products/windowfx/"
	};
	$('a[href=""]').each(function(index){
		$(this).attr('href',products[$(this).text()]);
	});
	/* FancyBox for the video */
	$("a#show_video_preview").fancybox({
		'transitionIn' : 'none',
		'transitionOut' : 'none'	
	}
	);
	
	/* Expander setup */
	$("a.expander_indicator").click(function(){
		if ($(this).hasClass('collapsed')) {
			$(this).removeClass('collapsed').addClass('expanded');
			$(this).parents('.expander_template').first().children('.expander_content').slideDown('fast');
		}
		else {
			$(this).removeClass('expanded').addClass('collapsed');
			$(this).parents('.expander_template').first().children('.expander_content').slideUp('fast');
		}
		
	})
	
	/*Highlighting of product rows on hover */
	$('#left_pane > div.product').hover(
		function(){
			$(this).stop().animate({
      backgroundColor: "#eaf5e2"
  }, '1' );
		},
		function () {
			$(this).stop().animate({
      backgroundColor: "#ffffff"
  }, '1');
		}
	);
	
	/* #region Labels inside of text inputs */

	$('input[type="text"][title],textarea[title]').each(function () {

		if ($(this).attr('value').length == 0) {
			$(this).attr('value', $(this).attr('title'));
			$(this).addClass('text-label');
		}


		$(this).focus(function () {
			if (this.value == $(this).attr('title')) {
				this.value = '';
				$(this).removeClass('text-label');
			}
		});

		$(this).blur(function () {
			if (this.value == '') {
				this.value = $(this).attr('title');
				$(this).addClass('text-label');
			}
		});
	});

	$('.button').click(function () {
		$.each($('input'), function (index, value) {
			if ($(value).attr('value') == $(value).attr('title'))
				$(value).attr('value', '');
		});

		return true;
	});

	/* #endregion */
	
	/* Submit on enter */
	$('.sdmagazine').keypress(function (event) {
        if (event.which == 13) {
            $('a[id$=stardock_magazine_signup]').click();
        }
    });
		
});
