(function() {	
	tinymce.create('tinymce.plugins.ya_Shortcodes', {
		init : function(ed, url){
			//do nothing
		},
		createControl : function(btn, e) {
			if ( btn == "ya_shortcodes_button" ) {
				var a = this;	
				var btn = e.createSplitButton('ya_button', {
	                title: "Insert Shortcode",
					image: yaShortcodesVars.url,
					icons: false,
	            });
	            btn.onRenderMenu.add(function (c, b) {
					a.render( b, "Icon", "icon" );
					a.render( b, "Buttons Type", "buttons" );
					a.render( b, "Alert", "alert" );
					a.render( b, "Bloginfo", "bloginfo" );
					a.render( b, "Row", "row" );
					a.render( b, "Column", "col" );
					a.render( b, "Google Map", "googlemap" );
					a.render( b, "Tabs", "tabs" );
					a.render( b, "Collapse", "collapse" );
					a.render( b, "Slideshow", "slideshow" );
					a.render( b, "Breadcrumb", "breadcrumb" );
				});
	            
	          return btn;
			}
			return null;               
		},
		render : function(ed, title, id) {
			ed.add({
				title: title,
				onclick: function () {
					
					// Icon
					if(id == "icon") {
						tinyMCE.activeEditor.selection.setContent('[icon name="*"]');
					}
					
					// Buttons Type
					if(id == "buttons") {
						tinyMCE.activeEditor.selection.setContent('[button id="" class="btn" type="primary" target="" href="#" tag="span"]link[/button]');
					}
					
					// Alert
					if(id == "alert") {
						tinyMCE.activeEditor.selection.setContent('[alert class="alert" type="success" dismiss="true" tag="div"][/alert]');
					}
					
					// Row
					if(id == "row") {
						tinyMCE.activeEditor.selection.setContent('[row class="" type="fluid" tag="div"][/row]');
					}
					
					// Column
					if(id == "col") {
						tinyMCE.activeEditor.selection.setContent('[col class="" tag="div" span="6"][/col]');
					}
					
					// Site URL
					if(id == "bloginfo") {
						tinyMCE.activeEditor.selection.setContent('[bloginfo show="wpurl" filter="raw"]');
					}
					
					// Google Map
					if(id == "googlemap") {
						tinyMCE.activeEditor.selection.setContent('[googlemaps title="Envato Office" location="Hoan Kiem District, Hanoi, Vietnam" zoom="10" Width="100%" height=250]');
					}
					
					// Tab
					if(id == "tabs") {
						tinyMCE.activeEditor.selection.setContent('[tabs position="top" class="tabs" tag="div"]<br />[tab title="Section 1"]Tab Content 1[/tab]<br />[tab title="Section 2"]Tab Content 2[/tab]<br />[tab title="Section 3"]Tab Content 3[/tab]<br />[/tabs]');
					}
					
					// Collapse
					if(id == "collapse") {
						tinyMCE.activeEditor.selection.setContent('[collapses class="collapses" tag="div"]<br/>[collapse title="Section 1"]Accordion Content 1[/collapse]<br/>[collapse title="Section 2"]Accordion Content 2[/collapse]<br/>[collapse title="Section 3"]Accordion Content 3[/collapse]<br/>[/collapses]');
					}
					
					// Slideshow
					if(id == "slideshow") {
						tinyMCE.activeEditor.selection.setContent('[slideshow ids="" caption="true" size="medium" interval="5000" event="slide" class=""]');
					}
					
					// Breadcrcumb
					if(id == "breadcrumb") {
						tinyMCE.activeEditor.selection.setContent('[breadcrumb class="breadcrumbs" tag="div"]');
					}
					
					return false;
				}
			})
		}
	
	});
	tinymce.PluginManager.add("ya_shortcodes", tinymce.plugins.ya_Shortcodes);
})();  