$(document).ready(function() {
	
	// left slideshow
	$("#home_slideshow_left").cycle({
		fx: 'scrollLeft',
		sync:1,
		speed:1500,
		timeout:5000
	});

	// right slideshow
	$("#home_slideshow_right").cycle({
		fx: 'scrollRight',
		sync:1,
		speed:1500,
		delay:500,
		timeout:5000
	});

	// hack for msie email box positioning
	if ($.browser.msie) {
		$("#mce-EMAIL").css("margin-top","-2px");
		$("#mce-EMAIL").css("margin-left","-0px");
		$("#mc-embedded-subscribe").css("margin-top","-1px");
	}					
	
	// handle goto pulldown menu
	$("#go_to_orig").change(function() {
		if ($(this).val() != "" && $(this).val() != "----------") {
			var loc = window.location.href.split("/")
			window.location = "http://" + loc[2] + $(this).val() + "/"
		}
	})
 	
	// handle buy button 
	$(".buy").click(function() {
		var loc = window.location.href.split("/")
		var url = "http://"+loc[2]+"/buy/index.php?";
		var rel = $(this).attr("rel")
		url += "page=shop/cart&func=cartAddMulti&"+$(this).attr("rel")+"=1&"+$(this).attr("rel")+"_cpu="+$("#"+rel).val();
		window.location=url
	})
	$(".buy").mouseover(function() {
		$(this).attr("src","/images/layout/BUY_rollover.png");
	})
	$(".buy").mouseout(function() {
		$(this).attr("src","/images/layout/BUY.png");
	})
	
	// handle selected state for browse nav
	var loc = window.location.href.split("/");
	if (loc[3] == 'browse') {
		href = "/"+loc[3]+"/"+loc[4]
		$("a[href="+href+"]").parent().addClass("selected");
	}
	
	// Handle email address signup text
	$("input#mce-EMAIL").focus(function() {
		$(this).val("");
	})
	$("input#mce-EMAIL").blur(function() {
		if ($(this).val() == "")
			$(this).val("Enter Email Address");
	})
	
	// Handle typesetter input
	$("#typesetter_input").focus(function() {
		$(this).val("");
	})
	
	// Handle typesetter 
	$("#typesetter_form").submit(function() {
		var newtext = $("#typesetter_input").val()
		var oldsrc = $("#typesetter img.setting").attr("src")
		var newsrc = oldsrc.replace(/text=.+/, "text="+newtext)
		$("#typesetter img.setting").attr("src",newsrc)
		return false;
	})
	
	// Dropdown Replacement - http://programmingdrunk.com/current-projects/dropdownReplacement/
	
	// for font & package buy menues	
	cmd = window.location.search.substring(1);	
	if (cmd != 'disableddr') {
		$("#singles select, #_buy select, #leftcol.cart select").each(function(){
			$(this).dropdownReplacement({
				resizeOptionsToFitSelect: false,
				resizeSelectToFitOptions: true,
				optionsDisplayNum: 11,
				optionsWidthOffset: 3,
				width: "100px"
			});
		});
	}	
	
	// for goto menu
	$("#go_to select").each(function() {
		$(this).dropdownReplacement({
			resizeOptionsToFitSelect: false,
			resizeSelectToFitOptions: false,
			optionsDisplayNum: 37, 
			optionsWidthOffset: 3,
			width:"200px"
		});
	});

	// download link
	$("#download_link").click(function() {
		$("#download_link img").attr('src','/images/buy/mvb_download_clicked.png')		
	})

	// Handle contact form submit
	$("#contact_form").ajaxForm(function() {
		$("#contact_form_response").text("Your message has been sent to MVB Fonts.").show();
	})
	
});
