jQuery(document).ready(function($) {	
    //tab
    var tabID = 0;
    $('.tabAllHolder').each(function () {
        $(this).attr('id', 'tabs-' + tabID);
        tabID++;
    });

    tabID = 0;
    $('.tabs-container').each(function () {
        $(this).attr('id', 'tabs-' + tabID);
        tabID++;
    });

    (function ($) {

        var titles = new Array();
        var contents = new Array();
        var IDs = new Array();
		
        $(".tabAllHolder").find(".tab-all").each(function () {
            if ($(this).attr("rendered") != "true") {
                var title = $(this).data("title");						
                titles.push(title);
                contents.push($(this).text());
                IDs.push($(this).parent().attr('id'));
				
            }
        });		
		
        $('div').remove('.tabAllHolder');
        $('.tabs-container').each(function () {	
			var tabi = "first";		
            for (var i = 0; i < titles.length; i++) {				
                if (IDs[i] == $(this).attr('id')) {					
					if(tabi!=$(this).attr('id')){
						tabi = ""+ $(this).attr('id');
                    $(this).children('#myTab').append('<li class="active"><a href="#' + i + '" data-toggle="tab"><p class="post-title smaller-title">' + titles[i] + '</p>'+'</a></li>');
                    $(this).children('#myTabContent').append('<div class="tab-pane fade in active" id="'+ i +'"><p class="post-categoty">' + contents[i] + '</p></div>');
                }
				else
				{
				 $(this).children('#myTab').append('<li><a href="#' + i + '" data-toggle="tab"><p class="post-title smaller-title">' + titles[i] + '</p>'+'</a></li>');
                 $(this).children('#myTabContent').append('<div class="tab-pane fade in" id="'+ i +'"><p class="post-categoty">' + contents[i] + '</p></div>');
				}
				}
            }
        });

    })(jQuery);
	
	//accordion
    var accID = 0;
	
    $('.accAllHolder').each(function () {
        $(this).attr('id', 'accordion' + accID);
        accID++;
    });

    accID = 0;
    $('.shortcode').each(function () {
		$(this).attr('id', 'accordion' + accID);
        accID++;
    });

    (function ($) {

        var titles = new Array();
        var contents = new Array();
        var IDs = new Array();
		
        $(".accAllHolder").find(".accHeader").each(function () {
            if ($(this).attr("rendered") != "true") {
                var title = $(this).data("title");
                titles.push(title);
                contents.push($(this).text());
                IDs.push($(this).parent().attr('id'));
				
            }
        });		
		
        $('div').remove('.accAllHolder');
        $('.shortcode').each(function () {	
			var tabi = "first";		
		
            for (var i = 0; i < titles.length; i++) {	
					//console.log($(this).attr('id'));
					//console.log(IDs[i]);
                if (IDs[i] == $(this).attr('id')) {	
									
					if(tabi!=$(this).attr('id')){
						tabi = ""+ $(this).attr('id');
                    $(this).children('#myAcc').append(
					'<div class="accordion-heading acc-heading-color"><a class="accordion-toggle" data-toggle="collapse" data-parent="#'+$(this).attr('id')+'" href="#collapse'+i+'">'
						      + '<p class="post-title smaller-title">'+ titles[i] +'</p></a></div>'+
					'<div id="collapse'+i+'" class="accordion-body in collapse">'+
						      '<div class="accordion-inner">'+
						      	'<div class="acc-container">'+
						      		'<p class="post-categoty acc-inner-text">'+
										 contents[i] + 
						      		'</p></div></div></div>');					
                  
                }
				else
				{
				   $(this).children('#myAcc').append(
					'<div class="accordion-heading acc-heading-color"><a class="accordion-toggle" data-toggle="collapse" data-parent="#'+$(this).attr('id')+'" href="#collapse'+i+'">'
						      + '<p class="post-title smaller-title">'+ titles[i] +'</p></a></div>'+
					'<div id="collapse'+i+'" class="accordion-body collapse">'+
						      '<div class="accordion-inner">'+
						      	'<div class="acc-container">'+
						      		'<p class="post-categoty acc-inner-text">'+
										 contents[i] + 
						      		'</p></div></div></div>');		
				}
				}
            }
        });

    })(jQuery);
});