jQuery(document).ready(function(){
    jQuery('#shortcode_generator_list > div').css('display','none');
    jQuery('#shortcode_selector').change(function(){
        jQuery('#shortcode_generator_list > div').css('display','none');
        jQuery('#shortcode_'+jQuery(this).val()).css('display','block');
    });
	
	jQuery('#Shortcodes').each(function()
    {
        //Home page item selection
        var class1 = "#style_shortcodeColumns1";
        var class2 = "#style_shortcodeColumns2";
        var container = jQuery(this),
        superselector = container.find('#style_shortcodeColumns0');
        baseVal = superselector.val();
        if(baseVal == 'Fullwidth')
            container.find(class1).css("display","none");
        else if(baseVal == 'Sidebar')
            container.find(class2).css("display","none");
        else
            container.find(class1+", "+class2).css("display","none");
        superselector.bind("change", function()
        {
            var newValue = superselector.val();
            //find all subSelects and subInputs and show only the selected one
            container.find(class1+", "+class2).css("display","none");
            //set the new value for the input field
            if (newValue == 'Fullwidth')
                container.find(class1).fadeIn(); 
			else if (newValue == 'Sidebar')
                container.find(class2).fadeIn();
            //hiddenValue.val(newValue);
            baseVal = newValue;
        });
		
		var class3 = ".style_shortcode_videoimage";
		var container1 = jQuery(this),
		superselector1 = container1.find('#style_shortcodeVideo0');
		baseVal1 = superselector1.val();
		if(baseVal1 != 'html5')
            container1.find(class3).css("display","none");
		superselector1.bind("change", function()
		{
            var newValue1 = superselector1.val();
            container1.find(class3).css("display","none");
            if (newValue1 == 'html5')
                container1.find(class3).fadeIn(); 
            baseVal1 = newValue1;
        });
			
    });
});
function insertShortcode() {
    var item = "";
    var parent = document.getElementById('style_shortcode');
    var ShortCodeId = parent.value;
    if (ShortCodeId != 'Select Shortcode' && ShortCodeId != '' )
    {
        tagtext = "";
        try
        {
            for(i=0; i<document.getElementById('sssss'+ShortCodeId).value; i++)
            {
                styleId = "style_shortcode"+ShortCodeId+i;
                var el = document.getElementById(styleId);
                var option = el.name;
                var value = el.value;
                var count = el.value;
                var row;
                var column;
                tagtext += " "+option+"="+value;
                if( ShortCodeId == 'List' )
                {
                    if (i == 1)
                    {
                        tagtext = "";
                        tagtext = " "+option+"="+value;
                    }
                    else
                        var counter = el.value;
                }
                if( ShortCodeId == 'Table' )
                {
                    if (i == 0)
                        row = el.value;
                    else
                        column = el.value;
                }
            }
            ShortCodeId = ShortCodeId.toLowerCase();
            if( ShortCodeId == 'list' )
            {
                for ( i=0; i<counter; i++)
                {
                    item +=" [li]Insert your text here[/li]<br/>"
                }
                tagtext =" ["+ ShortCodeId + tagtext + "]<br/>"+item+"[/" + ShortCodeId + "]";
            }
            else if( ShortCodeId == 'toggle' )
            {
                for ( i=0; i<count; i++)
                {
                    item +=" [toggle title=\"toggle title\"]Insert your text here[/toggle]<br>"
                }
                tagtext = item;
            }
            else if( ShortCodeId == 'tab' )
            {
                item +=" [tab_container]<br />";
                for ( i=1; i<=count; i++)
                {
                    item +=" [tab title=\"title"+i+"\"]Insert your text here[/tab]<br>";
                }
                item +="[/tab_container]";
                tagtext = item;
            }
            else if( ShortCodeId == 'accordion' )
            {
                item +=" [accordion]<br />";
                for ( i=1; i<=count; i++)
                {
                    item +=" [a_tab title=\"title"+i+"\"]Insert your text here[/a_tab]<br>";
                }
                item +="[/accordion]";
                tagtext = item;
            }
            else if( ShortCodeId == 'table' )
            {
                tagtext = "<table class=\"Pricing\" border='1'>";
                var singlenode = "";
                for (i=0;i<row;i++)
                {
                    singlenode = "";
                    for (j=0;j<column;j++)
                    {
                        if(i==0)
                            singlenode += "<th>Your title</th>";
                        else if(i==row-1)
                            singlenode += "<th>Your footer</th>";
                        else
                            singlenode += "<td>Your data</td>";
                    }
                    if(i==0)
                        tagtext = tagtext + "<thead><tr class=\"title\">"+singlenode+"</tr></thead>";
                    else if(i==row-1)
                        tagtext = tagtext + "<tfoot><tr class=\"title\">"+singlenode+"</tr></tfoot>";
                    else
                        tagtext = tagtext + "<tbody><tr class=\"title\">"+singlenode+"</tr></tbody>";
                }
                tagtext = tagtext + "</table>";
            }
            else
            {
                tagtext = " ["+ ShortCodeId + tagtext + "]Insert your text here[/" + ShortCodeId + "]";
            }
            window.tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, tagtext);
            tinyMCEPopup.close();
        }
        catch(err)
        {
            ShortCodeId = ShortCodeId.toLowerCase();
            if( ShortCodeId == 'tooltip' )
            {
                tagtext = " ["+ ShortCodeId + " alt=\"Your tooltip text\"]Insert your text here[/" + ShortCodeId + "]";
            }
            else if( ShortCodeId == 'button' )
            {
            tagtext = " ["+ ShortCodeId + " link=\"Your Link\"]Button text[/" + ShortCodeId + "]";
            }
            else if( ShortCodeId == 'seperator' )
            {
                tagtext = "<hr class=\"hrFullWidth\"/>";
            }
            else if( ShortCodeId == 'contact' )
            {
                tagtext = " [contact email=YOUR E-MAIL]";
            }
            else
            {
                tagtext = " ["+ ShortCodeId + tagtext + "]Insert your text here[/" + ShortCodeId + "]";
            }
            window.tinyMCE.execInstanceCommand('content', 'mceInsertContent', false, tagtext);
            tinyMCEPopup.close();
        }
    }
}



