

var base_url = 'http://www.madeinthemidlands.com/';



var app_path = 'application/';

$(document).ready(function() {

	// Input Placeholders for legacy browsers
	if(!Modernizr.input.placeholder){
		$(':input[placeholder]').each(function(){
			var $this = $(this);
			if(!$this.val()){
				$this.val($this.attr('placeholder'));
				$this.addClass('placeholder');
			}
		}).live('focus', function(e){
			var $this = $(this);
			if($this.hasClass('placeholder')){
				$this.val('');
				$this.attr('placeholder', '');
				$this.removeClass('placeholder')
			}
		}).live('blur', function(e){
			var $this = $(this);
			if(!$this.val()){
				$this.addClass('placeholder');
				$this.val($this.attr('placeholder'));
			}
		});

		// Don't submit Placeholder Values, that would be silly!
		$('form').submit(function() {
			$('input', $(this)).each(function(){
				if($(this).val() === $(this).attr('placeholder')) {
					$(this).val('');
				}
			});
		});
	}

	// Hide Flash Msgs
	$('div.flash, .save-success').click(function()
	{
		$(this).stop().fadeOut();
	});

	$('a.hide').click(function() {
		$(this).parent().fadeOut();
		return false;
	});

	// TinyMCE
	$('.basic-wysiwyg').tinymce({
	   // Location of TinyMCE script
	    script_url : 'tiny_mce/tiny_mce.js',

	    // General options
	    theme : "advanced",
	    plugins : "imagemanager,filemanager,pagebreak,layer,table,save,advhr,advimage,advlink,inlinepopups,insertdatetime,preview,media,contextmenu,paste,directionality,fullscreen,noneditable,nonbreaking,xhtmlxtras,advlist",

	    // Theme options
	    theme_advanced_buttons1 : "bold,italic,underline|,justifyleft,justifycenter,justifyright,|,pastetext,pasteword,|,bullist,numlist,|,undo,redo,|,link,unlink",

	    theme_advanced_buttons2: "",
	    theme_advanced_buttons3 : "",
	    width: '100%',

	    theme_advanced_blockformats : "p,h3,h4,h5",

	   	file_browser_callback : "imagemanager",

		pagebreak_separator : "<!--[page-break]-->",

	    theme_advanced_styles : "Left=left;Right=right;",

	    invalid_elements : "div,section,span",

	    force_br_newlines : false,
	    force_p_newlines : true,

	    //content_css : base_url + 'assets/public/css/main.css',

	    theme_advanced_toolbar_location : "top",
	    theme_advanced_toolbar_align : "center",
	    theme_advanced_statusbar_location : "bottom",
	    theme_advanced_resizing : true,
	    theme_advanced_resize_horizontal : false,
	    convert_urls : false,
		relative_urls : false,

			valid_styles : {
				"*" : "font-weight,font-style,text-decoration"
			},
			valid_elements : ""
				+"a[coords|href|hreflang|id|name|rel|rev|shape<circle?default?poly?rect|style|target|type],"
				+"br[clear<all?left?none?right|style],"
				+"em/i[style],"
				+"h1[align<center?justify?left?right|style],"
				+"h2[align<center?justify?left?right|style],"
				+"h3[align<center?justify?left?right|style],"
				+"h4[align<center?justify?left?right|style],"
				+"h5[align<center?justify?left?right|style],"
				+"h6[align<center?justify?left?right|style],"
				+"p[align<center?justify?left?right|style],"
				+"span[align<center?justify?left?right|style],"
				+"strong/b[style],"
				+"u[style],"
				+"img[align<bottom?left?middle?right?top|alt|border|class|dir<ltr?rtl|height"
				  +"|hspace|id|ismap<ismap|lang|longdesc|name|onclick|ondblclick|onkeydown"
				  +"|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover"
				  +"|onmouseup|src|style|title|usemap|vspace|width],"
				+"object[type|data|width|height|classid|codebase],"
				+"param[name|value],"
				+"embed[src|type|width|height|flashvars|wmode],"
				+"ol[type|compact],ul[type|compact],li"
				,

			cleanup_on_startup : true,
			paste_remove_styles : true,
			paste_text_sticky : true,

			setup : function( ed ) {
				ed.onInit.add( function( ed ) {
					ed.pasteAsPlainText = true;
				});
			}

	});

	$('input.add-row').click(function() {

		row_id = $(this).data('row') +1;

		if(row_id > 5) {
			return false;
		}

		$('div#row-'+row_id).slideDown();

		$(this).slideUp();

		return false;
	});

	$("#main-ad").mouseenter(function() {
		$(this).stop().animate({
			height: 200
		});
	});
	$("#main-ad").mouseleave(function() {
		$(this).stop().animate({
			height: 48
		});
	});

});

