/*!
 * jQuery Cookie Plugin v1.1
 * https://github.com/carhartl/jquery-cookie
 *
 * Copyright 2011, Klaus Hartl
 * Dual licensed under the MIT or GPL Version 2 licenses.
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.opensource.org/licenses/GPL-2.0
 */
(function($, document) {

	var pluses = /\+/g;
	function raw(s) {
		return s;
	}
	function decoded(s) {
		return decodeURIComponent(s.replace(pluses, ' '));
	}

	$.cookie = function(key, value, options) {

		// key and at least value given, set cookie...
		if (arguments.length > 1 && (!/Object/.test(Object.prototype.toString.call(value)) || value == null)) {
			options = $.extend({}, $.cookie.defaults, options);

			if (value == null) {
				options.expires = -1;
			}

			if (typeof options.expires === 'number') {
				var days = options.expires, t = options.expires = new Date();
				t.setDate(t.getDate() + days);
			}

			value = String(value);

			return (document.cookie = [
				encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value),
				options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
				options.path    ? '; path=' + options.path : '',
				options.domain  ? '; domain=' + options.domain : '',
				options.secure  ? '; secure' : ''
			].join(''));
		}

		// key and possibly options given, get cookie...
		options = value || $.cookie.defaults || {};
		var decode = options.raw ? raw : decoded;
		var cookies = document.cookie.split('; ');
		for (var i = 0, parts; (parts = cookies[i] && cookies[i].split('=')); i++) {
			if (decode(parts.shift()) === key) {
				return decode(parts.join('='));
			}
		}
		return null;
	};

	$.cookie.defaults = {};

})(jQuery, document);

var _fonts = '<option value="" class="_font_open_default">Default</option><option class="_font_open_sans">Open Sans</option><option class="_font_droid_sans">Droid Sans</option><option class="_font_oswald">Oswald</option><option class="_font_droid_serif">Droid Serif</option><option class="_font_lobster">Lobster</option><option class="_font_yanone_kaffeesatz">Yanone Kaffeesatz</option><option class="_font_pt_sans">PT Sans</option><option class="_font_lora">Lora</option><option class="_font_ubuntu">Ubuntu</option><option class="_font_crushed">Crushed</option><option class="_font_lato">Lato</option><option class="_font_arvo">Arvo</option><option class="_font_pt_sans_narrow">PT Sans Narrow</option><option class="_font_nunito">Nunito</option><option class="_font_open_sans_condensed">Open Sans Condensed</option><option class="_font_crafty_girls">Crafty Girls</option><option class="_font_just_me_again_down_here">Just Me Again Down Here</option><option class="_font_bitter">Bitter</option><option class="_font_marck_script">Marck Script</option><option class="_font_cabin">Cabin</option><option class="_font_dancing_script">Dancing Script</option><option class="_font_francois_one">Francois One</option><option class="_font_arimo">Arimo</option><option class="_font_josefin_sans">Josefin Sans</option><option class="_font_play">Play</option><option class="_font_coming_soon">Coming Soon</option><option class="_font_gochi_hand">Gochi Hand</option><option class="_font_pt_serif">PT Serif</option><option class="_font_anton">Anton</option><option class="_font_raleway">Raleway</option><option class="_font_caloptiongraffitti">Caloptiongraffitti</option><option class="_font_nobile">Nobile</option><option class="_font_cantarell">Cantarell</option><option class="_font_shadows_into_optionght">Shadows Into optionght</option><option class="_font_salsa">Salsa</option><option class="_font_cherry_cream_soda">Cherry Cream Soda</option><option class="_font_cuprum">Cuprum</option><option class="_font_tangerine">Tangerine</option><option class="_font_maven_pro">Maven Pro</option><option class="_font_molengo">Molengo</option><option class="_font_rock_salt">Rock Salt</option><option class="_font_abel">Abel</option><option class="_font_reenie_beanie">Reenie Beanie</option><option class="_font_pacifico">Pacifico</option><option class="_font_chewy">Chewy</option><option class="_font_ubuntu_condensed">Ubuntu Condensed</option><option class="_font_unkempt">Unkempt</option><option class="_font_sunshiney">Sunshiney</option><option class="_font_luckiest_guy">Luckiest Guy</option><option class="_font_amaranth">Amaranth</option><option class="_font_vollkorn">Vollkorn</option><option class="_font_bree_serif">Bree Serif</option><option class="_font_crimson_text">Crimson Text</option><option class="_font_philosopher">Philosopher</option><option class="_font_condiment">Condiment</option><option class="_font_asap">Asap</option><option class="_font_kreon">Kreon</option><option class="_font_permanent_marker">Permanent Marker</option><option class="_font_walter_turncoat">Walter Turncoat</option><option class="_font_rokkitt">Rokkitt</option><option class="_font_josefin_slab">Josefin Slab</option><option class="_font_droid_sans_mono">Droid Sans Mono</option><option class="_font_homemade_apple">Homemade Apple</option><option class="_font_muoption">Muoption</option><option class="_font_architects_daughter">Architects Daughter</option><option class="_font_merriweather">Merriweather</option><option class="_font_mate_sc">Mate SC</option><option class="_font_allerta">Allerta</option><option class="_font_indie_flower">Indie Flower</option><option class="_font_shadows_into_optionght_two">Shadows Into optionght Two</option><option class="_font_paytone_one">Paytone One</option><option class="_font_syncopate">Syncopate</option><option class="_font_copse">Copse</option><option class="_font_marvel">Marvel</option><option class="_font_news_cycle">News Cycle</option><option class="_font_cardo">Cardo</option><option class="_font_slackey">Slackey</option><option class="_font_varela_round">Varela Round</option><option class="_font_lobster_two">Lobster Two</option><option class="_font_fontdiner_swanky">Fontdiner Swanky</option><option class="_font_covered_by_your_grace">Covered By Your Grace</option><option class="_font_questrial">Questrial</option><option class="_font_didact_gothic">Didact Gothic</option><option class="_font_pt_sans_caption">PT Sans Caption</option><option class="_font_old_standard_tt">Old Standard TT</option><option class="_font_carter_one">Carter One</option><option class="_font_bevan">Bevan</option><option class="_font_neucha">Neucha</option><option class="_font_just_another_hand">Just Another Hand</option><option class="_font_tinos">Tinos</option><option class="_font_neuton">Neuton</option><option class="_font_inconsolata">Inconsolata</option><option class="_font_puritan">Puritan</option><option class="_font_cabin_sketch">Cabin Sketch</option><option class="_font_signika">Signika</option><option class="_font_schoolbell">Schoolbell</option><option class="_font_goudy_bookletter_1911">Goudy Bookletter 1911</option><option class="_font_leckeroption_one">Leckeroption One</option><option class="_font_amatic_sc">Amatic SC</option><option class="_font_waiting_for_the_sunrise">Waiting for the Sunrise</option><option class="_font_jura">Jura</option><option class="_font_allerta_stencil">Allerta Stencil</option><option class="_font_voltaire">Voltaire</option><option class="_font_istok_web">Istok Web</option><option class="_font_gloria_hallelujah">Gloria Hallelujah</option><option class="_font_montserrat">Montserrat</option><option class="_font_the_girl_next_door">The Girl Next Door</option><option class="_font_short_stack">Short Stack</option><option class="_font_quicksand">Quicksand</option><option class="_font_bowlby_one_sc">Bowlby One SC</option><option class="_font_maiden_orange">Maiden Orange</option><option class="_font_comfortaa">Comfortaa</option><option class="_font_orbitron">Orbitron</option><option class="_font_chivo">Chivo</option><option class="_font_bad_script">Bad Script</option><option class="_font_pinyon_script">Pinyon Script</option><option class="_font_cousine">Cousine</option><option class="_font_kranky">Kranky</option><option class="_font_quattrocento_sans">Quattrocento Sans</option><option class="_font_kameron">Kameron</option><option class="_font_brawler">Brawler</option><option class="_font_varela">Varela</option><option class="_font_kristi">Kristi</option><option class="_font_exo">Exo</option><option class="_font_love_ya_optionke_a_sister">Love Ya optionke A Sister</option><option class="_font_days_one">Days One</option><option class="_font_special_eoptionte">Special Eoptionte</option><option class="_font_passion_one">Passion One</option><option class="_font_medievalsharp">MedievalSharp</option><option class="_font_handlee">Handlee</option><option class="_font_gruppo">Gruppo</option><option class="_font_cabin_condensed">Cabin Condensed</option><option class="_font_carme">Carme</option><option class="_font_changa_one">Changa One</option><option class="_font_michroma">Michroma</option><option class="_font_mountains_of_christmas">Mountains of Christmas</option><option class="_font_rancho">Rancho</option><option class="_font_optionmeoptionght">optionmeoptionght</option><option class="_font_sorts_mill_goudy">Sorts Mill Goudy</option><option class="_font_deoptionus_unicase">Deoptionus Unicase</option><option class="_font_miltonian_tattoo">Miltonian Tattoo</option><option class="_font_bentham">Bentham</option><option class="_font_shanti">Shanti</option><option class="_font_stardos_stencil">Stardos Stencil</option><option class="_font_deoptionus">Deoptionus</option><option class="_font_im_fell_engoptionsh">IM Fell Engoptionsh</option><option class="_font_eb_garamond">EB Garamond</option><option class="_font_volkhov">Volkhov</option><option class="_font_fugaz_one">Fugaz One</option><option class="_font_merienda_one">Merienda One</option><option class="_font_pt_serif_caption">PT Serif Caption</option><option class="_font_dosis">Dosis</option><option class="_font_podkova">Podkova</option><option class="_font_rosario">Rosario</option><option class="_font_metrophobic">Metrophobic</option><option class="_font_yellowtail">Yellowtail</option><option class="_font_six_caps">Six Caps</option><option class="_font_corben">Corben</option><option class="_font_mako">Mako</option><option class="_font_nixie_one">Nixie One</option><option class="_font_rochester">Rochester</option><option class="_font_metamorphous">Metamorphous</option><option class="_font_playfair_display">Playfair Display</option><option class="_font_satisfy">Satisfy</option><option class="_font_cookie">Cookie</option><option class="_font_share">Share</option><option class="_font_sue_ellen_francisco">Sue Ellen Francisco</option><option class="_font_im_fell_engoptionsh_sc">IM Fell Engoptionsh SC</option><option class="_font_actor">Actor</option><option class="_font_gudea">Gudea</option><option class="_font_coustard">Coustard</option><option class="_font_quattrocento">Quattrocento</option><option class="_font_sansita_one">Sansita One</option><option class="_font_bangers">Bangers</option><option class="_font_im_fell_dw_pica">IM Fell DW Pica</option><option class="_font_aoptionce">Aoptionce</option><option class="_font_andika">Andika</option><option class="_font_viga">Viga</option><option class="_font_noticia_text">Noticia Text</option><option class="_font_oxygen">Oxygen</option><option class="_font_hammersmith_one">Hammersmith One</option><option class="_font_jockey_one">Jockey One</option><option class="_font_crete_round">Crete Round</option><option class="_font_nothing_you_could_do">Nothing You Could Do</option><option class="_font_geo">Geo</option><option class="_font_coda">Coda</option><option class="_font_patrick_hand">Patrick Hand</option><option class="_font_judson">Judson</option><option class="_font_patua_one">Patua One</option><option class="_font_spinnaker">Spinnaker</option><option class="_font_magra">Magra</option><option class="_font_lekton">Lekton</option><option class="_font_poly">Poly</option><option class="_font_wire_one">Wire One</option><option class="_font_annie_use_your_telescope">Annie Use Your Telescope</option><option class="_font_sancreek">Sancreek</option><option class="_font_allan">Allan</option><option class="_font_ropa_sans">Ropa Sans</option><option class="_font_alfa_slab_one">Alfa Slab One</option><option class="_font_righteous">Righteous</option><option class="_font_ultra">Ultra</option><option class="_font_damion">Damion</option><option class="_font_antic">Antic</option><option class="_font_im_fell_dw_pica_sc">IM Fell DW Pica SC</option><option class="_font_norican">Norican</option><option class="_font_ubuntu_mono">Ubuntu Mono</option><option class="_font_redressed">Redressed</option><option class="_font_pompiere">Pompiere</option><option class="_font_unifrakturmaguntia">UnifrakturMaguntia</option><option class="_font_give_you_glory">Give You Glory</option><option class="_font_anonymous_pro">Anonymous Pro</option><option class="_font_doppio_one">Doppio One</option><option class="_font_deoptionus_swash_caps">Deoptionus Swash Caps</option><option class="_font_snippet">Snippet</option><option class="_font_cedarville_cursive">Cedarville Cursive</option><option class="_font_federo">Federo</option><option class="_font_tienne">Tienne</option><option class="_font_artifika">Artifika</option><option class="_font_aldrich">Aldrich</option><option class="_font_la_belle_aurore">La Belle Aurore</option><option class="_font_abril_fatface">Abril Fatface</option><option class="_font_smythe">Smythe</option><option class="_font_over_the_rainbow">Over the Rainbow</option><option class="_font_aclonica">Aclonica</option><option class="_font_ruluko">Ruluko</option><option class="_font_happy_monkey">Happy Monkey</option><option class="_font_dawning_of_a_new_day">Dawning of a New Day</option><option class="_font_tenor_sans">Tenor Sans</option><option class="_font_chau_philomene_one">Chau Philomene One</option><option class="_font_aladin">Aladin</option><option class="_font_nova_round">Nova Round</option><option class="_font_telex">Telex</option><option class="_font_inder">Inder</option><option class="_font_lustria">Lustria</option><option class="_font_convergence">Convergence</option><option class="_font_contrail_one">Contrail One</option><option class="_font_berkshire_swash">Berkshire Swash</option><option class="_font_gentium_book_basic">Gentium Book Basic</option><option class="_font_im_fell_french_canon_sc">IM Fell French Canon SC</option><option class="_font_glegoo">Glegoo</option><option class="_font_loved_by_the_king">Loved by the King</option><option class="_font_candal">Candal</option><option class="_font_cambo">Cambo</option><option class="_font_caudex">Caudex</option><option class="_font_montez">Montez</option><option class="_font_prata">Prata</option><option class="_font_lusitana">Lusitana</option><option class="_font_kaushan_script">Kaushan Script</option><option class="_font_gentium_basic">Gentium Basic</option><option class="_font_vt323">VT323</option><option class="_font_expletus_sans">Expletus Sans</option><option class="_font_signika_negative">Signika Negative</option><option class="_font_adamina">Adamina</option><option class="_font_forum">Forum</option><option class="_font_im_fell_great_primer_sc">IM Fell Great Primer SC</option><option class="_font_almendra_sc">Almendra SC</option><option class="_font_mate">Mate</option><option class="_font_ovo">Ovo</option><option class="_font_baumans">Baumans</option><option class="_font_rationale">Rationale</option><option class="_font_im_fell_great_primer">IM Fell Great Primer</option><option class="_font_black_ops_one">Black Ops One</option><option class="_font_gfs_neohellenic">GFS Neohellenic</option><option class="_font_buda">Buda</option><option class="_font_unifrakturcook">UnifrakturCook</option><option class="_font_parisienne">Parisienne</option><option class="_font_vidaloka">Vidaloka</option><option class="_font_zeyada">Zeyada</option><option class="_font_league_script">League Script</option><option class="_font_hanuman">Hanuman</option><option class="_font_poiret_one">Poiret One</option><option class="_font_ruslan_display">Ruslan Display</option><option class="_font_im_fell_double_pica_sc">IM Fell Double Pica SC</option><option class="_font_kenia">Kenia</option><option class="_font_arapey">Arapey</option><option class="_font_nova_soptionm">Nova Soptionm</option><option class="_font_radley">Radley</option><option class="_font_marmelad">Marmelad</option><option class="_font_fredoka_one">Fredoka One</option><option class="_font_nova_square">Nova Square</option><option class="_font_vibur">Vibur</option><option class="_font_economica">Economica</option><option class="_font_euphoria_script">Euphoria Script</option><option class="_font_im_fell_french_canon">IM Fell French Canon</option><option class="_font_tulpen_one">Tulpen One</option><option class="_font_rammetto_one">Rammetto One</option><option class="_font_bowlby_one">Bowlby One</option><option class="_font_swanky_and_moo_moo">Swanky and Moo Moo</option><option class="_font_kelly_slab">Kelly Slab</option><option class="_font_jolly_lodger">Jolly Lodger</option><option class="_font_nova_oval">Nova Oval</option><option class="_font_holtwood_one_sc">Holtwood One SC</option><option class="_font_gravitas_one">Gravitas One</option><option class="_font_unna">Unna</option><option class="_font_nova_script">Nova Script</option><option class="_font_meddon">Meddon</option><option class="_font_piedra">Piedra</option><option class="_font_nova_flat">Nova Flat</option><option class="_font_modern_antiqua">Modern Antiqua</option><option class="_font_julee">Julee</option><option class="_font_petrona">Petrona</option><option class="_font_im_fell_double_pica">IM Fell Double Pica</option><option class="_font_esteban">Esteban</option><option class="_font_astloch">Astloch</option><option class="_font_electrooptionze">Electrooptionze</option><option class="_font_armata">Armata</option><option class="_font_squada_one">Squada One</option><option class="_font_fredericka_the_great">Fredericka the Great</option><option class="_font_coda_caption">Coda Caption</option><option class="_font_lemon">Lemon</option><option class="_font_yeseva_one">Yeseva One</option><option class="_font_aoptionke">Aoptionke</option><option class="_font_prociono">Prociono</option><option class="_font_nova_mono">Nova Mono</option><option class="_font_asset">Asset</option><option class="_font_numans">Numans</option><option class="_font_megrim">Megrim</option><option class="_font_gfs_didot">GFS Didot</option><option class="_font_fjord_one">Fjord One</option><option class="_font_andada">Andada</option><option class="_font_geostar">Geostar</option><option class="_font_wallpoet">Wallpoet</option><option class="_font_great_vibes">Great Vibes</option><option class="_font_ruda">Ruda</option><option class="_font_dorsa">Dorsa</option><option class="_font_monoton">Monoton</option><option class="_font_fanwood_text">Fanwood Text</option><option class="_font_irish_grover">Irish Grover</option><option class="_font_federant">Federant</option><option class="_font_itaoptionanno">Itaoptionanno</option><option class="_font_sniglet">Sniglet</option><option class="_font_aubrey">Aubrey</option><option class="_font_acme">Acme</option><option class="_font_quantico">Quantico</option><option class="_font_boogaloo">Boogaloo</option><option class="_font_optionnden_hill">optionnden Hill</option><option class="_font_bigshot_one">Bigshot One</option><option class="_font_aoptionke_angular">Aoptionke Angular</option><option class="_font_pontano_sans">Pontano Sans</option><option class="_font_karla">Karla</option><option class="_font_lancelot">Lancelot</option><option class="_font_nova_cut">Nova Cut</option><option class="_font_optionoptionta_one">optionoptionta One</option><option class="_font_goboptionn_one">Goboptionn One</option><option class="_font_homenaje">Homenaje</option><option class="_font_voces">Voces</option><option class="_font_vast_shadow">Vast Shadow</option><option class="_font_playball">Playball</option><option class="_font_sigmar_one">Sigmar One</option><option class="_font_miltonian">Miltonian</option><option class="_font_smokum">Smokum</option><option class="_font_monofett">Monofett</option><option class="_font_galdeano">Galdeano</option><option class="_font_chelsea_market">Chelsea Market</option><option class="_font_poller_one">Poller One</option><option class="_font_allura">Allura</option><option class="_font_imprima">Imprima</option><option class="_font_supermercado_one">Supermercado One</option><option class="_font_passero_one">Passero One</option><option class="_font_suwannaphum">Suwannaphum</option><option class="_font_atomic_age">Atomic Age</option><option class="_font_geostar_fill">Geostar Fill</option><option class="_font_overlock_sc">Overlock SC</option><option class="_font_enriqueta">Enriqueta</option><option class="_font_fresca">Fresca</option><option class="_font_sofia">Sofia</option><option class="_font_alegreya">Alegreya</option><option class="_font_russo_one">Russo One</option><option class="_font_audiowide">Audiowide</option><option class="_font_trade_winds">Trade Winds</option><option class="_font_bubblegum_sans">Bubblegum Sans</option><option class="_font_duru_sans">Duru Sans</option><option class="_font_amethysta">Amethysta</option><option class="_font_oleo_script">Oleo Script</option><option class="_font_trocchi">Trocchi</option><option class="_font_rouge_script">Rouge Script</option><option class="_font_itaoptionana">Itaoptionana</option><option class="_font_flamenco">Flamenco</option><option class="_font_advent_pro">Advent Pro</option><option class="_font_mr_de_haviland">Mr De Haviland</option><option class="_font_sail">Sail</option><option class="_font_antic_slab">Antic Slab</option><option class="_font_trochut">Trochut</option><option class="_font_averia_optionbre">Averia optionbre</option><option class="_font_cantata_one">Cantata One</option><option class="_font_lovers_quarrel">Lovers Quarrel</option><option class="_font_niconne">Niconne</option><option class="_font_bilbo">Bilbo</option><option class="_font_kotta_one">Kotta One</option><option class="_font_junge">Junge</option><option class="_font_henny_penny">Henny Penny</option><option class="_font_ruthie">Ruthie</option><option class="_font_engagement">Engagement</option><option class="_font_gorditas">Gorditas</option><option class="_font_sonsie_one">Sonsie One</option><option class="_font_overlock">Overlock</option><option class="_font_londrina_sooptiond">Londrina Sooptiond</option><option class="_font_buenard">Buenard</option><option class="_font_basic">Basic</option><option class="_font_pt_mono">PT Mono</option><option class="_font_alegreya_sc">Alegreya SC</option><option class="_font_krona_one">Krona One</option><option class="_font_medula_one">Medula One</option><option class="_font_arizonia">Arizonia</option><option class="_font_titan_one">Titan One</option><option class="_font_cutive">Cutive</option><option class="_font_khmer">Khmer</option><option class="_font_iceberg">Iceberg</option><option class="_font_shojumaru">Shojumaru</option><option class="_font_mr_dafoe">Mr Dafoe</option><option class="_font_germania_one">Germania One</option><option class="_font_habibi">Habibi</option><option class="_font_alex_brush">Alex Brush</option><option class="_font_dynaoptionght">Dynaoptionght</option><option class="_font_glass_antiqua">Glass Antiqua</option><option class="_font_ledger">Ledger</option><option class="_font_rosarivo">Rosarivo</option><option class="_font_prosto_one">Prosto One</option><option class="_font_concert_one">Concert One</option><option class="_font_averia_serif_optionbre">Averia Serif optionbre</option><option class="_font_knewave">Knewave</option><option class="_font_miniver">Miniver</option><option class="_font_averia_sans_optionbre">Averia Sans optionbre</option><option class="_font_mystery_quest">Mystery Quest</option><option class="_font_sirin_stencil">Sirin Stencil</option><option class="_font_iceland">Iceland</option><option class="_font_trykker">Trykker</option><option class="_font_averia_gruesa_optionbre">Averia Gruesa optionbre</option><option class="_font_macondo_swash_caps">Macondo Swash Caps</option><option class="_font_qwigley">Qwigley</option><option class="_font_yesteryear">Yesteryear</option><option class="_font_sevillana">Sevillana</option><option class="_font_stint_ultra_condensed">Stint Ultra Condensed</option><option class="_font_fondamento">Fondamento</option><option class="_font_oldenburg">Oldenburg</option><option class="_font_ribeye_marrow">Ribeye Marrow</option><option class="_font_graduate">Graduate</option><option class="_font_belleza">Belleza</option><option class="_font_average">Average</option><option class="_font_emilys_candy">Emilys Candy</option><option class="_font_simonetta">Simonetta</option><option class="_font_flavors">Flavors</option><option class="_font_asul">Asul</option><option class="_font_press_start_2p">Press Start 2P</option><option class="_font_inika">Inika</option><option class="_font_devonshire">Devonshire</option><option class="_font_nosifer">Nosifer</option><option class="_font_princess_sofia">Princess Sofia</option><option class="_font_antic_didone">Antic Didone</option><option class="_font_codystar">Codystar</option><option class="_font_creepster">Creepster</option><option class="_font_frijole">Frijole</option><option class="_font_mrs_sheppards">Mrs Sheppards</option><option class="_font_della_respira">Della Respira</option><option class="_font_bokor">Bokor</option><option class="_font_bilbo_swash_caps">Bilbo Swash Caps</option><option class="_font_belgrano">Belgrano</option><option class="_font_londrina_shadow">Londrina Shadow</option><option class="_font_seaweed_script">Seaweed Script</option><option class="_font_ribeye">Ribeye</option><option class="_font_revaoptiona">Revaoptiona</option><option class="_font_port_loptiongat_slab">Port Loptiongat Slab</option><option class="_font_uncial_antiqua">Uncial Antiqua</option><option class="_font_almendra">Almendra</option><option class="_font_stoke">Stoke</option><option class="_font_macondo">Macondo</option><option class="_font_feoptionpa">Feoptionpa</option><option class="_font_balthazar">Balthazar</option><option class="_font_cagoptionostro">Cagoptionostro</option><option class="_font_aguafina_script">Aguafina Script</option><option class="_font_caesar_dressing">Caesar Dressing</option><option class="_font_fascinate">Fascinate</option><option class="_font_jim_nightshade">Jim Nightshade</option><option class="_font_spirax">Spirax</option><option class="_font_stint_ultra_expanded">Stint Ultra Expanded</option><option class="_font_sarina">Sarina</option><option class="_font_marko_one">Marko One</option><option class="_font_ewert">Ewert</option><option class="_font_moul">Moul</option><option class="_font_unlock">Unlock</option><option class="_font_chango">Chango</option><option class="_font_wellfleet">Wellfleet</option><option class="_font_metal">Metal</option><option class="_font_moulpaoption">Moulpaoption</option><option class="_font_monsieur_la_doulaise">Monsieur La Doulaise</option><option class="_font_londrina_sketch">Londrina Sketch</option><option class="_font_herr_von_muellerhoff">Herr Von Muellerhoff</option><option class="_font_battambang">Battambang</option><option class="_font_chicle">Chicle</option><option class="_font_diplomata_sc">Diplomata SC</option><option class="_font_original_surfer">Original Surfer</option><option class="_font_spicy_rice">Spicy Rice</option><option class="_font_erica_one">Erica One</option><option class="_font_dr_sugiyama">Dr Sugiyama</option><option class="_font_ceviche_one">Ceviche One</option><option class="_font_mrs_saint_delafield">Mrs Saint Delafield</option><option class="_font_montaga">Montaga</option><option class="_font_emblema_one">Emblema One</option><option class="_font_port_loptiongat_sans">Port Loptiongat Sans</option><option class="_font_butterfly_kids">Butterfly Kids</option><option class="_font_ruge_boogie">Ruge Boogie</option><option class="_font_dangrek">Dangrek</option><option class="_font_mr_bedfort">Mr Bedfort</option><option class="_font_plaster">Plaster</option><option class="_font_angkor">Angkor</option><option class="_font_content">Content</option><option class="_font_siemreap">Siemreap</option><option class="_font_londrina_outoptionne">Londrina Outoptionne</option><option class="_font_diplomata">Diplomata</option><option class="_font_freehand">Freehand</option><option class="_font_miss_fajardose">Miss Fajardose</option><option class="_font_eater">Eater</option><option class="_font_arbutus">Arbutus</option><option class="_font_fascinate_inoptionne">Fascinate Inoptionne</option><option class="_font_taprom">Taprom</option><option class="_font_bonbon">Bonbon</option><option class="_font_chenla">Chenla</option><option class="_font_nokora">Nokora</option><option class="_font_bayon">Bayon</option><option class="_font_preahvihear">Preahvihear</option><option class="_font_odor_mean_chey">Odor Mean Chey</option><option class="_font_butcherman">Butcherman</option><option class="_font_koulen">Koulen</option>';
var _fonts_sizes = "<option value=''>Default</option>";
var _slide_text_template =
'<div class="slider_text">\
 <div class="value">\
	<table>\
	<tr>\
		<td><label>Title</label></td>\
		<td><input type="text" name="slider_title"/></td>\
	</tr>\
	<!-- <tr>\
		<td><label>Subtitle</label></td>\
		<td><input type="text" name="slider_subtitle"/></td>\
	</tr> -->\
	<tr>\
		<td><label>Description</label></td>\
		<td><textarea name="slider_description"></textarea></td>\
	</tr>\
	</table>\
 </div>\
</div>';		 
var background_style = '';			 

for (var i = 8;i < 65;i++)
{
		_fonts_sizes += "<option value='" + i + "'>" + i + "</option>";
}


function rgb2hex(rgb){
 if (!rgb) return '';
 rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
 return (rgb && rgb.length === 4) ? "#" +
  ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
  ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
  ("0" + parseInt(rgb[3],10).toString(16)).slice(-2) : '';
}

var _nico_changes = {};
var _background_backup;

function normalize_string(str)
{
	return str.toLowerCase().replace(/[ -,\.;]/g,'_');
}

var _nico_save_message = "Done";
if (typeof _nico_demo != "undefined" && _nico_demo == true) _nico_save_message = "Saving is disabled in the DEMO version!";

function nico_save_theme()
{
/*	_nico_changes['slider_text'] = {};
	for (l in lang)
	{
		_nico_changes['slider_text'][lang[l]] = {};
		_nico_changes['slider_text'][lang[l]]['title'] = [];
		_nico_changes['slider_text'][lang[l]]['subtitle'] = [];
		_nico_changes['slider_text'][lang[l]]['description'] = [];
		
		var i = -1;
		jQuery("#nico_theme_editor .nico_slide_text.lang_" + [lang[l]]  + " .slider_text input, #nico_theme_editor .nico_slide_text.lang_" + [lang[l]]  + " div.slider_text textarea").each(function ()
		{
			if (this.name == 'slider_title')
			{
				i++;
				if (!_nico_changes['slider_text'][lang[l]][i]) _nico_changes['slider_text'][lang[l]][i] = {};
				_nico_changes['slider_text'][lang[l]][i]['title'] = this.value; 
			} else if (this.name == 'slider_subtitle')
			{
				if (!_nico_changes['slider_text'][lang[l]][i]) _nico_changes['slider_text'][lang[l]][i] = {};
				_nico_changes['slider_text'][lang[l]][i]['subtitle'] = this.value; 
			} else if (this.name == 'slider_description')
			{
				if (!_nico_changes['slider_text'][lang[l]][i]) _nico_changes['slider_text'][lang[l]][i] = {};
				_nico_changes['slider_text'][lang[l]][i]['description'] = this.value; 
			}
		});
   }
   
	var menu = [];
	function processOneLi(node) {       
		if (node.hasClass("categories"))
		{
			 var retVal = {
				"categories": true,
			}
		} else
		{
			var retVal = {};
			jQuery("> div > input", node).each(function() 
			{
				var $this = jQuery(this);
				var name = $this.attr("name");
				var val = $this.val();
				if (name == 'url' && val != '' ) retVal['url'] = $this.val();
				else
				{
				    if (!retVal['text']) retVal['text'] = {};
				    if (val != '') retVal['text'][name] = val;
				}
			});
		}
		
		node.find("> ul > li").each(function() {
			if (!retVal.hasOwnProperty("children")) {
				retVal.children = [];
			}
			retVal.children.push(processOneLi($(this)));
		});
		return retVal;
	}
	$("#nico_menu ul.jstree-no-dots > li").each(function() {
		menu.push(processOneLi($(this)));
	});

	_nico_changes['menu'] = menu;
*/
	var path = document.location.pathname;
	if (typeof path == "undefined") path = "";

	jQuery(".nico_status").text("Saving ...").show()
	$.ajax({
	  type:"POST",
	  url: path,
	  data:_nico_changes,
	  context: document.body
	}).done(function() { 
		var queryString = '?reload=' + new Date().getTime();
		
		$('link[rel="stylesheet"]._editor_css').attr("href", function () 
		{ 
			return this.href.replace(/\?.*|$/, queryString);
		});
		jQuery(".nico_status").text(_nico_save_message).show()
		
		_nico_changes = {};
		_nico_changes['styles'] = {};
		setTimeout('jQuery(".nico_status").text("").hide();', 2000);
	});		
}	

function init_backgrounds()
{
		jQuery("#nico_theme_editor .pattern .value").hover(
		  function (e) 
		  {
			var body = jQuery("body");
			var $this = jQuery(this);

			_background_backup = body.css('background-image');
			//jQuery(".page-container body").css('background-image', $this.css('background-image'));
			jQuery("body").attr("style",'background-image:'+ $this.css('background-image') + ';background-size:auto;' + background_style);
		  }, 
		  function (e) 
		  {
			var body = jQuery("body");
			jQuery("body").css('background-image', _background_backup);
		  }
		).click(function (e)
		{
			var body = jQuery("body");
			var $this = jQuery(this);
			jQuery("#nico_theme_editor .pattern .value").removeClass("selected");
			_nico_changes['background-image'] = _background_backup = $this.addClass("selected").css('background-image');
			jQuery("body").attr("style",'background-image:'+ _nico_changes['background-image'] + ';background-size:auto;' + background_style);
		});
		
		jQuery("#nico_theme_editor #background-style").on("change", function() 
		{
			_nico_changes['background-style'] = this.value;
			switch(this.value)
			{
					case 'repeat':
						background_style = 'background-repeat:repeat';
					break;
					case 'repeat-x':
						background_style = 'background-repeat:repeat-x';
					break;
					case 'repeat-y':
						background_style = 'background-repeat:repeat-y';
					break;
					case 'stretch':
						background_style = 'background-size:100%;background-size:cover';
					break;
					case 'no-repeat':
						background_style = 'background-repeat:no-repeat';
			}
			
			jQuery("body").attr("style",'background-image:' + _background_backup + ';background-size:auto;' + background_style);
		});
			
}

function init_colors()
{
	
		var picker_options =
		{
			parts:['map', 'bar', 'hex', 'hsv', 'rgb', 'alpha', 'preview'],
			alpha: true,
			inline:false,
			buttonColorize: true,
			showNoneButton: true,
			colorFormat: 'RGBA',
			color:"#ffffff",
			mode:"r",
			select:	function(event, color) 
			{
				var element = $(this);
				element.css('backgroundColor', color.formatted);
				jQuery(element.attr("selector")).css(element.attr("attribute"), color.formatted);

				if (!_nico_changes["colors"]) _nico_changes["colors"] = {};
				if (!_nico_changes["colors"][element.attr("selector")]) _nico_changes["colors"][element.attr("selector")] = {};
				if (color.formatted) _nico_changes['colors'][element.attr("selector")][element.attr("attribute")] = color.formatted;
			}
		};
	
		jQuery("#nico_theme_editor .color").each(function() 
		{
			var element = jQuery(".value", this);
			var back_color = "";
			back_color = element.attr("default");
			if (back_color == "") back_color = jQuery(element.attr("selector")).css(element.attr("attribute"));
			
			if (typeof back_color != "undefined" && back_color.charAt(0) != "#") back_color = rgb2hex(back_color);
			
			element.css({backgroundColor:back_color});
			picker_options.color = back_color;
			
			$(element).colorpicker(picker_options);
		});
}

function init_fonts()
{
		jQuery("#nico_theme_editor ._font_select").each(function() 
		{
			var element = jQuery(this);
			element.html(_fonts);
			var font_family = element.attr("default");
			if (!font_family) font_family = jQuery(element.attr("selector")).css("font-family");
			element.val(font_family);
				/*var element = $(this);
				jQuery(element.attr("selector")).css({fontFamily:this.value});*/
		});
		
		jQuery("#nico_theme_editor ._font_select_size").each(function() 
		{
			var element = jQuery(this);
			element.html(_fonts_sizes);

			var font_size = element.attr("default");
			if (!font_size) font_size = jQuery(element.attr("selector")).css("font-size");
			
			element.val(parseInt(font_size));
				/*var element = $(this);
				jQuery(element.attr("selector")).css({fontFamily:this.value});*/
		});

		
		jQuery("#nico_theme_editor ._font_select").on("change", function() 
		{
				var element = $(this);
				if (jQuery("._font_" + this.value).length == 0)
				{
					var font = normalize_string(this.value);
					$('body').append('<link class="_font_' + this.value + '" rel="stylesheet" href="https://fonts.googleapis.com/css?family=' + this.value + '" type="text/css" />');
				}			

				jQuery(element.attr("selector")).css({fontFamily:this.value});
				
				if (!_nico_changes["fonts"]) _nico_changes["fonts"] = {};
				if (!_nico_changes["fonts"][element.attr("selector")]) _nico_changes["fonts"][element.attr("selector")] = {};				
				_nico_changes['fonts'][element.attr("selector")]['font-family'] = this.value;

/*				if (!_nico_changes["fonts"]) _nico_changes["fonts"] = {};
				_nico_changes['fonts'][element.attr("selector")] = this.value;*/
		});
		
		jQuery("#nico_theme_editor ._font_select_size").on("change", function() 
		{
				var element = $(this);
				jQuery(element.attr("selector")).css({fontSize:this.value + "px"});
				
				if (!_nico_changes["fonts"]) _nico_changes["fonts"] = {};
				if (!_nico_changes["fonts"][element.attr("selector")]) _nico_changes["fonts"][element.attr("selector")] = {};				
				_nico_changes['fonts'][element.attr("selector")]['size'] = this.value;
		});
}

var _backgrounds_first_load = true;
var _colors_first_load = true;
var _fonts_first_load = true;

function init_editor()
{
	$(".nico_tab").eq(0).show();
	
	jQuery("#nico_save_settings").on("click", function(e) 
		{
			if (_nico_changes)
			{
				_nico_changes["_nico_save_theme"] = true;
				nico_save_theme();
				
			} else
			{
				alert("Nothing to save, make some changes first");	
			}
			e.preventDefault();
			return false;
		});
		
		jQuery("#nico_reset").on("click", function(e) 
		{
			_nico_changes["_nico_reset_theme"] = true;
			nico_save_theme();
			e.preventDefault();
			return false;
		});
		
	
		$(".nico_tabs li").click(function(e) 
		{
			e.preventDefault();
			
			if (_backgrounds_first_load && this.innerHTML == "Background")
			{
				jQuery(".nico_status").text("Loading background patterns ...").show();
				_backgrounds_first_load = false;
				 $(".nico_tab > div").hide();
				 window.setTimeout(function() 
				 {
					init_backgrounds();
					$(".nico_tab > div").show();
					jQuery(".nico_status").text("").hide();
				}, 100);
			}
			if (_colors_first_load && this.innerHTML == "Colors")
			{
				jQuery(".nico_status").text("Loading colors ...").show();
				_colors_first_load = false;
				 window.setTimeout(function() 
				 {
					init_colors();
					jQuery(".nico_status").text("").hide();
				}, 100);
			}
			if (_fonts_first_load && this.innerHTML == "Fonts")
			{
				jQuery(".nico_status").text("Loading fonts ...").show();
				_fonts_first_load = false;
				 window.setTimeout(function() 
				 {
					init_fonts();
					jQuery(".nico_status").text("").hide();
				}, 100);
			}		  
			
		  var index = $(".nico_tabs li").removeClass("selected").index(this);
		  $(this).addClass("selected");
		  $(".nico_tab").hide().eq(index).show();
		});
		
		
		$(".nico_slide_text li").click(function(e) 
		{
		  var index = $(".nico_slide_text li").removeClass("selected").index(this);
		  $(this).addClass("selected");
		  $("div.nico_slide_text").hide().eq(index).show();
		});
		
		$("div.nico_slide_text").eq(0).show();
			
		jQuery("#nico_theme_editor .setting .value input[type=text]").on("keyup", function() 
		{
				var element = $(this);
				var attribute = element.attr("attribute");
				if (attribute == 'text')
				{
					jQuery(element.attr("selector")).text(this.value);
				} else
				{
					jQuery(element.attr("selector")).attr(attribute, this.value);
				}
				
				if (!_nico_changes["settings"]) _nico_changes["settings"] = {};
				_nico_changes['settings'][element.attr("name")] = this.value;
		});
		
		jQuery("#nico_theme_editor .setting .value input[type=checkbox]").on("change", function() 
		{
				var element = $(this);
				var attribute = element.attr("attribute");
				if (attribute == 'text')
				{
					jQuery(element.attr("selector")).text(this.value);
				} else
				{
					jQuery(element.attr("selector")).attr(attribute, this.value);
				}
				
				if (!_nico_changes["settings"]) _nico_changes["settings"] = {};
				_nico_changes['settings'][element.attr("name")] = this.checked;
		});
		
				
		jQuery("#nico_theme_editor .setting .value textarea, #nico_theme_editor .setting .value select").on("change", function() 
		{
				var element = $(this);
				var attribute = element.attr("attribute");
				if (attribute == 'text')
				{
					jQuery(element.attr("selector")).text(this.value);
				} else
				{
					jQuery(element.attr("selector")).attr(attribute, this.value);
				}
				
				if (!_nico_changes["settings"]) _nico_changes["settings"] = {};
				_nico_changes['settings'][element.attr("name")] = this.value;
		});
		
		/* ---- */
		jQuery("#nico_theme_editor .slider .value input[type=text]").on("keyup", function() 
		{
				var element = $(this);
				var attribute = element.attr("attribute");
				var page = element.attr("page");
				var slider = element.attr("slider");
				
				if (attribute == 'text')
				{
					jQuery(element.attr("selector")).text(this.value);
				} else
				{
					jQuery(element.attr("selector")).attr(attribute, this.value);
				}
				
				if (!_nico_changes["sliders"]) _nico_changes["sliders"] = {};
				if (!_nico_changes["sliders"][page]) _nico_changes["sliders"][page] = {};
				if (!_nico_changes["sliders"][page][slider]) _nico_changes["sliders"][page][slider] = {};
				
				_nico_changes['sliders'][page][slider][element.attr("_name")] = this.value;
		});
				
		jQuery("#nico_theme_editor .label_option input[type=radio], #nico_theme_editor .slider .value input[type=checkbox], #nico_theme_editor .slider .value input[type=radio]").on("change", function() 
		{
				var element = $(this);
				var attribute = element.attr("attribute");
				var page = element.attr("page");
				var slider = element.attr("slider");
				
				if (attribute == 'text')
				{
					jQuery(element.attr("selector")).text(this.value);
				} else
				{
					jQuery(element.attr("selector")).attr(attribute, this.value);
				}
				
				if (!_nico_changes["sliders"]) _nico_changes["sliders"] = {};
				if (!_nico_changes["sliders"][page]) _nico_changes["sliders"][page] = {};
				if (slider && !_nico_changes["sliders"][page][slider]) _nico_changes["sliders"][page][slider] = {};
				
				var value = '';
				if (this.type == "checkbox") value = this.checked; else value = this.value;
				if (!slider) _nico_changes['sliders'][page]['active'] = this.value;
				else _nico_changes['sliders'][page][slider][element.attr("_name")] = value;
		});
		
		jQuery("#nico_theme_editor .slider .value select").on("change", function() 
		{
			var element = jQuery(this);
			var page = element.attr("page");
			var slider = element.attr("slider");			
			
			if (!_nico_changes["sliders"]) _nico_changes["sliders"] = {};
			if (!_nico_changes["sliders"][page]) _nico_changes["sliders"][page] = {};
			if (!_nico_changes["sliders"][page][slider]) _nico_changes["sliders"][page][slider] = {};
				
			_nico_changes['sliders'][page][slider][element.attr("_name")] = element.val();
		});
		
				
		jQuery("#nico_theme_editor .slider .value textarea").on("change", function() 
		{
				var element = $(this);
				var attribute = element.attr("attribute");
				var page = element.attr("page");
				var slider = element.attr("slider");
				
				if (attribute == 'text')
				{
					jQuery(element.attr("selector")).text(this.value);
				} else
				{
					jQuery(element.attr("selector")).attr(attribute, this.value);
				}
				
				if (!_nico_changes["sliders"]) _nico_changes["sliders"] = {};
				if (!_nico_changes["sliders"][page]) _nico_changes["sliders"][page] = {};
				if (!_nico_changes["sliders"][page][slider]) _nico_changes["sliders"][page][slider] = {};
				
				_nico_changes['sliders'][page][slider][element.attr("_name")] = this.value;
		});
				
		
		/*jQuery("#nico_theme_editor .option select.value").each(function() 
		{
			var element = jQuery(this);
			element.val(jQuery(element.attr("selector")).css(element.attr("attribute")));
		});*/
					
		jQuery("#nico_theme_editor .option select.value").on("change", function() 
		{
			var element = jQuery(this);
			jQuery(element.attr("selector")).css(element.attr("attribute"), this.value);
			
			if (!_nico_changes["options"]) _nico_changes["options"] = {};
			if (!_nico_changes["options"][element.attr("selector")]) _nico_changes["options"][element.attr("selector")] = {};				
			_nico_changes['options'][element.attr("selector")][element.attr("attribute")] = this.value;
		});
		
		
		_nico_changes['styles']= {};
		var _css_backup = {};
		jQuery("#nico_theme_editor .style .value").hover(
		  function (e) 
		  {
			var $this = jQuery(this);  
			var group = $this.attr("group");
			var css = jQuery('#_style_css_' + group);
			var css_file =  $this.attr("css");
			
			if (css.length)
			{
				_css_backup[group] = css.attr("href");
				css.attr("href", css_file);
			} else
			{	
				_css_backup[group] = '';
				$('body').append('<link id="_style_css_' + group + '" rel="stylesheet" href="' + css_file + '" type="text/css" />');			  
			}
			  
		  }, 
		  function (e) 
		  {
			var $this = jQuery(this);  
			var group = $this.attr("group");
			var css = jQuery('#_style_css_' + group);

			css.attr("href", _css_backup[group]);
		  }
		).click(function (e)
		{
			var $this = jQuery(this);  
			var group = $this.attr("group");
			var css = jQuery('#_style_css_' + group);
			var css_file =  $this.attr("css");
			var file =  $this.attr("file");
			
			css.attr("href", css_file);
			_css_backup[group] = css_file;
			_nico_changes['styles'][group] = file;
			
			jQuery("#nico_theme_editor .style .value." + group).removeClass("selected");
			$this.addClass("selected")
		});
}

var _scroll_timer;
function nico_import_start()
{
	if (_nico_demo)
	{
		jQuery(".nico_status").text(_nico_save_message).show()
		
		_nico_changes = {};
		_nico_changes['styles'] = {};
		setTimeout('jQuery(".nico_status").text("").hide();', 2000);
		return;
	}
	
	$('#import_modal .modal-body').html('<iframe style="width:100%;" frameborder="0" src="index.php?route=module/nicoimport&' + jQuery(".nico_import_tab input, .nico_import_tab select").serialize() + '&rand=' + Math.random() + '"></iframe>');
	//console.log('<iframe style="width:100%;" frameborder="0" src="index.php?route=module/nicoimport&' + jQuery(".nico_import_tab input, .nico_import_tab select").serialize() + '&rand=' + Math.random() + '"></iframe>');
	$('#import_modal').modal('toggle');
	
	$('#import_modal iframe').load(function () 
	{
		var $contents = $('#import_modal iframe').contents();
		if ($contents.length)
		$contents.scrollTop($contents.height());
		clearInterval(_scroll_timer);
	});
	
	_scroll_timer = setInterval(function ()
	{
			var $contents = $('#import_modal iframe').contents();
			if ($contents.length)
			$contents.scrollTop($contents.height());
	}, 500);


	/*
	jQuery(".nico_status").text('Initializing data import ...').show();
	$.ajax({
	  type:"POST",
	  dataType: "jsonp",
	  url: store_path,
	  context: document.body
	}).done(function(data) 
	{ 
		if (data.error) 
		{
			jQuery(".nico_status").text("").hide();

			$('#import_modal .modal-body').html('<h1>' + data.error + '</h1>');
			$('#import_modal').modal('toggle');

			if (data.import)
			{
				nico_import();
			}
		}
	});*/	
}

function nico_import()
{
	jQuery(".nico_status").text("").hide();
	$('#import_modal').modal('toggle');
	message = $('#import_modal .modal-body');

	message.append('<div>Purchase code ok</div><div><strong>Importing modules</strong></div><div>Nico custom products</div>');
	
	 var last_response_len = false;
		$.ajax('catalog/view/theme/x-shop/nico_theme_editor/import.php', {
			xhrFields: {
				onprogress: function(e)
				{
					var this_response, response = e.currentTarget.response;
					if(last_response_len === false)
					{
						this_response = response;
						last_response_len = response.length;
					}
					else
					{
						this_response = response.substring(last_response_len);
						last_response_len = response.length;
					}
					
					message.append(this_response);
					console.log(this_response);
					height = message[0].scrollHeight;
					message.scrollTop(height);
				}
			}
		})
		.done(function(data)
		{
			message.append('Import finished: ' + data);
			console.log('Import finished: ' + data);
		})
		.fail(function(data)
		{
			console.log('Error: ', data);
			message.append('Error: ' + data);
		});
		
		message.append('Download started');

	
}


jQuery(document).ready(function()
{
		var _first_load = true;
		$("#show_hide_editor").on("click", function (e) 
		{
			var editor = jQuery("#nico_theme_editor");
			if (editor.css("height") == '0px')
			{
				jQuery(this).css({marginTop:"-30px", paddingBottom:"50px", opacity:"0.2",'z-index':'-2', 'margin-left':'0px',display:"none"}).text("Hide panel");
				jQuery("body").css("marginBottom", "300px");
				editor.animate({height:"300px"},500, function() { $("#show_hide_editor").fadeIn();});
				$.cookie('editor', 'true');
				if (_first_load)
				{
					_first_load = false;
					
					/*if (!is_writable || !is_writable_css) 
					{
								jQuery(".nico_status").html("<p>File <strong>/nico_theme_editor/settings.inc</strong> and <strong>/nico_theme_editor/editor_settings.css</strong> is not writable by php, <strong>saving will not work</strong>.<br>Set proper permission to make the file writable by php, 0766 if unsure.<br/>Check theme docs for more info.</p>").show();
								setTimeout('jQuery(".nico_status").text("").hide();', 20000);
					}
					*/
					init_editor();
				}
			} else
			{
				jQuery(this).css({marginTop:"-50px",paddingBottom:"50px", opacity:"1",'z-index':'-1', 'margin-left':'10px', display:"none"}).text("Customize theme");
				jQuery("body").css("marginBottom", "0px");
				editor.animate({height:"0px"},500, function() { $("#show_hide_editor").fadeIn();});
				$.cookie('editor', 'false');
			}
			
			e.preventDefault();
			return false;
		});
		if ($.cookie('editor') == "true") $("#show_hide_editor").click();
		
		
		//slider accordion
		$('.nico_tab.sliders div .label_option').click(function() {
			var $parent = this.parentNode;
			var $container = $(this).next();
			jQuery('> div.slider_container', $parent).not($container).slideUp('normal');
			$container.slideDown('normal');
		});
	 
	 
	 
		jQuery("#nico_zoom_bottomscreen").click(function(e) 
		{
			var editor = jQuery("#nico_theme_editor");
			var show_hide_editor = jQuery("#show_hide_editor");
			var prev_height = jQuery(".nico_tab").height();
			var height = 255;
			
			editor.animate({height:"300px"},500, function() 
			{ 
				if (prev_height > height)
				{
					jQuery(".nico_tab").css({height:height + "px"});					
				}
			});

			if (prev_height <= height)
			{
				jQuery(".nico_tab").css({height:height + "px"});					
			}
			
			//show_hide_editor.css({marginTop:"-50px",paddingBottom:"50px", opacity:"1", display:"none"}).text("Customize theme");
			editor.animate({height:"300px"},500);
			
			e.preventDefault();
			return false;
		});


		jQuery("#nico_zoom_halfscreen").click(function(e) 
		{
			var editor = jQuery("#nico_theme_editor");
			var prev_height = jQuery(".nico_tab").height();
			var height = ($(window).height() / 2) -45;
			
			editor.animate({height:"50%"},500, function() 
			{ 
				if (prev_height > height)
				{
					jQuery(".nico_tab").css({height:height + "px"});					
				}
			});

			if (prev_height <= height)
			{
				jQuery(".nico_tab").css({height:height + "px"});					
			}


			e.preventDefault();
			return false;
		});



		jQuery("#nico_zoom_fullscreen").click(function(e) 
		{
			var editor = jQuery("#nico_theme_editor");
			var prev_height = jQuery(".nico_tab").height();			
			var height = ($(window).height()) -45;
			
			editor.animate({height:"98%"},500, function() {
				if (prev_height > height)
				{
					jQuery(".nico_tab").css({height:height + "px"});					
				}
			});
			
			if (prev_height < height)
			{
				jQuery(".nico_tab").css({height:height + "px"});					
			}
			
			e.preventDefault();
			return false;
		});
/*		
		jQuery(".nico_add_slide").click(function (e)
		{
			e.preventDefault();
			var lang = this.getAttribute("lang");
			jQuery("div.nico_slide_text.lang_" + lang).append(_slide_text_template.replace("slider_text","slider_text lang_" + lang));
			return false;
		});
		
		jQuery(".nico_remove_slide").click(function (e)
		{
			e.preventDefault();
			var lang = this.getAttribute("lang");
			jQuery("div.nico_slide_text.lang_" + lang + " .slider_text:last-child").remove();
			return false;
		});
		
		var tree = $("#nico_menu");
		
	
		jQuery("#nico_menu").on("click", ".remove", function() {
			var node = this.parentNode.parentNode;
			if (confirm("Are you sure you want to remove this menu item and all it's submenus?") && tree.jstree("remove", node))
			{
			}
		});
		
		jQuery("#nico_menu").on("click", ".add_subcat", function() {
			jQuery("a", node).removeClass("jstree-clicked");

			var node = this.parentNode.parentNode;
			tree.jstree("create", node, "last","Menu item",  
				function(obj, name) {
					var clone = jQuery(".nico_new_menu_item_template").clone().attr("class","");
					jQuery("a",obj).addClass("jstree-clicked").after(clone);
					jQuery("input[name="+ current_lang + "]", obj).focus();
				}, true);
				
			return false;
		});
		
		jQuery(".nico_menu").on("click", "#nico_add_menu_item",function() 
		{
				jQuery(".jstree-clicked").removeClass("jstree-clicked");
				tree.jstree("create", -1, "last","Menu item",  
				function(obj, name) {
					var clone = jQuery(".nico_new_menu_item_template").clone().attr("class","");
					jQuery("a",obj).addClass("jstree-clicked").after(clone);
					jQuery("input[name="+ current_lang + "]", obj).focus();
				}, true);
				
				return false;
		});		
		
		jQuery(".nico_menu").on("click", "#nico_add_ocmenu_item",function() 
		{
				jQuery(".jstree-clicked").removeClass("jstree-clicked");
				tree.jstree("create", -1, "last","Opencart categories",  
				function(obj, name) {
					jQuery(obj).addClass("categories");;
					var clone = jQuery(".nico_new_menu_item_template").clone().attr("class","");
					jQuery("a",obj).addClass("jstree-clicked").after(clone);
					jQuery("input[name="+ current_lang + "]", obj).focus();
				}, true);
				
				return false;
		});			

		$("#nico_menu").jstree({"plugins" : [ "themes", "html_data", "cookie", "ui", "dnd", "crrm" ],
					"themes" : {
					"theme" : "default",
					"dots" : false}});
		
		jQuery("#nico_menu").on("keyup", "input[name="+ current_lang + "]", function (e) {jQuery(".jstree-clicked ins").get(0).nextSibling.textContent = this.value});*/
});
