/*
 *  For wordpress >=3.9 (tinemce 4+)
 * 
 */


tinymce.PluginManager.add('jaw_shortcodes', function(editor, url) {// Add a button that opens a window
    editor.addButton('jaw_shortcodes', {
        title: 'Insert Shortcode', 
        icon: 'jawshortcodeicon',
        type: 'menubutton', menu: [
            /* START COLUMNS **************************************/
            {text: 'Columns',
                menu: [
                    {text: 'One Half',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[one_half]' + tinymce.activeEditor.selection.getContent() + '[/one_half]');
                        }
                    },
                    {text: 'One Half Last',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[one_half_last]' + tinymce.activeEditor.selection.getContent() + '[/one_half_last]');
                        }
                    },
                    {text: 'One Third',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[one_third]' + tinymce.activeEditor.selection.getContent() + '[/one_third]');
                        }
                    },
                    {text: 'One Third Last',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[one_third_last]' + tinymce.activeEditor.selection.getContent() + '[/one_third_last]');
                        }
                    },
                    {text: 'Two Third',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[two_third]' + tinymce.activeEditor.selection.getContent() + '[/two_third]');
                        }
                    },
                    {text: 'Two Third Last',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[two_third_last]' + tinymce.activeEditor.selection.getContent() + '[/two_third_last]');
                        }
                    }, {text: 'One Fourth',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[one_fourth]' + tinymce.activeEditor.selection.getContent() + '[/one_fourth]');
                        }
                    },
                    {text: 'One Fourth Last',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[one_fourth_last]' + tinymce.activeEditor.selection.getContent() + '[/one_fourth_last]');
                        }},
                    {text: 'Three Fourth',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[three_fourth]' + tinymce.activeEditor.selection.getContent() + '[/three_fourth]');
                        }
                    },
                    {text: 'Three Fourth Last',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[three_fourth_last]' + tinymce.activeEditor.selection.getContent() + '[/three_fourth_last]');
                        }
                    },
                    {text: 'One Fifth',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[one_fifth]' + tinymce.activeEditor.selection.getContent() + '[/one_fifth]');
                        }
                    }, {text: 'One Fifth Last',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[one_fifth_last]' + tinymce.activeEditor.selection.getContent() + '[/one_fifth_last]');
                        }
                    },
                    {text: 'Two Fifth',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[two_fifth]' + tinymce.activeEditor.selection.getContent() + '[/two_fifth]');
                        }
                    },
                    {text: 'Two Fifth Last',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[two_fifth_last]' + tinymce.activeEditor.selection.getContent() + '[/two_fifth_last]');
                        }
                    },
                    {text: 'Three Fifth',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[three_fifth]' + tinymce.activeEditor.selection.getContent() + '[/three_fifth]');
                        }},
                    {text: 'Three Fifth Last', onclick: function() {
                            tinymce.activeEditor.selection.setContent('[three_fifth_last]' + tinymce.activeEditor.selection.getContent() + '[/three_fifth_last]');
                        }
                    },
                    {text: 'Four Fifth',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[four_fifth]' + tinymce.activeEditor.selection.getContent() + '[/four_fifth]');
                        }
                    },
                    {text: 'Four Fifth Last',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[four_fifth_last]' + tinymce.activeEditor.selection.getContent() + '[/four_fifth_last]');
                        }
                    },
                    {text: 'One Sixth',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[one_sixth]' + tinymce.activeEditor.selection.getContent() + '[/one_sixth]');
                        }
                    },
                    {text: 'One Sixth Last',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[one_sixth_last]' + tinymce.activeEditor.selection.getContent() + '[/one_sixth_last]');
                        }
                    },
                    {text: 'Five Sixth',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[five_sixth]' + tinymce.activeEditor.selection.getContent() + '[/five_sixth]');
                        }
                    },
                    {text: 'Five Sixth Last',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[five_sixth_last]' + tinymce.activeEditor.selection.getContent() + '[/five_sixth_last]');
                        }
                    }
                ]
            }
            /* END COLUMNS ****************************************/

            /* LAYOUTS ********************************************/
            , {
                text: 'Layouts',
                menu: [
                    {text: 'Two Columns',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_two_column'
                            })
                        }
                    },
                    {text: 'Three Colums',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_three_column'
                            })
                        }
                    },
                    {text: 'Four Colums',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_four_column'
                            })
                        }
                    },
                    {text: 'Five Colums',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {title: title,
                                identifier: 'l_five_column'
                            })
                        }
                    },
                    {text: 'Six Colums',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_six_column'
                            })
                        }
                    },
                    {text: 'One Third - Two Third',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_one_third_two_third'
                            })
                        }
                    },
                    {text: 'Two Third - One Third',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_two_third_one_third'
                            })
                        }
                    },
                    {text: 'One Fourth - Three Fourth',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_one_fourth_three_fourth'
                            })
                        }
                    },
                    {text: 'Three Fourth - One Fourth',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_three_fourth_one_fourth'
                            })
                        }
                    },
                    {text: 'One Fourth -One Fourth - OneHalf',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_one_fourth_one_fourth_one_half'
                            })
                        }
                    },
                    {text: 'One Fourth - One Half - One Fourth',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_one_fourth_one_half_one_fourth'
                            })
                        }
                    },
                    {text: 'One Half - One Fourth- One Fourth',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_one_half_one_fourth_one_fourth'
                            })
                        }
                    },
                    {text: 'Four Fifth - One Fifth',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_four_fifth_one_fifth'
                            })
                        }},
                    {text: 'One Fifth - Four Fifth',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_one_fifth_four_fifth'
                            })
                        }
                    },
                    {text: 'Two Fifth - Three Fifth',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_two_fifth_three_fifth'
                            })
                        }
                    },
                    {text: 'Three Fifth - Two Fifth',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_three_fifth_two_fifth'
                            })
                        }
                    },
                    {text: 'One Six - Five Six',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_one_sixth_five_sixth'})
                        }
                    },
                    {text: 'Five Six - One Six',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'l_five_sixth_one_sixth'
                            })
                        }
                    },
                    {text: 'One Sixth - One Sixth - One Sixth- One Half',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title, identifier: 'l_one_sixth_one_sixth_one_sixth_one_half'
                            })
                        }
                    }
                ]
            }
            /* END LAYOUTS ****************************************/

            /* START TYPOGRAPHY ***********************************/
            , {
                text: 'Typography',
                menu: [
                    {text: 'Headlines',
                        menu: [
                            {text: 'h1',
                                onclick: function() {
                                    tinymce.activeEditor.selection.setContent('[h1]' + tinymce.activeEditor.selection.getContent() + '[/h1]');
                                }
                            },
                            {text: 'h2',
                                onclick: function() {
                                    tinymce.activeEditor.selection.setContent('[h2]' + tinymce.activeEditor.selection.getContent() + '[/h2]');
                                }
                            }, {text: 'h3',
                                onclick: function() {
                                    tinymce.activeEditor.selection.setContent('[h3]' + tinymce.activeEditor.selection.getContent() + '[/h3]');
                                }
                            },
                            {text: 'h4',
                                onclick: function() {
                                    tinymce.activeEditor.selection.setContent('[h4]' + tinymce.activeEditor.selection.getContent() + '[/h4]');
                                }
                            },
                            {text: 'h5',
                                onclick: function() {
                                    tinymce.activeEditor.selection.setContent('[h5]' + tinymce.activeEditor.selection.getContent() + '[/h5]');
                                }},
                            {text: 'h6',
                                onclick: function() {
                                    tinymce.activeEditor.selection.setContent('[h6]' + tinymce.activeEditor.selection.getContent() + '[/h6]');
                                }
                            }
                        ]
                    },
                    {text: 'Blockquote',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title, identifier: 'blockquote'
                            })
                        }
                    },
                    {text: 'Button', onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'buttons'
                            })
                        }
                    },
                    {text: 'Highlight',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {title: title,
                                identifier: 'highlight'
                            })
                        }
                    },
                    {text: 'Notices',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'notices'
                            })
                        }
                    },
                    {text: 'Pre',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'pre'
                            })
                        }
                    },
                    {text: 'Code',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'code'
                            })
                        }
                    }
                ]
            }
            /* END TYPOGRAPHY *************************************/

            /* START DIVIDERS *************************************/
            , {
                text: 'Dividers',
                menu: [
                    {text: 'Divider To Top',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[divider_to_top]');
                        }
                    },
                    {text: 'Divider Line',
                        onclick: function() {
                            tinymce.activeEditor.selection.setContent('[divider_line]');
                        }
                    },
                    {text: 'Custom Divider Line',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'adv_divider'
                            })
                        }
                    },
                    {text: 'Custom Divider To Top',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'adv_divider_to_top'
                            })
                        }
                    }
                ]
            }
            /* END DIVIDERS ***************************************/

            /* FEATURES *******************************************/
            , {
                text: 'Features',
                menu: [
                    {text: 'Iframe',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'iframe'
                            })
                        }
                    },
                    {text: 'Google Map',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'google_map'
                            })
                        }
                    },
                    {text: 'Tabs',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {title: title,
                                identifier: 'tabs'
                            })
                        }
                    },
                    {text: 'Accordion',
                        onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'accordion'})
                        }
                    },
                    {text: 'Toggle', onclick: function() {
                            tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                title: title,
                                identifier: 'toggle'
                            })
                        }
                    }
                ]
            }
            /* END FEATURES ***************************************/

            /* MEDIA **********************************************/
            , {
                text: 'Media',
                menu: [
                    {text: 'Video',
                        menu: [
                            {text: 'Youtube',
                                onclick: function() {
                                    tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                        title: title,
                                        identifier: 'v_youtube'
                                    })
                                }
                            },
                            {text: 'Vimeo',
                                onclick: function() {
                                    tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                                        title: title,
                                        identifier: 'v_vimeo'
                                    })
                                }
                            }
                        ]
                    }
                ]
            }
            /* END MEDIA ******************************************/
            , {
                text: 'Contact Form',
                onclick: function() {
                    tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                        title: title,
                        identifier: 'contact_form'
                    })
                }
            },
            {text: 'Portfolio',
                onclick: function() {
                    tinyMCE.activeEditor.execCommand("jaw_shortcodes", false, {
                        title: title,
                        identifier: 'portfolio'
                    })
                }
            }

        ]
    });



    editor.addCommand("jaw_shortcodes", function(a, params)
    {
        var code = params.identifier;

        // load thickbox
        tb_show("Insert JaW Shortcode", url + "/jaw_shortcodes_generator.php?code=" + code + "&width=" + 670);

        var id_list = 1;
        jQuery('#TB_window').find('.add-list').live('click', function() {

            jQuery(this).parent().find('.list-li').last().after('<div class="list-li" >'
                    + '<input id="list" class="of-input" type="text" value="" name="' + jQuery(this).attr('id') + '-' + (id_list++) + '">'
                    + '</div>');
        });



    });
});



