// And now our functions..

$(function(){
		
	$("#accordion").accordion({ header: "h3" });
	// Tabs
	$('#tabs').tabs();
	// Dialog	
	$.ui.dialog.defaults.bgiframe = true;

	$('#dialog1, #dialog2, #dialog3, #dialog4, #dialog5, #dialog6').dialog({
		autoOpen: false,
		width: 370,
		buttons: {
				Close: function() {
					$(this).dialog('close');
					$('#dialog1, #dialog2, #dialog3, #dialog4, #dialog5, #dialog6').removeClass('selected');
				}
			},
		resizable: false
	});
	
	// Dialog Link
	$('#dialog_link1').click(function(){
		$('#dialog1').dialog('open');
		return false;
	});
	// Dialog Link
	$('#dialog_link3').click(function(){
		$('#dialog3').dialog('open');
		return false;
	});
	
	
	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
		
	// =---------------------------- ON TO OUR SCRIPTS NOW -----------------------------=
	

		/*
		// CHANGE FONT WEIGHT
		$('select#fontWeight').selectToUISlider({
			sliderOptions: {
			stop: function(e,ui) 
				{
					var currentfontWeightSlide = $('div#textInputViewer').css('font-size');
					var newfontWeightSlide = $('select#fontWeight').val();
					$('div#textInputViewer').css('font-weight', newfontWeightSlide);
				}
			}
		});
		

		// CHANGE FONT STYLE
		$('select#fontStyle').selectToUISlider({
			sliderOptions: {
			stop: function(e,ui) 
				{
					var currentfontStyleSlide = $('div#textInputViewer').css('font-style');
					var newfontStyleSlide = $('select#fontStyle').val();
					$('div#textInputViewer').css('font-style', newfontStyleSlide);
				}
			}
		});

		*/
		
		
		// ADVANCED
		// CHANGE PARAGRAPH FONT FAMILY
		$("select#fontFamily").change(function () {
			var currentfontFamily = $('div#textInputViewer p').css('font-family');
			var newfontFamily = $('select#fontFamily').val();
			$('div#textInputViewer p').css('font-family', newfontFamily);
			$('input.display_pfontfamily').empty().val(newfontFamily);
			return false;
        })

		// ADVANCED
		// CHANGE PARAGRAPH FONT FAMILY
		$("select#fontFamilyA").change(function () {
			var currentfontFamilyA = $('div#textInputViewer a').css('font-family');
			var newfontFamilyA = $('select#fontFamilyA').val();
			$('div#textInputViewer a').css('font-family', newfontFamilyA);
			$('input.display_afontfamily').empty().val(newfontFamilyA);
			return false;
        })
		
		// CHANGE PARAGRAPH FONT FAMILY
		$("select#fontFamilyMenu").change(function () {
			var currentfontFamilyMenu = $('div#navbar li a').css('font-family');
			var newfontFamilyMenu = $('select#fontFamilyMenu').val();
			$('div#navbar li a').css('font-family', newfontFamilyMenu);
			$('input.display_menu_fontfamily').empty().val(newfontFamilyMenu);
			return false;
        })
		
		// ADVANCED
		// CHANGE h1 FONT FAMILY
		$("select#h1fontFamily").change(function () {
			var currenth1fontFamily = $('div#textInputViewer h1').css('font-family');
			var newh1fontFamily = $('select#h1fontFamily').val();
			$('div#textInputViewer h1').css('font-family', newh1fontFamily);
			$('input.display_h1fontfamily').empty().val(newh1fontFamily);
			return false;
        })
		
		// ADVANCED
		// CHANGE h2 FONT FAMILY
		$("select#h2fontFamily").change(function () {
			var currenth2fontFamily = $('div#textInputViewer h2').css('font-family');
			var newh2fontFamily = $('select#h2fontFamily').val();
			$('div#textInputViewer h2').css('font-family', newh2fontFamily);
			$('input.display_h2fontfamily').empty().val(newh2fontFamily);
			return false;
        })


		// CHANGE FAMILY
		$("select#custom_css_decoration").change(function () {
			var currentLinkStyle = $('div#textInputViewer a').css('text-decoration');
			var newLinkStyle = $('select#custom_css_decoration').val();
			$('div#textInputViewer a').css('text-decoration', newLinkStyle);
			return false;
        })
		
		$("select#menu_link_style").change(function () {
			var currentMenuLinkStyle = $('div#navbar li a').css('text-decoration');
			var newMenuLinkStyle = $('select#menu_link_style').val();
			$('div#navbar li a').css('text-decoration', newMenuLinkStyle);
			$('input.display_menu_link_style').val(newMenuLinkStyle);
			return false;
        })
		
		$("select#menu_hover_style").change(function () {
			var newMenuHoverStyle = $('select#menu_hover_style').val();
			$('input.display_menu_hover_style').val(newMenuHoverStyle);
			return false;
        })
		
		// CHANGE Border-Underline for Menu
		$("select#custom_css_menuunderline").change(function () {
			var currentMenuUnderline = $('div#navbar li').css('border-bottom-style');
			var newMenuUnderline = $('select#custom_css_menuunderline').val();
			$('div#navbar li').css('border-bottom-style', newMenuUnderline);
			$('input.display_menu_underline').val(newMenuUnderline);
			return false;
        })
		// CHANGE Border-Underline Thickness for Menu
		$("select#custom_css_menuunderlinethick").change(function () {
			var currentMenuUnderlineThick = $('div#navbar li').css('border-width');
			var newMenuUnderlineThick = $('select#custom_css_menuunderlinethick').val();
			$('div#navbar li').css('border-width', newMenuUnderlineThick + 'px');
			$('input.display_menu_underline_thick').val(newMenuUnderlineThick);
			$('div#navbar li:has(ul)').css('border-width', '0px');
			return false;
        })
		
		
		// TOGGLE FONT TRANSFORM BUTTONS - after the values are retrieved from the db.
		$('a#fontBold').click(function(){
			if ($(this).hasClass('switchon'))
				{$(this).removeClass('switchon');$('input.display_fontweight, input.display_menu_fontweight').val('normal');$('div#textInputViewer h1, div#textInputViewer h2, div#textInputViewer p, div#textInputViewer a').css({fontWeight: 'normal'});}
			else {$(this).addClass('switchon');$('input.display_fontweight, input.display_menu_fontweight').val('bold');$('div#textInputViewer h1, div#textInputViewer h2, div#textInputViewer p, div#textInputViewer a').css({fontWeight: 'bold'});}
		});
		
		$('a#fontStyle').click(function(){
			if ($(this).hasClass('switchon'))
				{$(this).removeClass('switchon');$('input.display_fontstyle, input.display_menu_fontstyle').val('normal');$('div#textInputViewer h1, div#textInputViewer h2, div#textInputViewer p, div#textInputViewer a').css({fontStyle: 'normal'});}
			else {$(this).addClass('switchon');$('input.display_fontstyle, input.display_menu_fontstyle').val('italic');$('div#textInputViewer h1, div#textInputViewer h2, div#textInputViewer p, div#textInputViewer a').css({fontStyle: 'italic'});}
		});
		
		$('a#fontUppercase').click(function(){
			if ($(this).hasClass('switchon'))
				{$(this).removeClass('switchon');$('input.display_texttransform, input.display_menu_texttransform').val('none');$('div#textInputViewer h1, div#textInputViewer h2, div#textInputViewer p, div#textInputViewer a').css({textTransform: 'none'});}
			else {$(this).addClass('switchon');$('input.display_texttransform, input.display_menu_texttransform').val('uppercase');$('div#textInputViewer h1, div#textInputViewer h2, div#textInputViewer p, div#textInputViewer a').css({textTransform: 'uppercase'});}
		}); 
		
		
		
		// Personalise
	//$('.wiz.loginpanel').corner();
	//$('div.cornerit10px').corner('10px');
	
	// --------========== CHANGE MENU ============---------- //
	
	
	
	
	
	$('div.toggleBackgroundandColours, div.togglefontstylepro').css({opacity: '0'});
	$('div.toggleMenuFontStyle').css({zIndex: '10'});

	$('li.ChangeMenu_FontStyle').click(function(){
		$('div.changemenuattribute').css({opacity: '0', zIndex: '1'});
		$('div.toggleMenuFontStyle select, div.toggleBackgroundandColours select, div.changemenuattribute select').css({display: 'none'});
		$('div.toggleMenuFontStyle').css({opacity: '1', zIndex: '10'});
		$('div.toggleMenuFontStyle select').css({display: 'block'});
	});
	
	$('li.ChangeMenu_BgCol').click(function(){
		$('div.changemenuattribute').css({opacity: '0', zIndex: '1'});
		$('div.toggleMenuFontStyle select, div.toggleBackgroundandColours select, div.changemenuattribute select').css({display: 'none'});
		$('div.toggleBackgroundandColours').css({opacity: '1', zIndex: '10'});
		$('div.toggleBackgroundandColours select').css({display: 'block'});
	});

	$('li.ChangeMenu_FontStylePro').click(function(){
		$('div.changemenuattribute').css({opacity: '0', zIndex: '1'});
		$('div.toggleMenuFontStyle select, div.toggleBackgroundandColours select, div.changemenuattribute select').css({display: 'none'});
		$('div.togglefontstylepro').css({opacity: '1', zIndex: '10'});
	});

	// Make our dialog boxes draggable.... !
	$("div.mrs_dialogwrap").draggable({handle: 'span'});
		
});