libPath = CS_ROOT_URL + "library/";
$ = jQuery;
(function($) {
    jQuery.fn.cloudSliderAdmin = function(options) {
        // Bob's default settings:
        var default_items = {
            skins: {
                light_iron: {
                    containerBgColor: '#ccc',
                    containerBorder: '5px',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/light_iron/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/light_iron/left_arrow.png',
                        imgNext: libPath + 'skins/light_iron/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/light_iron/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/light_iron/right_arrow_activated.png',
                        positionOffset: -7,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: -7,
                        itemOpacity: 1,
                        itemMargin: 0,
                        imgItem: libPath + 'skins/light_iron/bullet_item.png',
                        imgItemActivated: libPath + 'skins/light_iron/bullet_item_activated.png',
                        imgContainerLeft: libPath + 'skins/light_iron/bullet_left.png',
                        imgContainerRight: libPath + 'skins/light_iron/bullet_right.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1.5
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: '#AAAAAA',
                        itemOpacity: 0.4,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#FFFFFF',
                        activatedBorderColor: '#FFFFFF',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/light_iron/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                dark_iron: {
                    containerBgColor: '#666666',
                    containerBorder: '5px',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/dark_iron/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/dark_iron/left_arrow.png',
                        imgNext: libPath + 'skins/dark_iron/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/dark_iron/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/dark_iron/right_arrow_activated.png',
                        positionOffset: -7,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: -7,
                        itemOpacity: 1,
                        itemMargin: 0,
                        imgItem: libPath + 'skins/dark_iron/bullet_item.png',
                        imgItemActivated: libPath + 'skins/dark_iron/bullet_item_activated.png',
                        imgContainerLeft: libPath + 'skins/dark_iron/bullet_left.png',
                        imgContainerRight: libPath + 'skins/dark_iron/bullet_right.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1.5
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: '#444444',
                        itemOpacity: 0.4,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#333333',
                        activatedBorderColor: '#333333',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/dark_iron/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                light_glass: {
                    containerBgColor: '#FFFFFF',
                    containerBorder: '6px',
                    containerBoxShadow: '0px 2px 30px 0px #000',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/light_glass/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/light_glass/left_arrow.png',
                        imgNext: libPath + 'skins/light_glass/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/light_glass/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/light_glass/right_arrow_activated.png',
                        positionOffset: 20,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 20,
                        itemOpacity: 1,
                        itemMargin: '0px 5px',
                        imgItem: libPath + 'skins/light_glass/bullet_item.png',
                        imgItemActivated: libPath + 'skins/light_glass/bullet_item_activated.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1.5
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: 'rgba(255, 255, 255, 0.5)',
                        itemOpacity: 0.5,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#FFFFFF',
                        activatedBorderColor: '#FFFFFF',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/light_glass/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                dark_glass: {
                    containerBgColor: '#333333',
                    containerBorder: '6px',
                    containerBoxShadow: '0px 2px 30px 0px #000',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/dark_glass/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/dark_glass/left_arrow.png',
                        imgNext: libPath + 'skins/dark_glass/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/dark_glass/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/dark_glass/right_arrow_activated.png',
                        positionOffset: 20,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 20,
                        itemOpacity: 1,
                        itemMargin: '0px 5px',
                        imgItem: libPath + 'skins/dark_glass/bullet_item.png',
                        imgItemActivated: libPath + 'skins/dark_glass/bullet_item_activated.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1.5
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: 'rgba(0, 0, 0, 0.5)',
                        itemOpacity: 0.5,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#333333',
                        activatedBorderColor: '#333333',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/dark_glass/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                light_rounded_bar: {
                    containerBgColor: '#AAAAAA',
                    containerBorder: '5px',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/light_rounded_bar/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/light_rounded_bar/left_arrow.png',
                        imgNext: libPath + 'skins/light_rounded_bar/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/light_rounded_bar/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/light_rounded_bar/right_arrow_activated.png',
                        positionOffset: 20,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 10,
                        itemOpacity: 1,
                        itemMargin: 0,
                        imgItem: libPath + 'skins/light_rounded_bar/bullet_item.png',
                        imgItemActivated: libPath + 'skins/light_rounded_bar/bullet_item_activated.png',
                        imgContainerLeft: libPath + 'skins/light_rounded_bar/bullet_left.png',
                        imgContainerRight: libPath + 'skins/light_rounded_bar/bullet_right.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: '#AAAAAA',
                        itemOpacity: 0.7,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#333333',
                        activatedBorderColor: '#FFFFFF',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/light_rounded_bar/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                dark_rounded_bar: {
                    containerBgColor: '#333333',
                    containerBorder: '5px',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/dark_rounded_bar/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/dark_rounded_bar/left_arrow.png',
                        imgNext: libPath + 'skins/dark_rounded_bar/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/dark_rounded_bar/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/dark_rounded_bar/right_arrow_activated.png',
                        positionOffset: 20,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 10,
                        itemOpacity: 1,
                        itemMargin: 0,
                        imgItem: libPath + 'skins/dark_rounded_bar/bullet_item.png',
                        imgItemActivated: libPath + 'skins/dark_rounded_bar/bullet_item_activated.png',
                        imgContainerLeft: libPath + 'skins/dark_rounded_bar/bullet_left.png',
                        imgContainerRight: libPath + 'skins/dark_rounded_bar/bullet_right.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: '#333333',
                        itemOpacity: 0.7,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#FFFFFF',
                        activatedBorderColor: '#000000',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/dark_rounded_bar/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                light_bar: {
                    containerBgColor: '#FFFFFF',
                    containerBorder: '5px 5px 20px 5px',
                    containerBoxShadow: '0px 2px 30px 0px #000',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/light_bar/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/light_bar/left_arrow.png',
                        imgNext: libPath + 'skins/light_bar/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/light_bar/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/light_bar/right_arrow_activated.png',
                        positionOffset: 20,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 3,
                        itemOpacity: 1,
                        itemMargin: 0,
                        imgItem: libPath + 'skins/light_bar/bullet_item.png',
                        imgItemActivated: libPath + 'skins/light_bar/bullet_item_activated.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: 'rgba(256, 256, 256, 0.5)',
                        itemOpacity: 0.7,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#FFFFFF',
                        activatedBorderColor: '#000000',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/light_bar/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                dark_bar: {
                    containerBgColor: '#333333',
                    containerBorder: '5px 5px 20px 5px',
                    containerBoxShadow: '0px 2px 30px 0px #000',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/dark_bar/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/dark_bar/left_arrow.png',
                        imgNext: libPath + 'skins/dark_bar/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/dark_bar/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/dark_bar/right_arrow_activated.png',
                        positionOffset: 20,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 3,
                        itemOpacity: 1,
                        itemMargin: 0,
                        imgItem: libPath + 'skins/dark_bar/bullet_item.png',
                        imgItemActivated: libPath + 'skins/dark_bar/bullet_item_activated.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: 'rgba(0, 0, 0, 0.5)',
                        itemOpacity: 0.7,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#000000',
                        activatedBorderColor: '#FFFFFF',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/dark_bar/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                light_tab: {
                    containerBgColor: '#FFFFFF',
                    containerBorder: '5px',
                    containerBoxShadow: '0px 2px 30px 0px #000',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/light_tab/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/light_tab/left_arrow.png',
                        imgNext: libPath + 'skins/light_tab/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/light_tab/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/light_tab/right_arrow_activated.png',
                        positionOffset: 20,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 5,
                        itemOpacity: 1,
                        itemMargin: 0,
                        imgItem: libPath + 'skins/light_tab/bullet_item.png',
                        imgItemActivated: libPath + 'skins/light_tab/bullet_item_activated.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: 'rgba(200, 200, 200, 0.7)',
                        itemOpacity: 0.7,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#FFFFFF',
                        activatedBorderColor: '#000000',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/light_tab/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                dark_tab: {
                    containerBgColor: '#000000',
                    containerBorder: '5px',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/dark_tab/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/dark_tab/left_arrow.png',
                        imgNext: libPath + 'skins/dark_tab/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/dark_tab/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/dark_tab/right_arrow_activated.png',
                        positionOffset: 20,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 5,
                        itemOpacity: 1,
                        itemMargin: 0,
                        imgItem: libPath + 'skins/dark_tab/bullet_item.png',
                        imgItemActivated: libPath + 'skins/dark_tab/bullet_item_activated.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: 'rgba(30, 30, 30, 0.7)',
                        itemOpacity: 0.7,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#FFFFFF',
                        activatedBorderColor: '#000000',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/dark_tab/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                light_outline: {
                    containerBgColor: '#ffffff',
                    containerBorder: '5px',
                    containerBoxShadow: '0px 2px 30px 0px #000',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/light_outline/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/light_outline/left_arrow.png',
                        imgNext: libPath + 'skins/light_outline/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/light_outline/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/light_outline/right_arrow_activated.png',
                        positionOffset: 30,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_right',
                        horizontalOffset: 30,
                        verticalOffset: 20,
                        itemOpacity: 1,
                        itemMargin: 2,
                        imgItem: libPath + 'skins/light_outline/bullet_item.png',
                        imgItemActivated: libPath + 'skins/light_outline/bullet_item_activated.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1.2
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: 'rgba(255, 255, 255, 0.8)',
                        itemOpacity: 0.3,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#FFFFFF',
                        activatedBorderColor: '#FFFFFF',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/light_outline/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                dark_outline: {
                    containerBgColor: '#000000',
                    containerBorder: '5px',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/dark_outline/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/dark_outline/left_arrow.png',
                        imgNext: libPath + 'skins/dark_outline/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/dark_outline/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/dark_outline/right_arrow_activated.png',
                        positionOffset: 30,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_right',
                        horizontalOffset: 30,
                        verticalOffset: 20,
                        itemOpacity: 1,
                        itemMargin: 5,
                        imgItem: libPath + 'skins/dark_outline/bullet_item.png',
                        imgItemActivated: libPath + 'skins/dark_outline/bullet_item_activated.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1.2
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '2px',
                        containerBgColor: '#333333',
                        itemOpacity: 1,
                        itemMargin: '2px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#FFFFFF',
                        activatedBorderColor: '#000000',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/dark_outline/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                stroke: {
                    containerBgColor: '#FFFFFF',
                    containerBorder: '5px',
                    containerBoxShadow: '0px 2px 30px 0px #000',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/stroke/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/stroke/left_arrow.png',
                        imgNext: libPath + 'skins/stroke/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/stroke/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/stroke/right_arrow_activated.png',
                        positionOffset: 40,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 20,
                        itemOpacity: 1,
                        itemMargin: 3,
                        imgItem: libPath + 'skins/stroke/bullet_item.png',
                        imgItemActivated: libPath + 'skins/stroke/bullet_item_activated.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1.5
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: 'transparent',
                        itemOpacity: 0.5,
                        itemMargin: '5px',
                        itemBorderWidth: '4px',
                        itemBorderColor: '#FFFFFF',
                        activatedBorderColor: '#FFFFFF',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/stroke/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                pierced: {
                    containerBgColor: '#FFFFFF',
                    containerBorder: '5px',
                    containerBoxShadow: '0px 2px 30px 0px #000',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/pierced/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/pierced/left_arrow.png',
                        imgNext: libPath + 'skins/pierced/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/pierced/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/pierced/right_arrow_activated.png',
                        positionOffset: -11,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: -12,
                        itemOpacity: 1,
                        itemMargin: 0,
                        imgItem: libPath + 'skins/pierced/bullet_item.png',
                        imgItemActivated: libPath + 'skins/pierced/bullet_item_activated.png',
                        imgContainerLeft: libPath + 'skins/pierced/bullet_left.png',
                        imgContainerRight: libPath + 'skins/pierced/bullet_right.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1.5
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: 'transparent',
                        itemOpacity: 1,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#333333',
                        activatedBorderColor: '#FFFFFF',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/pierced/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                polygon: {
                    containerBgColor: '#CCCCCC',
                    containerBorder: '0px',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/polygon/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/polygon/left_arrow.png',
                        imgNext: libPath + 'skins/polygon/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/polygon/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/polygon/right_arrow_activated.png',
                        positionOffset: 20,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 10,
                        itemOpacity: 1,
                        itemMargin: 1,
                        imgItem: libPath + 'skins/polygon/bullet_item.png',
                        imgItemActivated: libPath + 'skins/polygon/bullet_item_activated.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1.5
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: 'rgba(255, 255, 255, 0.5)',
                        itemOpacity: 0.5,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#FFFFFF',
                        activatedBorderColor: '#FFFFFF',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/polygon/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                embossed: {
                    containerBgColor: '#AAAAAA',
                    containerBorder: '5px',
                    containerBoxShadow: '0px 2px 30px 0px #000',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/embossed/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/embossed/left_arrow.png',
                        imgNext: libPath + 'skins/embossed/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/embossed/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/embossed/right_arrow_activated.png',
                        positionOffset: 20,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 20,
                        itemOpacity: 1,
                        itemMargin: 0,
                        imgItem: libPath + 'skins/embossed/bullet_item.png',
                        imgItemActivated: libPath + 'skins/embossed/bullet_item_activated.png',
                        imgContainerLeft: libPath + 'skins/embossed/bullet_left.png',
                        imgContainerRight: libPath + 'skins/embossed/bullet_right.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1.5
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: '#CCCCCC',
                        itemOpacity: 0.5,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#000000',
                        activatedBorderColor: '#FFFFFF',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/embossed/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                dark_short_bar: {
                    containerBgColor: '#333333',
                    containerBorder: '5px',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/dark_short_bar/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/dark_short_bar/left_arrow.png',
                        imgNext: libPath + 'skins/dark_short_bar/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/dark_short_bar/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/dark_short_bar/right_arrow_activated.png',
                        positionOffset: 20,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 20,
                        itemOpacity: 1,
                        itemMargin: 0,
                        imgItem: libPath + 'skins/dark_short_bar/bullet_item.png',
                        imgItemActivated: libPath + 'skins/dark_short_bar/bullet_item_activated.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1.5
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: 'rgba(0, 0, 0, 0.5)',
                        itemOpacity: 0.5,
                        itemMargin: '5px',
                        itemBorderWidth: '1px',
                        itemBorderColor: '#FFFFFF',
                        activatedBorderColor: '#FFFFFF',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/dark_short_bar/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                },
                'default': {
                    containerBgColor: '#FFF',
                    containerBorder: '5px',
                    containerBoxShadow: '0px 2px 30px 0px #000',
                    progressBarPosition: 'top',
                    progressBarColor: 'rgba(170, 170, 170, 0.5)',
                    progressBarThick: '3px',
                    imgLoader: libPath + 'skins/default/loading.gif',
                    arrow: {
                        imgPrev: libPath + 'skins/default/left_arrow.png',
                        imgNext: libPath + 'skins/default/right_arrow.png',
                        imgPrevActivated: libPath + 'skins/default/left_arrow_activated.png',
                        imgNextActivated: libPath + 'skins/default/right_arrow_activated.png',
                        positionOffset: 30,
                        responsiveLevel: 1.5
                    },
                    bullet: {
                        position: 'bottom_center',
                        horizontalOffset: 0,
                        verticalOffset: 15,
                        itemOpacity: 1,
                        itemMargin: '0px 5px',
                        imgItem: libPath + 'skins/default/bullet_item.png',
                        imgItemActivated: libPath + 'skins/default/bullet_item_activated.png',
                        activatedOpacity: 1,
                        responsiveLevel: 1.5
                    },
                    thumb: {
                        positionOffset: -120,
                        containerPadding: '5px',
                        containerBgColor: 'transparent',
                        itemOpacity: 0.7,
                        itemMargin: '5px',
                        itemBorderWidth: '2px',
                        itemBorderColor: '#FFFFFF',
                        activatedBorderColor: '#FFFFFF',
                        activatedOpacity: 1,
                        imgNoThumb: libPath + 'skins/default/no_thumb.png',
                        responsiveLevel: 1.3
                    }
                }
            },
            trans_2d_ids: new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"),
            trans_3d_ids: new Array("33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"),
            delay: "quite long",
            tabTemplate: "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close' role='presentation'>Remove Tab</span></li>",
            tabs: jQuery(this).find("#slide-tabs").tabs(),            
            isDraggEnabled: false,
            target: null,
            textAreas:new Array('callback-onInit','callback-onResume','callback-onPause','callback-onPrev','callback-onNext','callback-onSlideTo','callback-onSlidingStart','callback-onSlidingComplete','callback-onCloudClick','callback-onCloudHover'),
            codeMirror:new Array()
        };
        var settings = jQuery.extend({}, default_items, options);
        var $body = jQuery('body');
        return this.each(function() {
            // Plugin code would go here...
            /* Convert RGB to Hexadecimal  */
            var mainContainer = jQuery(this);
            var loaderPopup=mainContainer.find(".popup-trans-layer");
            var slideTabs = mainContainer.find("#slide-tabs");

            var strip_html_tags = function(text) {
                text = text.replace(/<script.*/ig, '');
                return text;
            }
            var fnCodeMirror=function(){               
                jQuery.each(settings.textAreas, function(index, item) {
                    var textEditor = document.getElementsByName(item)[0];
                    if (typeof textEditor != 'undefined') {
                        var text=textEditor.value;
                        var codeEditor = CodeMirror.fromTextArea(textEditor, {
                            mode: "javascript",
                            lineNumbers: true,
                            lineWrapping: true,
                            extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
                            foldGutter: true,
                            content: text,
                            matchBrackets: true,
                            gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
                        });
                        codeEditor.setValue(text);
                        settings.codeMirror.push(codeEditor);
                    }
                });                
            }
            var codeMirrorRefresh=function(){
                jQuery.each(settings.codeMirror, function(index, item) {                    
                    item.foldCode(CodeMirror.Pos(0, 0));
                    item.setSize('600','100');                    
                    item.on("change", function(instance,changeObj){                          
                        instance.save();                          
                    });
                    item.refresh();
                });
            }
            var hex2rgb=function (hex) {
                if (hex.lastIndexOf('#') > -1) {
                    hex = hex.replace(/#/, '0x');
                } else {
                    hex = '0x' + hex;
                }
                var r = hex >> 16;
                var g = (hex & 0x00FF00) >> 8;
                var b = hex & 0x0000FF;
                return {r: r, g: g, b: b};
            }

            var rgb2hex = function(rgb) {
                var opacity = parseFloat(rgb.replace(/^.*,(.+)\)/, '$1'));
                rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
                var hex = (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) : '';
                return {
                    hex: hex,
                    opacity: opacity
                };
            }
            /* Convert Hexadecimal to RGBA  */
            var hex2rgba = function(hex, opacity) {
                if (opacity == '') opacity = 1;
                hex = hex.replace('#', '');
                r = parseInt(hex.substring(0, 2), 16);
                g = parseInt(hex.substring(2, 4), 16);
                b = parseInt(hex.substring(4, 6), 16);
                result = 'rgba(' + r + ',' + g + ', ' + b + ', ' + opacity + ')';
                return result;
            }

            var changeBGColor=function(objColor) {
                if (typeof objColor != 'undefined') {
                    var color=objColor.val();
                    if (typeof color != 'undefined') {
                        if (color.indexOf('rgb') != -1) {
                            color = rgb2hex(color);
                        }
                        color=hex2rgba(color,objColor.attr('data-opacity'));
                        mainContainer.find(".preview").css({
                            "background-color": color
                        });
                    }
                }
            }

            var  ChangeUrl= function(page, url) {
                if (typeof (history.pushState) != "undefined") {
                    var obj = { Page: page, Url: url };
                    history.pushState(obj, obj.Page, obj.Url);
                } else {
                    alert("Browser does not support HTML5.");
                }
            }
            window.GetQueryString = function(q) {
                return (function(a) {
                    if (a == "") return {};
                    var b = {};
                    for (var i = 0; i < a.length; ++i) {
                        var p = a[i].split('=');
                        if (p.length != 2) continue;
                        b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
                    }
                    return b;
                })(q.split("&"));
            };
            /* Refreshes Tabs and its attributes  */
            var refreshTabs = function() {
                slideTabs.find('ul li').each(function(i) {
                    jQuery(this).attr('aria-controls', 'tabs-' + (i + 1));
                    jQuery(this).find('a').html("Slide#" + (i + 1)).attr('href', '#tabs-' + (i + 1));
                });
                slideTabs.find('.ui-tabs-panel').each(function(i) {
                    var x=i+1;                    
                    jQuery(this).attr({"slide-id": 'slide-'+ x,"id":'tabs-'+ x});
                    jQuery(this).find('.preview,.duplicate-slide,.2d_trans_ids,.3d_trans_ids,.slide-transition,.all-layer-table').attr('slide-id', 'slide-' + (i + 1));
                    jQuery(this).find('.add-new-layer').attr('id', 'slide-' + (i + 1));
                    jQuery(this).find('.options').filter("[setting='slide-options'],[setting='kenburn-options'],[setting='carousel-options'],[setting='layer-options']").each(function() {
                        jQuery(this).attr('id', jQuery(this).attr('setting') + '-' + (i + 1));
                    });

                });
                slideTabs.tabs().tabs("refresh");
            }
            var fnShowPreview = function(id,jsonData) {
                slidePreview = jQuery("#slider-preview");
                str =  "action=preview_slider&id=" + id + "&allData="+jsonData;
                jQuery.ajax({
                    url: ajaxurl,
                    data: str,
                    method: "POST",
                    async: false,
                    success: function(data) {
                        slidePreview.dialog({
                            modal: true,
                            title: 'Slider Preview',
                            dialogClass: "cs-preview-dialog",
                            width: jQuery(window).width(),
                            height: jQuery(window).height(),
                            draggable: false,
                            position: {
                                my: "top",
                                at: "top",
                                of: window,
                                collision: 'fit'
                            },
                            open: function(event, ui) {
                                loaderPopup.hide();
                                slidePreview.html(data);
                            },
                            close: function(event, ui) {
                                mainContainer.find('input[name="hdnPreview"]').val('');
                                slidePreview.dialog("destroy"); 
                                sliderId='#cloudslider'+jQuery('#editid').val();                               
                                jQuery(sliderId+' *').andSelf().each(function() {
                                    jQuery(this).stop(true, false).removeData().remove();
                                });
                                jQuery(sliderId).cloudKill();
                                slidePreview.remove();                                
                                jQuery("body").append('<div id="slider-preview" title="Slider Preview" class="hidden"></div>');
                                jQuery('.minicolors-input').each(function() {
                                    if (jQuery(this).val().indexOf('rgb') != -1) {
                                        var color = rgb2hex(jQuery(this).val());
                                        jQuery(this).attr('data-opacity', color.opacity);
                                        jQuery(this).val(color.hex);
                                    }
                                });
                            }
                        });
                    }
                });
            }            
            var generate_form_data = function(res) {
                var isPreview = mainContainer.find('#hdnPreview').val() == 'preview' ? 1 : 0;
                var preview = '';
                if (isPreview) { 
                    preview = '&hdnPreview=preview';                    
                }
                var formData=[]; 
                var objects=[];
                mainContainer.find('#slide-tabs > div').each(function(slide) {

                    try {
                        slideno = 0;
                        jQuery(this).find('.slide-property input,.slide-property select,.slide-property textarea').each(function() {
                            input_name = jQuery(this).attr('name');
                            if (jQuery(this).parents(".carousel-level").length > 0) {
                                slideno = jQuery(this).parents("table.carousel-multi-level").find("tr").index(jQuery(this).parents("tr"));                                
                                if (input_name.indexOf("slides[layers]") == -1) {
                                    jQuery(this).attr('data-name', input_name);
                                    jQuery(this).attr('name', 'slides[layers][' + slide + '][properties][carousel-level][' + slideno + '][' + input_name + ']');
                                    slideno++;
                                }
                            } else {                                
                                if (input_name.indexOf("slides[layers]") == -1) {                                    
                                    jQuery(this).attr('name', 'slides[layers][' + slide + '][properties][' + input_name + ']');
                                    jQuery(this).attr('data-name', input_name);
                                }                        
                            }
                        });
                    } catch (exception) {
                        console.log(exception);
                        return false;
                    }
                    try {
                        jQuery(this).find('.all-layer-table .layer').each(function(slide_no) {
                            jQuery(this).find('input,select,textarea,checkbox').each(function() {
                                if (!jQuery(this).hasClass("attach-layer") && !jQuery(this).hasClass("attr-value")) {
                                    name = jQuery(this).attr('name');
                                    if (name.indexOf('slides[layers][' + slide + '][sub_layer]') == -1) {
                                        jQuery(this).attr('data-name', name);
                                        jQuery(this).attr('name', 'slides[layers][' + slide + '][sub_layer][' + slide_no + '][properties][' + name + ']');
                                    }                                    
                                }
                            });
                            jQuery(this).find('.carousel-attr select,.carousel-attr textarea').each(function() {
                                //jQuery(this).attr('data-name', jQuery(this).attr('name'));
                                no = jQuery(this).parents("table.carousel-attr").find("tr").index(jQuery(this).parents("tr"));
                                input_name = jQuery(this).attr('name');
                                if (input_name.indexOf('slides[layers][' + slide + '][sub_layer]') == -1) {
                                    jQuery(this).attr('data-name', input_name);
                                    jQuery(this).attr('name', 'slides[layers][' + slide + '][sub_layer][' + slide_no + '][properties][carousel_attr][' + no + '][' + input_name + ']');
                                }
                            });
                        });

                    } catch (exception) {
                        console.log(exception);
                        return false;
                    }
                });
                try {
                    mainContainer.find('#slider-settings input, #slider-settings select, #slider-settings textarea').each(function() {

                        name = jQuery(this).attr('name');
                        if (name.indexOf("slides[settings]") != -1) {} else {
                            jQuery(this).attr('data-name', jQuery(this).attr('name'));
                            jQuery(this).attr('name', 'slides[settings][' + jQuery(this).attr('name') + ']');
                        }
                    });

                } catch (exception) {
                    console.log(exception);
                    return false;
                }
                try {
                    mainContainer.find('#events input, #events select, #events textarea.cs-textarea').each(function() {
                        name = jQuery(this).attr('name');
                        if (name.indexOf("slides[callbacks]") != -1) {} else {
                            jQuery(this).attr('data-name', jQuery(this).attr('name'));
                            jQuery(this).attr('name', 'slides[callbacks][' + jQuery(this).attr('name') + ']');

                        }
                    });

                    var jsonData=encodeURIComponent(JSON.stringify(jQuery('form#frmslider').serializeJSON()));

                    if (isPreview) {
                        fnShowPreview(res,jsonData);
                        loaderPopup.hide();
                    }
                    else
                        {
                        str =  "type=new&action=save_slider&slider-name=" + jQuery("input[name='slider-name']").val() + "&id=" + res + "&hidden_action=edit&save_slider=1" + preview+'&alldata='+jsonData;
                        jQuery.ajax({
                            url: ajaxurl,
                            data: str,
                            method: "POST",
                            async: false,
                            success: function(response) {
                                if ('SUCCESS' === response) {
                                    if (jQuery('#hdnPreview').val() != 'preview') {                                                            
                                        loaderPopup.find('p.successMsg').html('<strong>Slider saved successfully...<strong>');
                                    }
                                } else {
                                    loaderPopup.find('p.successMsg').html('<strong>Something went wrong, please try again...<strong>');
                                }
                                jQuery('.minicolors-input').each(function() {
                                    if (jQuery(this).val().indexOf('rgb') != -1) {
                                        var color = rgb2hex(jQuery(this).val());
                                        jQuery(this).attr('data-opacity', color.opacity);
                                        jQuery(this).val(color.hex);
                                    }
                                });                
                                setTimeout(function() {
                                    loaderPopup.hide();
                                    loaderPopup.find('p.successMsg').html('<strong>Page is loading, Please wait ...<strong>');
                                }, 1000);
                            },
                            error: function(response) {                                
                                loaderPopup.find('p.successMsg').html('<strong>Something went wrong, please try again...<strong>');
                                setTimeout(function() {
                                    loaderPopup.hide();
                                    loaderPopup.find('p.successMsg').html('<strong>Page is loading, Please wait ...<strong>');
                                }, 1000);
                            }
                        });
                    }

                    jQuery('#frmslider input, #frmslider select, #frmslider textarea').each(function(){
                        var attr = $(this).attr('data-name');
                        if(typeof attr !== typeof undefined && attr !== false){
                            jQuery(this).attr('name', jQuery(this).attr('data-name'));
                            jQuery(this).removeAttr('data-name');
                        }
                    });

                } catch (exception) {
                    console.log(exception);
                    return false;
                }
            }
            /* scale and positioning the background image according to kenburen options */
            var showBackgroundImage = function(url, slide_id, ele) {
                if (url != "none" && url != "") {                    
                    var pv_element = mainContainer.find(".preview[slide-id='" + slide_id + "']");
                    pv_element.find('.main-bg-img').remove();
                    pv_element.prepend("<div layerid='abc' class='main-bg-img'></div>");
                    var pv_bg_image = pv_element.find('.main-bg-img');
                    var slides_options = ele.parents(".slides-options");
                    pv_bg_size=slides_options.find('select.backsize').val();                 
                    pv_bg_image.css("background-image", "url('" + url + "')");
                    if(pv_bg_size=='contain')
                        {
                        pv_bg_image.css("background-size", "contain");
                    }                    
                    pos = "";
                    if (slides_options.find(".is-kenburn").find("input.kenburn").is(":checked")) {
                        //  pos = slides_options.find(".kenburn-setting").find("select[name='position-from']").val();
                        pos = slides_options.find(".kenburn-setting").find("select.position-from").val();
                        if (jQuery.trim(pos) == "top_left_per") {
                            top_pos = slides_options.find(".kenburn-setting").find("input.position-from-top").val();
                            left_pos = slides_options.find(".kenburn-setting").find("input.position-from-left").val();
                            pos = +left_pos + "% " + top_pos + "%";
                        } 
                        else pos = pos.replace("_", " ");
                        pv_bg_image.css("background-position", pos);
                        var ken_scale_form = slides_options.find(".kenburn-setting").find("input.scale-from").val();
                        if (ken_scale_form != "") size_from = ken_scale_form;
                        else size_from = "1";
                        var img = new Image;                       
                        img.onload = function() {
                            if ((img.src != 'undefined') && (img.src != "none")) {
                                calculateScales(size_from, img.width, img.height, pv_bg_image, pv_element);
                            }
                        };
                        img.src = url;
                    }
                    if (ele.parent().find(".delete-img-icon").length == 0) {
                        ele.parent().prepend("<span class='delete-img-icon' layerid='abc'><i class='fa fa-times-circle-o'></i></span>");
                    }
                }
            };
            /* scale background images and position */
            var calculateScales = function(proc, owidth, oheight, opt, pv_element) {
                proc = proc * 100;
                var ow = owidth;
                var oh = oheight;
                var setting_option = mainContainer.find(".settings-option");
                wdth = setting_option.find(".slider-width").val();
                hght = setting_option.find(".slider-height").val();
                if (typeof(wdth) == 'undefined') wdth = pv_element.width();
                if (typeof(hght) == 'undefined') hght = pv_element.height();
                opt.css({
                    "width": wdth + 'px',
                    "height": hght + 'px'
                });
                if (owidth / oheight > wdth / hght) {
                    //var factor = (opt.width() /ow);
                    var factor = (hght / oh);
                    var nwidth = ow * factor;
                    //var hfactor = (nheight / opt.height())*proc;
                    var wfactor = (nwidth / wdth) * proc;
                    opt.css({
                        "background-size": wfactor + "% " + proc + "%"
                    });
                } else {
                    //var factor = (opt.width() /ow);
                    var factor = (wdth / ow);
                    var nheight = oh * factor;
                    //var hfactor = (nheight / opt.height())*proc;
                    var hfactor = (nheight / hght) * proc;
                    opt.css({
                        "background-size": proc + "% " + hfactor + "%"
                    });
                }
            }
            var updateCommonLayer = function(slide_id) {
                var preview_panel = mainContainer.find('.ui-tabs-panel[slide-id="' + slide_id + '"] .preview');
                var options_panel = mainContainer.find('.ui-tabs-panel[slide-id="' + slide_id + '"] .slides-options');
                preview_panel.find('.preview_layer').not('.preview-carousel-container,.preview-carousel').each(function() {
                    var layer_id = jQuery(this).attr('layerid');
                    options_panel.find('.attach-layer').each(function() {
                        if (jQuery(this).val() == layer_id) {
                            options_panel.find('tr.layer[id="' + layer_id + '"]').find('.daynamic-content-text').val(jQuery(this).closest('tr').find('.attr-value').val());
                            options_panel.find('tr.layer[id="' + layer_id + '"]').find('.content-subnav a[href="#layer-daynamic-content"]').trigger('click');
                            return false;
                        }
                    });
                });
            };
            var updatePreviewLayerStyle = function(layer_id) {
                var layerSettingPanel = mainContainer.find('tr.layer[id="' + layer_id + '"]');
                var layerPreviewPanel = mainContainer.find('.preview_layer[layerid="' + layer_id + '"]').children();
                layerPreviewPanel.css({
                    width: layerSettingPanel.find('.img-width').val(),
                    height: layerSettingPanel.find('.img-height').val(),
                    top: layerSettingPanel.find('.img-top').val() + layerSettingPanel.find('.img-top').parent().find('.img-top-px').val(),
                    left: layerSettingPanel.find('.img-left').val() + layerSettingPanel.find('.img-left').parent().find('.img-left-px').val(),
                    paddingTop: layerSettingPanel.find('.img-padding-top').val() + 'px',
                    paddingRight: layerSettingPanel.find('.img-padding-right').val() + 'px',
                    paddingBottom: layerSettingPanel.find('.img-padding-bottom').val() + 'px',
                    paddingLeft: layerSettingPanel.find('.img-padding-left').val() + 'px',
                    fontFamily: layerSettingPanel.find('.text-font-family').val(),
                    fontSize: layerSettingPanel.find('.text-font-size').val() + 'px',
                    lineHeight: layerSettingPanel.find('.text-line-height').val()=='Normal'?'Normal': layerSettingPanel.find('.text-line-height').val()+ 'px',
                    borderRadius: layerSettingPanel.find('.rounded-corner').val() + 'px'
                });
                if (layerSettingPanel.find('.text-color').val() != '') {
                    layerPreviewPanel.css({
                        color: hex2rgba(layerSettingPanel.find('.text-color').val(), layerSettingPanel.find('.text-color').attr('data-opacity'))
                    });
                } else {
                    layerPreviewPanel.css({
                        color: '#000000'
                    });
                }
                if (layerSettingPanel.find('.bg-color').val() != '') {
                    layerPreviewPanel.css({
                        backgroundColor: hex2rgba(layerSettingPanel.find('.bg-color').val(), layerSettingPanel.find('.bg-color').attr('data-opacity'))
                    });
                } else {
                    layerPreviewPanel.css({
                        backgroundColor: 'transparent'
                    });
                }
            };
            fixHelperModified = function(evt, trow) {
                var trowClone = trow.clone();
                trowClone.children().each(function(i) {
                    jQuery(this).css({
                        width: trow.children().eq(i).width() + 'px'
                    });
                });
                trowClone.css({ 
                        left: evt.pageX + 'px',
                        top: evt.pageY + 'px' 
                });
                return trowClone;
            };
            hidediv = function(evt, ui) {
                var parent = ui.item.parent(); 
              //  console.log(evt.pageX+'::'+evt.pageY); 
                ui.helper.css({'left':evt.pageX + 'px','top':evt.pageY + 'px'});   
             //   console.log(evt.pageX+'::'+evt.pageY);         
                jQuery('tr.layer', parent).each(function(i) {
                    //jQuery(this).find(".current-layer").hide();
                });
            };

            /* disable carousel options */
            disableCarouselOptions = function(slide_id, layer_id) {
                var slide_tab = jQuery('.ui-tabs-panel[slide-id="' + slide_id + '"]');
                var layer_tab = slide_tab.find('tr.layer[id="' + layer_id + '"]');
                layer_tab.find('.lock-layer').trigger('click');
                layer_tab.find('.highlight-layer').addClass('disabled');

                //disable transition options
                layer_tab.find('.transition table > tbody > tr').each(function() {
                    if (!jQuery(this).hasClass('other_option') && !jQuery(this).hasClass('other-info')) {
                        jQuery(this).find('input, select').each(function() {
                            if (!jQuery(this).hasClass('attach-layer')) {                                                                
                                jQuery(this).attr('disabled','disabled').val('');
                            }
                        })
                    }
                });
                //disable link options
                layer_tab.find('.link input, .link select').each(function() {                                
                    jQuery(this).attr('disabled','disabled').val('');               

                });
                //disable styles options
                layer_tab.find('.styles input, .styles select').each(function() {                    
                    if (!jQuery(this).hasClass('rounded-corner') && !jQuery(this).hasClass('custom-style')) {                     
                        jQuery(this).attr('disabled','disabled').val('');                    
                    }
                });
                //disable content tab (enable only image tab)
                layer_tab.find('.content-subnav a[data-type="span"], .content-subnav a[data-type="html"], .content-subnav a[data-type="dynamic_text"]').each(function() {
                    jQuery(this).removeClass('active').addClass('kr-disabled');
                });
            }
            /* enable carousel options */
            enableCarouselOptions = function(slide_id, layer_id) {
                var slide_tab = jQuery('.ui-tabs-panel[slide-id="' + slide_id + '"]');
                var layer_tab = slide_tab.find('tr.layer[id="' + layer_id + '"]');
                layer_tab.find('.lock-layer').trigger('click');
                layer_tab.find('.highlight-layer').removeClass('disabled');

                //disable transition options
                layer_tab.find('.transition table > tbody > tr').each(function() {
                    if (!jQuery(this).hasClass('other_option') && !jQuery(this).hasClass('other-info')) {
                        jQuery(this).find('input, select').each(function() {
                            if (!jQuery(this).hasClass('attach-layer')) {                                
                                jQuery(this).removeAttr('disabled').val(jQuery(this).attr('data-value'));
                                if(jQuery(this).prop('tagName')=='SELECT')
                                    jQuery(this).trigger('change');
                                else    
                                    jQuery(this).trigger('blur');
                            }
                        })
                    }
                });
                //disable link options
                layer_tab.find('.link input, .link select').each(function() {
                    jQuery(this).removeAttr('disabled').val(jQuery(this).attr('data-value'));
                    if(jQuery(this).prop('tagName')=='SELECT')
                        jQuery(this).trigger('change');
                    else    
                        jQuery(this).trigger('blur');
                });
                //disable styles options
                layer_tab.find('.styles input, .styles select').each(function() {
                    if (!jQuery(this).hasClass('rounded-corner') && !jQuery(this).hasClass('custom-style')) {
                        jQuery(this).removeAttr('disabled').val(jQuery(this).attr('data-value'));
                        if(jQuery(this).prop('tagName')=='SELECT')
                            jQuery(this).trigger('change');
                        else    
                            jQuery(this).trigger('blur');                                                    
                    }
                });
                //disable content tab (enable only image tab)
                layer_tab.find('.content-subnav a[data-type="span"], .content-subnav a[data-type="html"], .content-subnav a[data-type="dynamic_text"]').each(function() {
                    jQuery(this).removeClass('kr-disabled').addClass('active');
                });
            }
            /* arrange carousel layers */
            arrangeCarouselLayers = function(slide_id) {
                if (typeof slide_id != 'undefined' || slide_id != null) {
                    var preview_container = jQuery('.ui-tabs-panel[slide-id="' + slide_id + '"] .preview');
                    var preview_layer = null;
                    jQuery('.ui-tabs-panel[slide-id="' + slide_id + '"]').find('.carousel-layer[type=checkbox]').each(function() {
                        if (jQuery(this).is(':checked')) {
                            preview_layer = preview_container.find('.preview_layer[layerid="' + jQuery(this).closest('.layer').attr('id') + '"]');
                            if (preview_layer != null && typeof preview_layer != 'undefined') {
                                preview_layer.addClass('preview-carousel');

                                if (preview_container.find('.preview-carousel-container').length > 0) {
                                }else {
                                    jQuery('<div class="preview_layer preview-carousel-container kr-carousel-container"><div class="preview-carousel-wrapper"></div></div>').prependTo(preview_container);
                                }
                                preview_layer.appendTo(preview_container.find('.preview-carousel-wrapper'));
                                disableCarouselOptions(slide_id, jQuery(this).closest('.layer').attr('id'));
                            }
                        } else {
                            var preview_layer = preview_container.find('.preview_layer[layerid="' + jQuery(this).closest('.layer').attr('id') + '"]');
                            preview_layer.find('img').css({
                                marginLeft: 0,
                                marginTop: 0
                            });
                            preview_layer.children().draggable().draggable('enable');
                            preview_layer.removeClass('preview-carousel').insertAfter(preview_container.find('.preview-carousel-container'));
                            TweenMax.set(preview_layer, {
                                css: {
                                    scale: 1,
                                    opacity: 1,
                                    rotationX: 0,
                                    rotationY: 0,
                                    rotationZ: 0
                                }
                            });
                            preview_layer.attr('style', '');

                        }
                    });
                    if (preview_container.find('.preview-carousel-wrapper').children().length > 0) {
                        resizeCarouselLayers(slide_id);
                    } else {
                        preview_container.find('.preview-carousel-container').remove();
                    }
                } else {
                    jQuery('.ui-tabs-panel').each(function() {
                        var preview_container = jQuery(this).find('.preview');
                        var slide_id = jQuery(this).attr('slide-id');
                        var preview_layer = null;
                        jQuery(this).find('.carousel-layer[type=checkbox]').each(function() {
                            if (jQuery(this).is(':checked')) {
                                preview_layer = preview_container.find('.preview_layer[layerid="' + jQuery(this).closest('.layer').attr('id') + '"]');
                                preview_layer.addClass('preview-carousel');
                                preview_layer.data('style', preview_layer.attr('style'));

                                if (preview_container.find('.preview-carousel-container').length > 0) {
                                }else {
                                    jQuery('<div class="preview_layer preview-carousel-container"><div class="preview-carousel-wrapper"></div></div>').prependTo(preview_container);
                                }
                                preview_layer.appendTo(preview_container.find('.preview-carousel-wrapper'));
                                disableCarouselOptions(slide_id, jQuery(this).closest('.layer').attr('id'));
                            }
                        });
                        if (preview_container.find('.preview-carousel-wrapper').children().length > 0) {
                            resizeCarouselLayers(slide_id);
                        }
                    });
                }
            };

            resizeCarouselLayers = function(slide_id) {
                var slide_tab = jQuery('.ui-tabs-panel[slide-id="' + slide_id + '"]');
                var preview_container = slide_tab.find('.preview');
                if (preview_container.find('.preview-carousel').length > 0) {
                    var firstCarouselItem = preview_container.find('.preview-carousel:eq(0)');
                    var carousel_width = parseInt(slide_tab.find('input.carousel-width').val());
                    var    carousel_height = parseInt(slide_tab.find('input.carousel-height').val());

                    var tmpImg = new Image();

                    tmpImg.onload = function() {
                        if (parseInt(carousel_width) > 0 && parseInt(carousel_height) > 0) {
                        } else if (parseInt(carousel_width) > 0) {
                            carousel_height = tmpImg.height / tmpImg.width * parseInt(carousel_width);
                        } else if (parseInt(carousel_height) > 0) {
                            carousel_width = tmpImg.width / tmpImg.height * parseInt(carousel_height);
                        } else {
                            carousel_width = tmpImg.width;
                            carousel_height = tmpImg.height;
                        }

                        var countCarousel = preview_container.find('.preview-carousel').length;
                        preview_container.find('.preview-carousel').each(function() {
                            var img = jQuery(this).find('img');

                            var tmpImg = new Image();

                            tmpImg.onload = function() {
                                countCarousel--;

                                if (tmpImg.width / tmpImg.height >= carousel_width / carousel_height) {
                                    var img_width = parseInt(tmpImg.width) * carousel_height / tmpImg.height;
                                    var img_height = carousel_height;
                                    img.css({
                                        width: img_width,
                                        height: img_height,
                                        marginTop: 0,
                                        marginLeft: - (img_width - carousel_width) / 2,
                                        top: 0,
                                        left: 0
                                    });
                                } else {
                                    var img_width = carousel_width;
                                    var img_height = parseInt(tmpImg.height) * carousel_width / tmpImg.width;
                                    img.css({
                                        width: img_width,
                                        height: img_height,
                                        marginLeft: 0,
                                        marginTop: - (img_height - carousel_height) / 2,
                                        top: 0,
                                        left: 0
                                    });
                                }
                                if (countCarousel == 0) {
                                    repositionCarouselLayers(slide_id);
                                }

                            }
                            tmpImg.src = img.attr('src');

                            jQuery(this).css({
                                top: 0,
                                width: carousel_width,
                                height: carousel_height
                            });

                        });
                    }
                    tmpImg.src = firstCarouselItem.find('img').attr('src');
                }
            };
            /* reset position of carousel layers */
            repositionCarouselLayers = function(slide_id) {
                var slide_tab = jQuery('.ui-tabs-panel[slide-id="' + slide_id + '"]');
                var preview_container = slide_tab.find('.preview');
                if (preview_container.find('.preview-carousel').length > 0) {
                    var firstCarouselItem = preview_container.find('.preview-carousel:eq(0)');
                    var carousel_width = firstCarouselItem.width();
                    var carousel_height = firstCarouselItem.height();
                    var carousel_count = preview_container.find('.preview-carousel').length;
                    var level_count = Math.floor(carousel_count / 2);
                    var current_carousel = 0;
                    var additional = carousel_count % 2;
                    for (var i = 0; i < carousel_count; i++) {
                        var side;
                        var carousel_level;
                        var carousel = preview_container.find('.preview-carousel').eq(i);

                        // Detect carousel level
                        if (Math.abs(i - current_carousel) > level_count) {
                            carousel_level = level_count - (Math.abs(i - current_carousel) % level_count == 0 ? level_count : Math.abs(i - current_carousel) % level_count) + additional;
                            if (i - current_carousel > 0) {
                                side = 'left';
                            } else {
                                side = 'right';
                            }
                        } else {
                            carousel_level = Math.abs(i - current_carousel);
                            if (i - current_carousel > 0) {
                                side = 'right';
                            } else {
                                side = 'left';
                            }
                        }

                        // Set z-index of carousel
                        carousel.css({
                            'z-index': level_count - carousel_level
                        });

                        // Set common style for carousel
                        if (carousel_level == 0) {
                            TweenMax.set(carousel, {
                                css: {
                                    top                     : 0,
                                    left                     : (preview_container.width() - carousel_width) / 2,
                                    scale                     : 1,
                                    opacity                 : 1,
                                    rotationX                 : 0,
                                    rotationY                 : 0,
                                    rotationZ                 : 0,
                                    transformPerspective     : (parseFloat(slide_tab.find('input.carousel-perspective').val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-perspective').val()) : carousel_width
                                }
                            });
                        } else {
                            var level_opacity = 1;
                            if (slide_tab.find('input.carousel-opacity').eq(carousel_level - 1).length > 0) {
                                level_opacity = (parseFloat(slide_tab.find('input.carousel-opacity').eq(carousel_level - 1).val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-opacity').eq(carousel_level - 1).val()) : 1;
                            } else {
                                level_opacity = (slide_tab.find('input.carousel-opacity').last().length > 0 && parseFloat(slide_tab.find('input.carousel-opacity').last().val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-opacity').last().val()) : 1;
                            }

                            var level_scale = 1;
                            if (slide_tab.find('input.carousel-scale').eq(carousel_level - 1).length > 0) {
                                level_scale = (parseFloat(slide_tab.find('input.carousel-scale').eq(carousel_level - 1).val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-scale').eq(carousel_level - 1).val()) : 1;
                            } else {
                                level_scale = (slide_tab.find('input.carousel-scale').last().length > 0 && parseFloat(slide_tab.find('input.carousel-scale').last().val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-scale').last().val()) : 1;
                            }

                            var level_rotationX = 0;
                            if (slide_tab.find('input.carousel-rotation-x').eq(carousel_level - 1).length > 0) {
                                level_rotationX = (jQuery.trim(slide_tab.find('input.carousel-rotation-x').eq(carousel_level - 1).val()) != '') ? parseFloat(slide_tab.find('input.carousel-rotation-x').eq(carousel_level - 1).val()) : 0;
                            } else {
                                level_rotationX = (slide_tab.find('input.carousel-rotation-x').last().length > 0 && jQuery.trim(slide_tab.find('input.carousel-rotation-x').last().val()) != '') ? parseFloat(slide_tab.find('input.carousel-rotation-x').last().val()) : 0;
                            }

                            var level_rotationY = 0;
                            if (slide_tab.find('input.carousel-rotation-y').eq(carousel_level - 1).length > 0) {
                                level_rotationY = (jQuery.trim(slide_tab.find('input.carousel-rotation-y').eq(carousel_level - 1).val()) != '') ? parseFloat(slide_tab.find('input.carousel-rotation-y').eq(carousel_level - 1).val()) : 0;
                            } else {
                                level_rotationY = (slide_tab.find('input.carousel-rotation-y').last().length > 0 && jQuery.trim(slide_tab.find('input.carousel-rotation-y').last().val()) != '') ? parseFloat(slide_tab.find('input.carousel-rotation-y').last().val()) : 0;
                            }

                            var level_rotationZ = 0;
                            if (slide_tab.find('input.carousel-rotation-z').eq(carousel_level - 1).length > 0) {
                                level_rotationZ = (jQuery.trim(slide_tab.find('input.carousel-rotation-z').eq(carousel_level - 1).val()) != '') ? parseFloat(slide_tab.find('input.carousel-rotation-z').eq(carousel_level - 1).val()) : 0;
                            } else {
                                level_rotationZ = (slide_tab.find('input.carousel-rotation-z').last().length > 0 && jQuery.trim(slide_tab.find('input.carousel-rotation-z').last().val()) != '') ? parseFloat(slide_tab.find('input.carousel-rotation-z').last().val()) : 0;
                            }

                            var level_width = carousel_width * level_scale;

                            if (side == 'right') {
                                TweenMax.set(carousel, {
                                    css: {
                                        scale                     : level_scale,
                                        opacity                 : level_opacity,
                                        rotationX                 : level_rotationX,
                                        rotationY                 : - level_rotationY,
                                        rotationZ                 : - level_rotationZ,
                                        transformPerspective     : (parseFloat(slide_tab.find('input.carousel-perspective').val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-perspective').val()) : level_width
                                    }
                                });
                            } else {
                                TweenMax.set(carousel, {
                                    css: {
                                        scale                     : level_scale,
                                        opacity                 : level_opacity,
                                        rotationX                 : level_rotationX,
                                        rotationY                 : level_rotationY,
                                        rotationZ                 : level_rotationZ,
                                        transformPerspective     : (parseFloat(slide_tab.find('input.carousel-perspective').val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-perspective').val()) : level_width
                                    }
                                });
                            }

                            carousel_overlay = parseFloat(slide_tab.find('input.carousel-overlay').val());
                            // Calculate left position of carousel
                            if ((slide_tab.find('input.carousel-overlay').val()).indexOf('%') > 0) {
                            } else {
                                carousel_overlay = parseFloat(slide_tab.find('input.carousel-overlay').val()) / carousel_width * 100 + '%';
                            }

                            if (side == 'left') {
                                var left = preview_container.width() / 2 - carousel_width / 2;
                                for (var j = 1; j <= carousel_level; j++) {

                                    var level_scale_1 = 1;
                                    if (slide_tab.find('input.carousel-scale').eq(j - 1).length > 0) {
                                        level_scale_1 = (parseFloat(slide_tab.find('input.carousel-scale').eq(j - 1).val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-scale').eq(j - 1).val()) : 1;
                                    } else {
                                        level_scale_1 = (slide_tab.find('input.carousel-scale').last().length > 0 && parseFloat(slide_tab.find('input.carousel-scale').last().val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-scale').last().val()) : 1;
                                    }

                                    var level_scale_2 = 1;
                                    if (slide_tab.find('input.carousel-scale').eq(j - 2).length > 0) {
                                        level_scale_2 = (parseFloat(slide_tab.find('input.carousel-scale').eq(j - 2).val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-scale').eq(j - 2).val()) : 1;
                                    } else {
                                        level_scale_2 = (slide_tab.find('input.carousel-scale').last().length > 0 && parseFloat(slide_tab.find('input.carousel-scale').last().val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-scale').last().val()) : 1;
                                    }

                                    left -= -(j == 1 ? 0 : carousel_width * (1 - level_scale_2) / 2) + carousel_width * level_scale_1 * (100 - parseFloat(carousel_overlay)) / 100 + carousel_width * (1 - level_scale_1) / 2;
                                }

                                TweenMax.set(carousel, {
                                    css: {
                                        left: left
                                    }
                                });
                            } else {
                                var left = preview_container.width() / 2 - carousel_width / 2;
                                for (var j = 1; j <= carousel_level; j++) {
                                    var level_scale_1 = 1;
                                    if (slide_tab.find('input.carousel-scale').eq(j - 1).length > 0) {
                                        level_scale_1 = (parseFloat(slide_tab.find('input.carousel-scale').eq(j - 1).val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-scale').eq(j - 1).val()) : 1;
                                    } else {
                                        level_scale_1 = (slide_tab.find('input.carousel-scale').last().length > 0 && parseFloat(slide_tab.find('input.carousel-scale').last().val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-scale').last().val()) : 1;
                                    }

                                    var level_scale_2 = 1;
                                    if (slide_tab.find('input.carousel-scale').eq(j - 2).length > 0) {
                                        level_scale_2 = (parseFloat(slide_tab.find('input.carousel-scale').eq(j - 2).val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-scale').eq(j - 2).val()) : 1;
                                    } else {
                                        level_scale_2 = (slide_tab.find('input.carousel-scale').last().length > 0 && parseFloat(slide_tab.find('input.carousel-scale').last().val()) >= 0) ? parseFloat(slide_tab.find('input.carousel-scale').last().val()) : 1;
                                    }

                                    left += (j == 1 ? carousel_width : carousel_width * level_scale_2 + carousel_width * (1 - level_scale_2) / 2) - carousel_width * level_scale_1 * parseFloat(carousel_overlay) / 100 - carousel_width * (1 - level_scale_1) / 2;
                                }
                                TweenMax.set(carousel, {
                                    css: {
                                        left: left
                                    }
                                });
                            }
                        }
                        if (carousel.find('img').css('-webkit-box-reflect') && carousel.find('img').css('-webkit-box-reflect').length != 0) {
                            carousel.css('-webkit-box-reflect', carousel.find('img').css('-webkit-box-reflect'));
                            carousel.find('img').css('-webkit-box-reflect', 'none');
                        }
                    }

                    // Set carousel container style
                    var top;
                    var carousel_position = slide_tab.find('select.carousel-pos').val();

                    if (carousel_position == 'top') {
                        top = 0;
                    } else if (carousel_position == 'bottom') {
                        top = preview_container.height() - carousel_height;
                    } else if (carousel_position == 'center') {
                        top = (preview_container.height() - carousel_height) / 2;
                    } else if ((slide_tab.find('input.carousel-pos-px-per').val() + '').indexOf('%') > 0) {
                        top = preview_container.height() * parseInt(slide_tab.find('input.carousel-pos-px-per').val()) / 100;
                    } else if (parseInt(slide_tab.find('input.carousel-pos-px-per').val()) >= 0) {
                        top = parseInt(slide_tab.find('input.carousel-pos-px-per').val());
                    } else {
                        top = (preview_container.height() - carousel_height) / 2;    // Center
                    }

                    preview_container.find('.preview-carousel-container').css({
                        width: preview_container.width(),
                        height: carousel_height,
                        top: top
                    });

                    preview_container.find('.preview-carousel-wrapper').css({
                        width: preview_container.width(),
                        height: carousel_height
                    });

                }
            }
            /* bind dropdown of common layer in carousel layer */
            commonLayerList = function(slide_id){
                carousel_ids="";
                opt = '<option>Please Select</option>';
                jQuery(".all-layer-table[slide-id='"+slide_id+"']").find("tr.layer").each(function(i){
                    if(!jQuery(this).find(".current-layer").find(".other-info").find("input.carousel-layer").is(":checked")){
                        opt_val=jQuery(this).attr('id');
                        opt_disp=jQuery(this).find(".layer-no").html();

                        if(jQuery(this).find(".layer-text").val())
                            opt_disp += " - "+ jQuery(this).find(".layer-text").val();
                        else
                            opt_disp += " - "+ jQuery(this).find(".layer-text").attr("placeholder");

                        if(jQuery(this).find(".current-layer").find(".common-layer").find("select.attach-layer[value='"+opt_val+"']").length==0){
                            opt +="<option value='"+opt_val+"'>"+opt_disp+"</option>";
                        }
                        else{
                            jQuery(this).find(".current-layer").find(".common-layer").find("select.attach-layer[value='"+opt_val+"']").remove();
                            opt +="<option value='"+opt_val+"'>"+opt_disp+"</option>";
                        }
                    }

                });
                if(opt!=""){
                    carousel_ids = "";
                    jQuery(".all-layer-table[slide-id='"+slide_id+"']").find("input.carousel-layer:checked").each(function(i){
                        jQuery(this).parents(".current-layer").find(".common-layer").find("select.attach-layer").each(function(){
                            oldval=jQuery(this).val();
                            newval = jQuery("input[name='layerid'][data-oldval='"+oldval+"']").val();
                            if(newval != "" && newval != undefined){
                                oldval = newval;
                            }
                            if(carousel_ids==""){
                                if(jQuery(this).val()!="")
                                    carousel_ids=jQuery(this).val();
                            }
                            else{
                                if(jQuery(this).val()!="")
                                    carousel_ids = carousel_ids +","+jQuery(this).val();
                            }
                            jQuery(this).html(opt).val(oldval);
                        });
                    });
                    jQuery(".all-layer-table[slide-id='"+slide_id+"']").parents(".ui-tabs-panel").find(".is-carousel").find("td:first").find(".carousel_layer_ids").val(carousel_ids);


                }
                jQuery("input[name='layerid']").removeAttr("data-oldval");
            };
            /* disable carousel options */



            updateIndex = function(e, ui) {
                var parent = ui.item.parent();
                jQuery('tr.layer', parent).each(function(i) {
                    layer_id = jQuery(this).attr("id");
                    newval =i+1;
                    jQuery("#" + layer_id).find(".current-layer").show();
                    /*change z-index according to layer*/
                    jQuery(".preview_layer[layerid='" + layer_id + "']").children().css("zIndex", newval);
                    //console.log('layer=>'+layer_id+"<New=>"+newval);
                    jQuery(this).find("td").find(".layer-no").html(newval);
                    oldval = jQuery(this).find(".other-info").find(".cur-layer-id").val();
                    jQuery(this).find(".other-info").find(".cur-layer-id").attr("data-oldval", oldval);
                    slide_id = jQuery(this).parents(".all-layer-table").attr('slide-id');
                    jQuery(this).find(".other-info").find(".cur-layer-id").val(newval);

                });
                if (ui.item.find('input.carousel-layer').is(':checked')) {
                    var layer_id = ui.item.attr('id');
                    var layer_index = 0;
                    ui.item.parent().find('tr.layer').each(function() {
                        if (jQuery(this).attr('id') == layer_id) {
                            return false;
                        }
                        if (jQuery(this).find('input.carousel-layer').is(':checked')) {
                            layer_index++;
                        }
                    });
                    var slide_tab = ui.item.closest('.ui-tabs-panel');
                    var slide_id = slide_tab.attr('slide-id');
                    var preview_container = slide_tab.find('.preview');
                    var preview_carousel = preview_container.find('.preview-carousel[layerid="' + layer_id + '"]');
                    if (layer_index == 0) {
                        preview_carousel.prependTo(preview_container.find('.preview-carousel-wrapper'));
                    } else {
                        preview_carousel.insertAfter(preview_container.find('.preview-carousel').eq(layer_index - 1));
                    }
                    resizeCarouselLayers(slide_id);
                    /*carouselOptions({
                    action: 'resizeLayers',
                    slideId: slide_id
                    });*/
                }
                commonLayerList(slide_id);
                /*carouselOptions({
                action: 'commonLayers',
                slideId: slide_id
                });*/
            };
            /* set shotcode data */
            setShortcodeData = function(post_id, textlen, elem) {
                content_text=elem.val();
                if (typeof content_text !='undefined' && content_text != null && content_text != "" && content_text != "[Text here]" ) {
                    if(content_text.indexOf('[') > -1 && content_text.indexOf(']') > -1){
                        content = "[post-id][post-slug][post-url][date-published][date-modified][image][image-url][title][content][excerpt]<a href='[post-url]'>Read more</a>[author][author-id][categories][tags][comments]";
                        var post_data = {
                            'action': 'cloud_short_code',
                            'content': content + '',
                            'text_length': textlen + '',
                            'postid': post_id + ''
                        };
                        jQuery.ajax({
                            url: ajaxurl,
                            data: post_data,
                            type: 'POST',
                            dataType: 'JSON',
                            async: false,
                            success: function(result) {
                                elem.data("post_data", result);
                            },
                            error: function() {
                                console.log('setShortcodeData failed');
                            }
                        });
                    }
                }
            };
            /* apply style when dragging element */
            dragLayer = function(ele, slide_id, layer_id) {                
                var previewLayer = mainContainer.find(".preview[slide-id='" + slide_id + "'] .preview_layer[layerid='" + layer_id + "']");                 
                if (ele.parents("tr#" + layer_id).find(".lock-layer").attr("lock") == "0") {  
                    previewLayer.children().each(function(){
                        jQuery(this).draggable({
                            stop: apply_style
                        });
                        //console.log(slide_id +'=> layer_id : '+layer_id +' ::: Class : '+jQuery(this).attr('class'));
                    })
                    data = previewLayer.children().html();

                    if (data && data.indexOf("iframe") >= 0) {
                        var previewLayerSpan = previewLayer.children("span");
                        previewLayerSpan.find('.dragme').remove();
                        temp = mainContainer.find(".preview[slide-id='" + slide_id + "'] .preview_layer[layerid='" + layer_id + "']").children("span");
                        previewLayerSpan.append('<div class="dragme"></div>');
                        /*var plsOuterWidth = jQuery(previewLayerSpan).outerWidth();
                        var plsOuterHeight = jQuery(previewLayerSpan).outerHeight();
                        var plsIframe = jQuery(previewLayerSpan).find("iframe");
                        if (plsOuterWidth == 0) {
                        plsOuterWidth = plsIframe.outerWidth();
                        }
                        if (plsOuterHeight == 0) {
                        plsOuterHeight = plsIframe.outerHeight();
                        }*/
                        previewLayerSpan.css({
                            /* width: plsOuterWidth + 'px',
                            height: plsOuterHeight + 'px',*/
                            position: 'absolute',                            
                            zIndex: jQuery(previewLayerSpan).css("zIndex")
                        });
                    }
                }
            };
            /* set style in input field on dragging layer */
            apply_style = function() {
                layer_id = jQuery(this).parents(".preview_layer").attr("layerid");
                //console.log(layer_id);
                img_top = jQuery(this).css("top");
                img_top = img_top.replace("px", "");
                var layerStyle = jQuery("tr#" + layer_id + " .styles");
                layerStyle.find(".img-top").val(img_top);
                layerStyle.find(".img-top-px").val("px");
                img_left = jQuery(this).css("left");
                img_left = img_left.replace("px", "");
                layerStyle.find(".img-left").val(img_left);
                layerStyle.find(".img-left-px").val("px");
            }
            filterPost = function(data, postid) {
                var preview = jQuery('#filter_posts').find('table').empty();
                /*if(data.length === 0) {*/
                if (jQuery.isEmptyObject(data)) {
                    preview.append(jQuery('<tr>').append(jQuery('<td>', {
                        'class': 'text-center',
                        'text': 'No posts were found with the current filters.'
                    })));
                } else {
                    for (c = 0; c < data.length; c++) {
                        preview.append(jQuery('<tr>').append(jQuery('<td>').append('<input type="radio" name="cs_post_id" value="' + data[c]['post-id'] + '" />' + (c + 1) + '.')).append(jQuery('<td>').append('<img src="' + data[c]['thumbnail'] + '" width="100px" />')).append(jQuery('<td>', {
                            'class': '',
                            'text': data[c]['title']
                        })).append(jQuery('<td>', {
                            'class': '',
                            'text': data[c]['content']
                        })).append(jQuery('<td>', {
                            'class': '',
                            'text': data[c]['date-published'] + " by " + data[c]['author']
                        })));
                    }
                    if (postid != "" && postid != undefined) jQuery("input[name='cs_post_id'][value='" + postid + "']").attr("checked", "checked");
                    else jQuery("input[name='cs_post_id']:first").attr("checked", "checked");
                }
            };
            changeSliderWidthHeight = function(callback) {
                mainContainer.find(".preview").css({
                    "width": parseFloat(jQuery(".slider-width").val()) + "px",
                    "height": parseFloat(jQuery(".slider-height").val()) + "px"
                });
                mainContainer.find('.ui-tabs-panel').each(function() {
                    var slideProperty = jQuery(this).find(".slide-property");
                    ele = slideProperty.find(".layer-add-img[preview='1']");                  
                    url = slideProperty.find(".layer-add-img").css("backgroundImage");
                    url = url.replace('url("', '').replace('")', '');
                    url = url.replace('url(', '').replace(')', '');
                    slide_id = jQuery(this).find(".all-layer-table").attr("slide-id");
                    showBackgroundImage(url, slide_id, ele);
                    resizeCarouselLayers(jQuery(this).attr('slide-id'));
                    /*carouselOptions({
                    action: 'resizeLayers',
                    slideId: jQuery(this).attr('slide-id')
                    });*/
                });
                changeBGColor(mainContainer.find('.container-bg-clr'));
                if (callback && typeof(callback) === "function") {
                    callback();
                }
            }
            /* move slide tabs */
            moveTabDiv = function(e, ui) {
                $prev_id = "";
                jQuery(this).find("li").each(function() {
                    id = jQuery(this).attr("aria-controls");
                    if ($prev_id == "") {
                        jQuery("#" + id).insertAfter(slideTabs.find("ul"));
                    } else {
                        jQuery("#" + id).insertAfter($prev_id);
                    }
                    $prev_id = "#" + id;
                });
                slideTabs.find('ul li').each(function() {
                    var tabCounter = jQuery(this).index() + 1;
                    jQuery(this).find('a').html("Slide#" + tabCounter);
                });
                refreshTabs();
            }
            mainContainer.on('click', 'input[name="save_data"]', function() {
                if (mainContainer.find('#hdnPreview').val() == 'preview') {                     
                    loaderPopup.find('p.successMsg').html('<strong>Preview is loading, Please wait ...<strong>');
                }
                else{
                    loaderPopup.find('p.successMsg').html('<strong>Slider is saving, Please wait ...<strong>');
                }
                loaderPopup.show();
                mainContainer.find('.minicolors-input').each(function() {
                    if (parseFloat(jQuery(this).attr('data-opacity')) < 1) {
                        if(jQuery(this).val()!=''){
                            var rgb = hex2rgb(jQuery(this).val()); 
                            jQuery(this).val('rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat(jQuery(this).attr('data-opacity')) + ')');
                        }
                    }
                });                
                setTimeout(function() {
                    var response = "";
                    var data = {
                        'action': 'cloud_id'
                    };
                    if (mainContainer.find('form#frmslider').attr('action') == '') {
                        jQuery.post(ajaxurl, data, function(responseId) {
                            mainContainer.find('form#frmslider').attr('action', 'admin.php?page=cloud-slider&action=edit&id=' + responseId);
                            response = responseId;
                        });
                    } else {
                        response = jQuery("#editid").val();
                    }
                    generate_form_data(response); 

                }, 100);

            });
            mainContainer.find(".msg_right").click(function() {
                jQuery(this).slideUp(300);
            });
            /* call checkbox on/off  in main slider setting options */
            mainContainer.find(".setting-data input.checkbox").checkbox({
                empty: CS_ROOT_URL + "/images/empty.png"
            });
            mainContainer.find('input[type="number"]').live('blur', function() {
                if (jQuery(this).val() != '') {
                    if (jQuery(this).val() < jQuery(this).attr('min')) {
                        jQuery(this).val(jQuery(this).attr('min'));
                    }
                    if (jQuery(this).val() > jQuery(this).attr('max')) {
                        jQuery(this).val(jQuery(this).attr('max'));
                    }
                } else {
                    if (jQuery(this).hasClass('scale-pos')) {
                        jQuery(this).val(jQuery(this).attr('min'));
                    }
                }
            });
            /* call accordion in slider setting */
            mainContainer.find("#setting_accordion").accordion({
                icons: false,
                animate: {
                    duration: 1
                },
                activate: function(event, ui) {
                    ui.newHeader.removeClass("accordion-head");
                    ui.newHeader.addClass("accordion-head-active");
                    ui.newHeader.find("span > i").addClass("fa-minus-circle");
                    ui.newHeader.find("span > i").removeClass("fa-plus-circle");
                    ui.oldHeader.removeClass("accordion-head-active");
                    ui.oldHeader.addClass("accordion-head");
                    ui.oldHeader.find("span > i").addClass("fa-plus-circle");
                    ui.oldHeader.find("span > i").removeClass("fa-minus-circle");
                }
            });
            /* add new slide */
            mainContainer.on("click", ".add-new-slide", function(e) {
                e.preventDefault();                
                loaderPopup.show();                

                var tabCounter = slideTabs.find('ul li').length + 1;
                id = "tabs-" + tabCounter;
                label = "Slide#" + tabCounter;
                li = jQuery(settings.tabTemplate.replace(/#\{href\}/g, "#" + id).replace(/#\{label\}/g, label))
                settings.tabs.find(".ui-tabs-nav").append(li);
                str = "action=get_templates&id=" + tabCounter + "&type=slider";
                jQuery.ajax({
                    url: ajaxurl,
                    data: str,
                    method: "POST",
                    async: false,
                    success: function(response) {
                        tabContent = response;
                        // var tabContent = $("#new-slide-data").children().clone();
                        //$div = jQuery("<div id='" + id + "' slide-id=''>").append(tabContent);

                        mainContainer.find(".main-settings li > ul li").find("a").each(function() {
                            if (jQuery(this).attr("setting")) {
                                old_href = jQuery(this).attr("setting");
                                jQuery(this).attr("href", "#" + old_href + "-" + tabCounter);

                            }
                        });
                        settings.tabs.append(tabContent);
                        $div = mainContainer.find("#" + id);
                        $div.find(".slide-property").find('input.kenburn').checkbox({
                            empty: CS_ROOT_URL + "/images/empty.png"
                        });
                        $div.find(".slide-property").find('input.carousel').checkbox({
                            empty: CS_ROOT_URL + "/images/empty.png"
                        });
                        title = $div.find(".slide-property").find('input.misc-hidden').data("title");
                        $div.find(".slide-property").find('input.misc-hidden').checkbox({
                            empty: CS_ROOT_URL + "/images/empty.png"
                        });
                        if (title) {
                            $div.find('input.misc-hidden').next(".jquery-checkbox").addClass("tooltip");
                            $div.find('input.misc-hidden').next(".jquery-checkbox").data("title", title);
                        }
                        refreshTabs();
                        li.find("a").trigger("click");
                        slideTabs.find('ul.ui-tabs-nav').sortable({
                            stop: moveTabDiv
                        });
                        mainContainer.find(".ui-tabs-panel").hide();
                        mainContainer.find("#" + id).show();
                        tabCounter++;
                        mainContainer.find(".slider-width").trigger("blur");
                        mainContainer.find(".slider-height").trigger("blur");

                        // console.log($div+'add-new-layer before');
                        fnNewLayer($div.find(".add-new-layer"));
                        //  $div.find(".add-new-layer").trigger("click");

                        changeSliderWidthHeight(function() {
                            //loaderPopup.hide();
                        });
                    }
                });

            });
            /* set slide id of selected tab after removing any tab or selecting any tab */
            settings.tabs.delegate("li.ui-state-default", "click", function(e) {
                var tabIndex = settings.tabs.tabs('option', 'active');
                var selected = slideTabs.find("li > a").eq(tabIndex).attr('href');
                if (selected) selected = selected.replace("#tabs-", "");
                var settingList = mainContainer.find('.main-settings li > ul li');
                settingList.find("a:focus").trigger("blur");
                //                settingList.find("a").removeClass("active");
                settingList.find("a").each(function() {
                    jQuery(this).removeClass("active");
                    if (jQuery(this).attr("setting")) {
                        old_href = jQuery(this).attr("setting");
                        if (selected) jQuery(this).attr("href", "#" + old_href + "-" + selected);
                        else jQuery(this).attr("href", "#" + old_href);
                        href = jQuery(this).attr("href");
                        if (jQuery(href).css("display") != "none") {
                            jQuery(this).addClass("active");
                        }
                    }
                });
            });
            /* move setting panels */
            jQuery(document).on("mousedown", "div.option-title", function(e) {
                //$(this).parents(".options").find('.option-container').hide();
                var option = jQuery(this);
                settings.isDraggEnabled = option.data("draggable");
                if (settings.isDraggEnabled) {
                    if (e.offsetX == undefined) {
                        x = e.pageX - option.offset().left;
                        y = e.pageY - option.offset().top;
                    } else {
                        x = e.offsetX;
                        y = e.offsetY;
                    };
                    option.parents(".options").addClass('movediv');
                    $body.addClass('noselect');
                    settings.target = option.parents(".options");
                };
                $body.append("<div class='trans-layer'></div>");
            });
            $body.on("mousemove", function(e) {
                if (settings.target) {
                    settings.target.offset({
                        top: e.pageY - y,
                        left: e.pageX - x
                    });
                };
            });
            $body.on("mouseup", function(e) {
                settings.target = null;
                //$(this).find('.option-container').show();
                jQuery(".movediv").removeClass('movediv');
                $body.removeClass('noselect');
                $body.find(".trans-layer").remove();
            });
            /* close settings panel */
            mainContainer.on("click", ".closethis a", function(e) {
                e.preventDefault();
                jQuery(this).parents(".options").hide();
                id = jQuery(this).parents(".options").attr("id");
                if (!id) id = jQuery(this).parents(".slide-container").attr("id");
                mainContainer.find(".main-settings").find("a[href='#" + id + "']").removeClass("active");
            });
            /* display panel according to click */
            mainContainer.on("click", ".cloud_slider_wrapper a", function(e) {
                if (!jQuery(this).hasClass('external')) {
                    e.preventDefault();
                    e.stopPropagation();
                    // disable content tabs for carousel layer (enable for only image tab)
                    if (jQuery(this).hasClass('kr-disabled')) {
                        return false;
                    }
                    //if($(this).parents(".preview_layer").length == 0)
                    href = jQuery(this).attr("href");
                    if (href.charAt(0) != "#") return false;
                    if (jQuery(this).parent().is("li")) jQuery(this).parent().parent().find("a").removeClass("active");
                    else {
                        //console.log($(this).parent());
                        if (!jQuery(this).hasClass("add-new-layer") && !jQuery(this).hasClass("add-new-slide")) {
                            //console.log($(this).attr("class"));
                            jQuery(this).parent().find("a.active").removeClass("active");
                        }
                    }
                    jQuery(this).addClass("active");
                    var cloudWrapper = jQuery(this).parents("div.cloud_slider_wrapper");
                    if (href != "#") {
                        id = href.substr(1);
                        cls = jQuery(this).attr("applycls");
                        pos_t = jQuery("#all-slides").position().top
                        if (jQuery(this).attr("applycls") == "options") {
                            cloudWrapper.find(".options").hide();
                            jQuery("#" + id).parents(".slides-options").find(".options").hide();
                            cloudWrapper.find("#" + id).fadeIn();
                        } else if (jQuery(this).attr("applycls") == "slide-container") {
                            cloudWrapper.find(".options").hide();
                            jQuery(this).parents(".main-settings").find("ul").hide();
                            cloudWrapper.find("." + cls).hide();
                            if (cloudWrapper.find("#" + id).find(".options").length == 1) {
                                cloudWrapper.find("#" + id).find(".options").show();
                            }
                            cloudWrapper.find("#" + id).fadeIn();
                        } else if (jQuery(this).attr("applycls") == "main-layer-tab" || jQuery(this).attr("applycls") == "layer-cls") {
                            jQuery(this).parents("div.layer-container").find("." + cls).hide();
                            jQuery(this).parents("div.layer-container").find("." + id).fadeIn();
                        } else {
                            cloudWrapper.find(".options").hide();
                            cloudWrapper.find("." + cls).hide();
                            cloudWrapper.find("#" + id).fadeIn();
                        }
                        cloudWrapper.find("#all-slides").show();
                        ele = jQuery(this);
                        if (jQuery(this).next().is("ul")) {
                            jQuery(this).next("ul").show();
                            jQuery("div#" + id).find(".options").each(function() {
                                if (jQuery(this).css("display") == "block") {
                                    sub_id = jQuery(this).attr("id");
                                    ele.parent().find("a[href='#" + sub_id + "']").addClass("active");
                                }
                            });
                        }
                    }
                    codeMirrorRefresh();
                }
            });
            /* delete tabs */
            settings.tabs.delegate("span.ui-icon-close", "click", function() {
                ans = confirm("Are you sure you want to delete this slide?");
                if (ans) {
                    var panelId = jQuery(this).closest("li").remove().attr("aria-controls");
                    licnt = settings.tabs.find("li").length;
                    jQuery("#" + panelId).remove();
                    refreshTabs();
                    if (settings.tabs.find("li").hasClass("ui-state-active") && settings.tabs.find("li").hasClass("ui-tabs-active")) {} else {
                        settings.tabs.find("li:last-child").addClass("ui-state-active");
                        settings.tabs.find("li:last-child").addClass("ui-tabs-active");
                        id = settings.tabs.find("li:last-child").attr("aria-controls");
                        jQuery("#" + id).show();
                    }
                }
            });
            /* slide transition popup and select value according to selcted transition */
            mainContainer.on("click", ".slide-transition", function(e) {
                e.preventDefault();
                slide_id = jQuery(this).attr("slide-id");
                val_2d = jQuery(".2d_trans_ids[slide-id='" + slide_id + "']").val();
                val_3d = jQuery(".3d_trans_ids[slide-id='" + slide_id + "']").val();
                var slideTransition = jQuery("#slide-transition");
                slideTransition.dialog({
                    modal: true,
                    width: 900,
                    height: 500,
                    draggable: false,
                    open: function(event, ui) {
                        slideTransition.find(".checkbox").attr("checked", false);
                        slideTransition.attr("slide-id", slide_id);
                        slideTransition.find(".2d-transition td").removeClass("select");
                        if (val_2d != "") {
                            if (val_2d.indexOf(",") != -1) {
                                arr_2d = val_2d.split(",");
                                if (settings.trans_2d_ids.length == arr_2d.length) slideTransition.find(".2d_select_all").attr("checked", "checked");
                                jQuery(arr_2d).each(function(index, value) {
                                    if (jQuery.inArray(value, settings.trans_2d_ids) != -1) jQuery("a[rel='2d_" + value + "']").parent().addClass("select");
                                });
                            } else jQuery("a[rel='2d_" + val_2d + "']").parent().addClass("select");
                        }
                        slideTransition.find(".2d_select_all").checkbox({
                            empty: CS_ROOT_URL + "/images/empty.png"
                        });
                        slideTransition.find(".3d-transition td").removeClass("select");
                        if (val_3d != "") {
                            if (val_3d.indexOf(",") != -1) {
                                arr_3d = val_3d.split(",");
                                if (settings.trans_3d_ids.length == arr_3d.length) slideTransition.find(".3d_select_all").attr("checked", "checked");
                                jQuery(arr_3d).each(function(index, value) {
                                    if (jQuery.inArray(value, settings.trans_3d_ids) != -1) jQuery("a[rel='3d_" + value + "']").parent().addClass("select");
                                });
                            } else jQuery("a[rel='3d_" + val_3d + "']").parent().addClass("select");
                        }
                        slideTransition.find(".3d_select_all").checkbox({
                            empty: CS_ROOT_URL + "/images/empty.png"
                        });
                    }
                });
            });
            /* select all 2d tansitions */
            jQuery(document).on("change", ".2d_select_all", function(e) {
                slide_id = jQuery(this).parents("#slide-transition").attr("slide-id");
                if (jQuery(this).is(":checked")) {
                    val_2d = settings.trans_2d_ids.join(",");
                    jQuery(".2d_trans_ids[slide-id='" + slide_id + "']").val(val_2d);
                    jQuery(".2d-transition tr:not(:first) td").addClass("select");
                } else {
                    jQuery(".2d_trans_ids[slide-id='" + slide_id + "']").val("");
                    jQuery(".2d-transition tr:not(:first) td").removeClass("select");
                }
            });
            /* select all 3d tansitions */
            jQuery(document).on("change", ".3d_select_all", function(e) {
                slide_id = jQuery(this).parents("#slide-transition").attr("slide-id");
                if (jQuery(this).is(":checked")) {
                    val_3d = settings.trans_3d_ids.join(",");
                    jQuery(".3d_trans_ids[slide-id='" + slide_id + "']").val(val_3d);
                    jQuery(".3d-transition tr:not(:first) td").addClass("select");
                } else {
                    jQuery(".3d_trans_ids[slide-id='" + slide_id + "']").val("");
                    jQuery(".3d-transition tr:not(:first) td").removeClass("select");
                }
            });
            /* select transition according to click */
            jQuery(document).on("click", ".transition-table a", function(e) {
                e.preventDefault();
                oldval = "";
                newval = "";
                slide_id = jQuery(this).parents("#slide-transition").attr("slide-id");
                type = jQuery(this).attr("rel");
                type = type.substr(0, 2);
                if (jQuery("." + type + "_trans_ids[slide-id='" + slide_id + "']").val() != "") oldval = jQuery("." + type + "_trans_ids[slide-id='" + slide_id + "']").val();
                newval = jQuery(this).attr("rel");
                newval = newval.substr(3);
                //newval=parseInt(newval)+1;
                if (jQuery(this).parent("td").hasClass("select")) {
                    jQuery("#slide-transition ." + type + "_select_all").attr("checked", false);
                    jQuery("#slide-transition ." + type + "_select_all").checkbox({
                        empty: CS_ROOT_URL + "/images/empty.png"
                    });
                    if (oldval != "") {
                        if (oldval.indexOf(",") != -1) {
                            oldarr = oldval.split(",");
                            if (jQuery.inArray(newval, oldarr) != -1) {
                                oldarr = jQuery.grep(oldarr, function(value) {
                                    return value != newval;
                                });
                                newval = oldarr.join(",");
                                jQuery("." + type + "_trans_ids[slide-id='" + slide_id + "']").val(newval);
                            }
                        } else jQuery("." + type + "_trans_ids[slide-id='" + slide_id + "']").val("");
                    }
                    jQuery(this).parent("td").removeClass("select");
                } else {
                    if (oldval == "") jQuery("." + type + "_trans_ids[slide-id='" + slide_id + "']").val(newval);
                    else jQuery("." + type + "_trans_ids[slide-id='" + slide_id + "']").val(oldval + "," + newval);
                    jQuery(this).parent("td").addClass("select");
                }
            });
            /* display transition effect on hover */
            jQuery(document).on("mouseenter", ".transition-table a", function(e) {
                el = jQuery(this);
                rel = jQuery(this).attr("rel");
                rel = rel.substr(3);
                rel = parseInt(rel);
                $body.prepend(jQuery('<div>', {
                    'class': 'preview-popup'
                }));
                var slider_content = '<div id="cloudslider">' + '<div class="kr-sky" data-duration="500" data-transition="' + rel + '">' + '<img class="sky-background" src="' + CS_ROOT_URL + '/images/slide1.png" alt="Slide background">' + '</div>' + '<div class="kr-sky" data-duration="500" data-transition="' + rel + '">' + '<img class="sky-background" src="' + CS_ROOT_URL + '/images/slide2.png" alt="Slide background">' + '</div>' + '</div>';
                var popup = jQuery('.preview-popup').html(slider_content);
                var v_w = jQuery(window).width();
                var e_w = jQuery(el).width();
                var e_l = jQuery(el).offset().left;
                var e_t = jQuery(el).offset().top;
                var t_w = popup.outerWidth();
                var t_h = popup.outerHeight();
                popup.css({
                    top: e_t - t_h - 60,
                    left: e_l - (t_w - e_w) / 2
                });
                if (popup.offset().top < 20) {
                    popup.css('top', e_t + 75);
                }
                if (popup.offset().left < 20) {
                    popup.css('left', 20);
                }
                popup.find("#cloudslider").cloudSlider({
                    width: 320,
                    height: 170,
                    progressBarPosition: 'hide',
                    imgLoader: libPath + 'img/loading.gif',
                    navType: 'none',
                    arrow: {
                        visibility: 'hide'
                    }
                });
                /*}, function() {
                $('.transition-show-panel').stop(true, true).remove();*/
            });
            /* remove transition preview popup on mouse leave */
            jQuery(document).on("mouseleave", ".transition-table a", function(e) {
                if (typeof jQuery('#cloudslider') != 'undefined' || jQuery('#cloudslider') != null) {
                    jQuery('#cloudslider').cloudKill();
                    jQuery('.preview-popup').remove();
                }
            });
            /* image upload */
            mainContainer.on("click", ".layer-add-img", function() {
                ele = jQuery(this);
                var send_attachment_bkp = wp.media.editor.send.attachment;
                var custom_uploader = wp.media({
                    title: 'Upload Image For Slider',
                    button: {
                        text: 'Insert into Slider'
                    },
                    library: {
                        type: 'image'
                    },
                    multiple: false // Set this to true to allow multiple files to be selected
                }).on('select', function() {
                    var attachment = custom_uploader.state().get('selection').first().toJSON();
                    //alert(attachment.url);
                    wp.media.editor.send.attachment = send_attachment_bkp;
                    var slide_id = ele.parents(".ui-tabs-panel").attr("slide-id");
                    //console.log('layer-add-img=>'+slide_id);
                    jQuery(ele).next('input').val(attachment.url);
                    if (ele.attr("preview") == "1") {
                        cnt = mainContainer.find(".preview_layer").length + 1;
                        layer_id = ele.attr("layerid");
                        var previewLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                        var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']");
                        if (ele.attr("layer") == "1") {
                            /* Check if child exist  If yes then copy style of it and apply it on new */
                            ele_style = "";
                            ele_id = "";
                            ele_cls = "";
                            ele_title = "";
                            ele_alt = "";
                            ele_rel = "";
                            if (previewLayer.children().length > 0) {
                                $child = previewLayer.children();
                                $child.css({
                                    "width": "auto",
                                    "height": "auto"
                                });
                                mainContainer.find("tr#" + layer_id).find(".style-layer-table").find(".img-width").val("auto");
                                mainContainer.find("tr#" + layer_id).find(".style-layer-table").find(".img-height").val("auto");
                                ele_style = $child.attr("style");
                                ele_id = $child.attr("id");
                                ele_cls = $child.attr("class");
                                ele_title = $child.attr("title");
                                ele_alt = $child.attr("alt");
                                ele_rel = $child.attr("rel");
                            } else {

                                ele_style = "z-index:" + (previewSlide.find('.preview_layer').length) + ";";
                            }

                            previewSlide.find("img[layerid='" + layer_id + "']").remove();
                            previewLayer.html("<img id='" + ele_id + "' alt='" + ele_alt + "' title='" + ele_title + "' rel='" + ele_rel + "' src='" + attachment.url + "' style='" + ele_style + "' class='drag-img pos-abs draggable " + ele_cls + "' layerid='" + layer_id + "' />");
                            if (ele.parent().find(".delete-img-icon").length == 0) {
                                ele.parent().prepend("<span class='delete-img-icon' layerid='" + layer_id + "'><i class='fa fa-times-circle-o'></i></span>");
                            }
                            dragLayer(ele, slide_id, layer_id);
                            if (ele.parents("tr#" + layer_id).find(".hide-layer").attr("hide") == "1") {
                                previewSlide.find(".preview_layer[layerid='" + layer_id + "']").children().hide();
                            }
                            if (ele.parents("tr#" + layer_id).find(".highlight-layer").attr("highlight") == "1") {
                                previewSlide.find(".preview_layer").children().css("opacity", "0.5");
                                previewSlide.find(".main-bg-img").css("opacity", "0.5");
                                previewSlide.find(".preview_layer[layerid='" + layer_id + "']").children().css("opacity", "1");
                            }
                            resizeCarouselLayers(slide_id);
                            /*carouselOptions({
                            action: 'resizeLayers',
                            slideId: slide_id,
                            layerId: ''
                            });*/
                        } else {
                            showBackgroundImage(attachment.url, slide_id, ele);
                        }
                    } else {
                        if (ele.parent().find(".delete-img-icon").length == 0) {
                            ele.parent().prepend("<span class='delete-img-icon'><i class='fa fa-times-circle-o'></i></span>");
                        }
                    }
                    ele.text("");
                    ele.css("background-image", "url(" + attachment.url + ")");
                }).open();
                return false;
            });
            /* kenburn setting */
            mainContainer.on("change", "input.kenburn", function() {
                if (jQuery(this).is(":checked")) {
                    var kenburnSetting = jQuery(this).parents(".slides-options").find("tr.kenburn-setting");
                    kenburnSetting.show();
                    kenburnSetting.find(".scale-from").trigger("keyup");
                } else {
                    /*$(this).parents(".slide-property").find("tr.kenburn-setting").find('input').val("");*/
                    slide_id = jQuery(this).parents(".ui-tabs-panel").attr("slide-id");
                    jQuery(this).parents(".ui-tabs-panel").find(".preview[slide-id='" + slide_id + "']").find(".main-bg-img").css({
                        "background-size": "cover",
                        "background-position": "top center"
                    });
                    jQuery(this).parents(".slides-options").find("tr.kenburn-setting").hide();
                }
            });
            /* kenburn postion percentage input display */
            mainContainer.on("change", ".ken-position", function() {
                var nextSpan = jQuery(this).next("span")
                if (jQuery(this).val() == "top_left_per") {
                    nextSpan.show();
                    nextSpan.find('.scale-pos').each(function() {
                        jQuery(this).val('50');
                    });
                } else {
                    nextSpan.find("input").val("");
                    nextSpan.hide();
                }
                var slideProperty = jQuery(this).parents(".slides-options").find(".slide-property");
                ele = slideProperty.find(".layer-add-img[preview='1']");
                /*url=$(this).parents(".slide-property").find(".layer-add-img").css("backgroundImage").replace('url("','').replace('")','');*/
                url = slideProperty.find(".layer-add-img").css("backgroundImage");
                url = url.replace('url("', '').replace('")', '');
                url = url.replace('url(', '').replace(')', '');
                slide_id = jQuery(this).parents(".ui-tabs-panel").attr("slide-id");
                showBackgroundImage(url, slide_id, ele);
            });
            /* set background size */
            mainContainer.on("keyup blur mouseup",".scale-from",function() {
                if(jQuery(this).val()!=""){
                    var slideProperty = jQuery(this).parents(".slides-options").find(".slide-property");
                    ele = slideProperty.find(".layer-add-img[preview='1']");
                    url= slideProperty.find(".layer-add-img").css("background-image");
                    url= url.replace('url("','').replace('")','');
                    url=url.replace('url(','').replace(')','');
                    slide_id=jQuery(this).parents(".ui-tabs-panel").attr("slide-id");
                    showBackgroundImage(url,slide_id,ele);
                }
            });

            /* set background position */
            mainContainer.on("keyup blur mouseup", ".scale-pos", function() {
                if (jQuery(this).val() != "") {
                    var slideProperty = jQuery(this).parents(".slides-options").find(".slide-property");
                    ele = slideProperty.find(".layer-add-img[preview='1']");
                    /*url=$(this).parents(".slide-property").find(".layer-add-img").css("backgroundImage").replace('url("','').replace('")','');*/
                    url = slideProperty.find(".layer-add-img").css("backgroundImage");
                    url = url.replace('url("', '').replace('")', '');
                    url = url.replace('url(', '').replace(')', '');
                    slide_id = jQuery(this).parents(".ui-tabs-panel").attr("slide-id");
                    showBackgroundImage(url, slide_id, ele);
                }
            });
            /* coursel position */
            mainContainer.on("change", ".carousel-pos", function() {
                var nextSpan = jQuery(this).next("span");
                if (jQuery(this).val() == "px_or_per") {nextSpan.show();}
                else {
                    repositionCarouselLayers(jQuery(this).closest('.ui-tabs-panel').attr('slide-id'));                    
                    /*carouselOptions({
                    action: 'resizeLayers',
                    slideId: jQuery(this).closest('.ui-tabs-panel').attr('slide-id')
                    });*/
                    nextSpan.find("input").val("");
                    nextSpan.hide();
                }
            });
            /* resizing carousel layers on keyup */
            mainContainer.on('keyup blur mouseup', 'input.carousel-pos-px-per, input.carousel-width, input.carousel-height, input.carousel-overlay, input.carousel-scale, input.carousel-opacity, input.carousel-rotation-x, input.carousel-rotation-y, input.carousel-rotation-z', function() {
                resizeCarouselLayers(jQuery(this).closest('.ui-tabs-panel').attr('slide-id'));
                /*                carouselOptions({
                action: 'resizeLayers',
                slideId: jQuery(this).closest('.ui-tabs-panel').attr('slide-id')
                });*/
            });
            /* resizing carousel layers on change */
            mainContainer.on('change', 'input.carousel-pos-px-per, input.carousel-width, input.carousel-height, input.carousel-overlay, input.carousel-scale, input.carousel-opacity, input.carousel-rotation-x, input.carousel-rotation-y, input.carousel-rotation-z', function() {
                resizeCarouselLayers(jQuery(this).closest('.ui-tabs-panel').attr('slide-id'));
                /* carouselOptions({
                action: 'resizeLayers',
                slideId: jQuery(this).closest('.ui-tabs-panel').attr('slide-id')
                });*/
            });
            /* add carousel level */
            mainContainer.on("click", ".add-carousel-level", function(e) {
                e.preventDefault();                
                var slideId=jQuery(this).parents('.ui-tabs-panel').attr('slide-id');
                var slideNumber=parseInt(slideId.slice(6));
                var slideProperty = jQuery(this).parents(".slide-property").find(".carousel-multi-level");
                var rows=slideProperty.find('tr').length;
                if (rows > 1) {
                    $level = slideProperty.find('tr').last().clone();
                } else {
                    $level = mainContainer.find("#carousel-level-setting").find("tr").clone();
                }                
                $level.find('input').each(function(){
                    if(jQuery(this).attr('name').indexOf('slides[layers]')!=-1)
                        {
                        jQuery(this).attr('name','slides[layers]['+(slideNumber-1)+'][properties][carousel-level]['+(rows)+']['+jQuery(this).attr('data-name')+']');
                    }
                });
                slideProperty.find('tr').find('td:last .delete-carousel-level').remove();
                if($level.find('td:last .delete-carousel-level').length<1)                
                    $level.find('td:last').append('<a href="#" class="delete-carousel-level">Delete</a>');

                slideProperty.append($level);
            });
            /* delete carousel level */
            mainContainer.on("click", ".delete-carousel-level", function(e) {
                e.preventDefault();
                var slideProperty = jQuery(this).parents(".carousel-multi-level");
                resizeCarouselLayers(jQuery(this).closest('.ui-tabs-panel').attr('slide-id'));
                jQuery(this).parent().parent().remove();
                if(slideProperty.find('tr').length>2)
                    slideProperty.find('tr:last td:last').append('<a href="#" class="delete-carousel-level">Delete</a>');
            });
            /* if image has not added yet, disable carousel option*/
            mainContainer.on('click', '.layer-tabs a[href="#carousel"]', function() {
                if (jQuery(this).closest('tr.layer').find('.content-subnav a[href="#layer-image"]').hasClass('active') && jQuery(this).closest('tr.layer').find('.delete-img-icon').length > 0) {
                    jQuery(this).closest('tr.layer').find('.carousel-layer').removeAttr('disabled');
                } else {
                    jQuery(this).closest('tr.layer').find('.carousel-layer').attr('disabled', 'disabled');
                }
            });
            /* hide attach layer if carousel layer if off */
            mainContainer.on("change", "input.carousel-layer", function() {
                var slide_id = jQuery(this).closest('.ui-tabs-panel').attr('slide-id');                 
                var layer_id = jQuery(this).closest('tr.layer').attr('id');
                var rowLayer = mainContainer.find('tr.layer[id="' + layer_id + '"]');
                var custom_style=rowLayer.find('.layer-data.styles .custom-style');
                if (jQuery(this).is(":checked")) {
                    jQuery(this).parents(".other-info").next(".common-layer").show();                    
                    rowLayer.find('.layer-data.styles').find('input').each(function() {                        
                        jQuery(this).attr('data-value',jQuery(this).val());
                        if (jQuery(this).hasClass('text-color')) {
                            jQuery(this).attr('data-opacity', 1);
                            jQuery(this).minicolors('value', '#000000');
                        } else if (jQuery(this).hasClass('bg-color')) {
                            jQuery(this).attr('data-opacity', 1);
                            jQuery(this).minicolors('value', '');
                        } else if (typeof jQuery(this).attr('data-default') != 'undefined') {
                            jQuery(this).val(jQuery(this).attr('data-default'));
                        }
                    });
                    rowLayer.find('.layer-data.styles').find('select').each(function() {
                        jQuery(this).attr('data-value',jQuery(this).val());
                    });                    
                    rowLayer.find('.layer-data.transition').find('input, select').each(function() {
                        jQuery(this).attr('data-value',jQuery(this).val());
                    });

                    custom_style.attr('data-value',custom_style.val()).val('');
                    disableCarouselOptions(slide_id,layer_id);
                    /*                    carouselOptions({
                    action: 'disable',
                    slideId: slide_id,
                    layerId: layer_id
                    });*/
                } else {
                    jQuery(this).parents(".other-info").next(".common-layer").hide();
                    custom_style.val(custom_style.attr('data-value')).change();
                    enableCarouselOptions(slide_id,layer_id);
                    /*carouselOptions({
                    action: 'enable',
                    slideId: slide_id,
                    layerId: layer_id
                    });*/
                    jQuery(this).closest("tr.layer").find(".custom-style").trigger("blur");
                }
                slide_id = jQuery(this).parents(".all-layer-table").attr("slide-id");

                commonLayerList(slide_id);
                /*carouselOptions({
                action: 'commonLayers',
                slideId: slide_id
                });*/
                arrangeCarouselLayers(slide_id);
                /*carouselOptions({
                action: 'arrangeLayers',
                slideId: slide_id
                });*/
            });
            /* add attach layer drop down */
            mainContainer.on("click", ".add-attach-layer", function(e) {
                e.preventDefault();
                $att = mainContainer.find("#carousel-attribute").find("tr").clone();
                /*$att.append("<td><a href='#' class='remove-carousel-attr'>Delete</a></td>");*/
                jQuery(this).parent().next("td").find("table.carousel-attr").append($att);
                slide_id = jQuery(this).parents(".all-layer-table").attr("slide-id");
                commonLayerList(slide_id);
                /*carouselOptions({
                action: 'commonLayers',
                slideId: slide_id
                });*/
            });
            /* update layer content connected with carousel layer  */
            mainContainer.on("change", ".attach-layer", function(e) {
                e.preventDefault();
                var slide_id = jQuery(this).closest('.ui-tabs-panel').attr('slide-id');                
                updateCommonLayer(slide_id);                
                /*carouselOptions({
                action: 'commonLayers',
                slideId: slide_id
                });*/
            });
            /* update layer content connected with carousel layer  */
            mainContainer.on("blur", ".attr-value", function(e) {
                e.preventDefault();
                var slide_id = jQuery(this).closest('.ui-tabs-panel').attr('slide-id');
                updateCommonLayer(slide_id);
                /*carouselOptions({
                action: 'commonLayers',
                slideId: slide_id
                });*/
            });
            /* remove carousel attribute */
            mainContainer.on("click", ".remove-carousel-attr", function(e) {
                e.preventDefault();
                jQuery(this).parent().parent().remove();
            });
            /* image upload and display path in corresponding inpt field in slider */
            mainContainer.on("click", ".upload-image", function(e) {
                e.preventDefault();
                ele = jQuery(this);
                var send_attachment_bkp = wp.media.editor.send.attachment;
                var custom_uploader = wp.media({
                    title: 'Upload Image',
                    button: {
                        text: 'Insert Image'
                    },
                    library: {
                        type: 'image'
                    },
                    multiple: false // Set this to true to allow multiple files to be selected
                }).on('select', function() {
                    var attachment = custom_uploader.state().get('selection').first().toJSON();
                    wp.media.editor.send.attachment = send_attachment_bkp;
                    jQuery(ele).parent("td").find('input').val(attachment.url);
                }).open();
                return false;
            });
            /* add new layer */
            mainContainer.on("click", ".add-new-layer", function(e) {
                e.preventDefault();
                loaderPopup.show();
                fnNewLayer(jQuery(this));
            });

            var fnNewLayer=function(newButton)
            {
                id = newButton.attr("id");
                /*$(".preview[slide-id='"+id+"']").parents(".preview-container").next(".enter-preview").trigger("click");*/
                rno = new Date().getTime();
                rno += Math.floor((Math.random() * 100) + 1) + '';
                str = "action=get_templates&layerId=" + rno + "&type=layer";
                var new_layer = '';
                setTimeout(function(){
                    jQuery.ajax({
                        url: ajaxurl,
                        data: str,
                        method: "POST",
                        async: false,
                        success: function(response) {
                            new_layer = response;
                            var slideTable=mainContainer.find(".all-layer-table[slide-id='" + id + "']");
                            if(mainContainer.find(".all-layer-table[slide-id='" + id + "'] > tbody").length<1){
                                slideTable.append('<tbody></tbody>');
                            }
                            slide=mainContainer.find(".all-layer-table[slide-id='" + id + "'] > tbody");
                            cnt = slide.find("tr.layer").length + 1;
                            mainContainer.find(".preview[slide-id='" + id + "']").append("<div class='preview_layer' layerid='" + rno + "'></div>");
                            slide.append(new_layer);
                            var layerRow = slide.find("tr#" + rno);
                            layerRow.find(".layer-text").attr("placeholder", "Layer#" + cnt);
                            layerRow.find(".layer-no").html(cnt);
                            layerRow.find(".other-info").find(".cur-layer-id").val(cnt);
                            layerRow.find(".layer-text").trigger("click");
                            layerRow.find('input.minicolors').each(function() {
                                var color_value = jQuery(this).val();
                                jQuery(this).minicolors('destroy').minicolors({
                                    control: 'hue',
                                    inline: false,
                                    opacity: true,
                                    position: 'bottom left',
                                    theme: 'default'
                                });
                            });
                            layerRow.find('div.minicolors').each(function() {
                                jQuery(this).wrap("<td></td>");
                            });
                            textlen = layerRow.find(".content").find('.layer-daynamic-content').find(".textlength").val();
                            postid = layerRow.find(".content").find('.layer-daynamic-content').find(".cs-post-id").val();
                            sdata = setShortcodeData(postid, textlen, layerRow.find(".daynamic-content-text"));

                            var tableRow = mainContainer.find('tr#' + rno);
                            title = tableRow.find('input.other').data("title");
                            tableRow.find('input.checkbox').checkbox({
                                empty: CS_ROOT_URL + "/images/empty.png"
                            });
                            if (title) {
                                var nextCheckbox = tableRow.find('input.other').next(".jquery-checkbox");
                                nextCheckbox.addClass("tooltip")
                                nextCheckbox.data("title", title);
                            }
                            wtitle = jQuery('tr#' + rno + ' input.word-wrap').data("title");
                            if (wtitle) {
                                var nextCheckbox = tableRow.find('input.word-wrap').next(".jquery-checkbox");
                                nextCheckbox.addClass("tooltip")
                                nextCheckbox.data("title", wtitle);
                            }
                            slide.sortable({
                                helper: fixHelperModified,
                                stop: updateIndex,
                                start: hidediv,
                                handle: ".move"
                            });
                            commonLayerList(id);
                            loaderPopup.hide();
                            /*carouselOptions({
                            action: 'commonLayers',
                            slideId: id
                            });*/
                        }
                    });
                },100);
            }
            /* Duplicate layer */
            mainContainer.on("click", ".duplicate-layer", function(e) {
                e.preventDefault();
                slide_id = jQuery(this).parents(".all-layer-table").attr("slide-id");
                old_layer_id = jQuery(this).parents("tr.layer").attr("id");
                old_place_holder = jQuery(this).parents("tr#" + old_layer_id).find(".layer-text").attr("placeholder");
                cnt = jQuery(this).parents(".all-layer-table[slide-id='" + slide_id + "']").find("tr.layer").length + 1;
                var new_layer = jQuery(this).parents("tr.layer").find("td.main_td:first-child").children().clone(true, true);
                rno = new Date().getTime();
                rno += Math.floor((Math.random() * 100) + 1) + '';
                new_layer.find(".jquery-checkbox").remove();
                new_layer.find(".layer-text").attr("placeholder", old_place_holder + " copy");
                new_layer.find(".layer-no").html(cnt);
                new_layer.find(".remove-layer,.duplicate-layer,.delete-img-icon,.layer-add-img,.layer-add-media").attr("layerid", rno);
                new_layer.find("input[data-name='layer_id'],[name='layer_id']").val(rno);
                new_layer.find(".cur-layer-id").val(cnt);
                $td = jQuery("<td class='main_td'>").append(new_layer);
                $tr = jQuery("<tr id='" + rno + "' class='layer'>").append($td);
                slide = parseInt(slide_id.slice(6)) - 1;
                slide_no = cnt - 1;
                jQuery(this).parents(".all-layer-table[slide-id='" + slide_id + "']").append($tr);
                jQuery(this).parents(".all-layer-table[slide-id='" + slide_id + "']").find("tr#" + rno).find(".layer-text").trigger("click");
                $tr.find('input,select,textarea,checkbox').not(".attach-layer", ".attr-value").each(function() {
                    name = jQuery(this).attr('name');                    
                    if (name.indexOf('slides[layers][' + slide + '][sub_layer]')==-1){     
                        // jQuery(this).attr('name', 'slides[layers][' + slide + '][sub_layer][' + slide_no + '][properties][' + name+ ']');                                  
                        //jQuery(this).attr('data-name',name);
                    }
                    else
                        {
                        jQuery(this).attr('name', 'slides[layers][' + slide + '][sub_layer][' + slide_no + '][properties][' + jQuery(this).attr('data-name') + ']'); 
                    }
                });
                $tr.find('.carousel-attr select,.carousel-attr textarea').each(function() {
                    //jQuery(this).attr('data-name', jQuery(this).attr('name') );
                    no = jQuery(this).parents("table.carousel-attr").find("tr").index(jQuery(this).parents("tr"));
                    input_name = jQuery(this).attr('name');
                    if (input_name.indexOf('slides[layers][' + slide + '][sub_layer]')==-1) {
                        //jQuery(this).attr('name', 'slides[layers][' + slide + '][sub_layer][' + slide_no + '][properties][carousel_attr][' + no + '][' + input_name + ']');
                        //jQuery(this).attr('data-name',input_name);
                    }
                    else{
                        jQuery(this).attr('name', 'slides[layers][' + slide + '][sub_layer][' + slide_no + '][properties][carousel_attr][' + no + '][' + jQuery(this).attr('data-name') + ']'); 
                    }
                });
                var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']"); 
                var new_layer_preview = previewSlide.find(".preview_layer[layerid='" + old_layer_id + "']").children().clone();
                new_layer_preview.attr("layerid", rno);
                oldindex = new_layer_preview.css("zIndex");
                new_layer_preview.css("zIndex", previewSlide.find(".preview_layer").length+1);
                $div = jQuery("<div class='preview_layer' layerid='" + rno + "'>").append(new_layer_preview);
                var tableRow = mainContainer.find('tr#' + rno);
                title = tableRow.find('input.other').data("title");
                tableRow.find('input.checkbox').checkbox({
                    empty: CS_ROOT_URL + "/images/empty.png"
                });
                if (title) {
                    var nextCheck = tableRow.find('input.other').next(".jquery-checkbox");
                    nextCheck.addClass("tooltip");
                    nextCheck.data("title", title);
                }
                wtitle = tableRow.find('input.word-wrap').data("title");
                if (wtitle) {
                    var nextCheck = tableRow.find('input.word-wrap').next(".jquery-checkbox");
                    nextCheck.addClass("tooltip");
                    nextCheck.data("title", wtitle);
                }
                //////////////////////////////////////$('tr#'+rno).find('.tooltip').tooltipster();

                previewSlide.append($div);
                ele = $td;
                dragLayer(ele, slide_id, rno);
                var previewLayer = previewSlide.find(".preview_layer[layerid='" + rno + "']").children();
                if ($tr.find(".hide-layer").attr("hide") == "1") {
                    previewLayer.hide();
                }
                if ($tr.find(".highlight-layer").attr("highlight") == "1") {
                    previewLayer.css("opacity", "0.5");
                }
                mainContainer.find(".all-layer-table[slide-id='" + slide_id + "'] tbody").sortable({
                    helper: fixHelperModified,
                    stop: updateIndex,
                    start: hidediv,
                    handle: ".move"
                });
                var tRow = mainContainer.find('tr#' + rno);
                tRow.find('input.checkbox').checkbox({
                    empty: CS_ROOT_URL + "/images/empty.png"
                });
                if (jQuery(this).closest('tr.layer').find('.carousel-layer').is(':checked')) {
                    arrangeCarouselLayers(slide_id);
                    /*                    carouselOptions({
                    action: 'arrangeLayers',
                    slideId: slide_id
                    });*/
                }
                title = tRow.find('input.other').data("title");
                tRow.find('input.checkbox').checkbox({
                    empty: CS_ROOT_URL + "images/empty.png"
                });
                if (title) {
                    var nextCheck = tRow.find('input.other').next(".jquery-checkbox");
                    nextCheck.addClass("tooltip")
                    nextCheck.data("title", title);
                }
                wtitle = tRow.find('input.word-wrap').data("title");
                if (wtitle) {
                    var nextCheck = tRow.find('input.word-wrap').next(".jquery-checkbox");
                    nextCheck.addClass("tooltip")
                    nextCheck.data("title", wtitle);
                }
            });
            /* remove layer */
            mainContainer.on("click", ".remove-layer", function(e) {
                e.preventDefault();
                ans = confirm("Are you sure you want to delete this layer?")
                if (ans) {
                    layer_id = jQuery(this).parents("tr").attr("id");
                    slide_id = jQuery(this).parents(".all-layer-table").attr("slide-id");
                    jQuery(this).parents(".ui-tabs-panel").find(".preview[slide-id='" + slide_id + "'] .preview_layer[layerid='" + layer_id + "']").remove();
                    var allLayerSlide = mainContainer.find(".all-layer-table[slide-id='" + slide_id + "']");
                    allLayerSlide.find("tr.layer:last-child").find(".layer-text").trigger("click");
                    jQuery(this).parents("tr").remove();
                    cnt = 1;
                    allLayerSlide.find("tr.layer").each(function() {
                        jQuery(this).find(".layer-no").html(cnt);
                        if (jQuery(this).find(".layer-text").val() == "") jQuery(this).find(".layer-text").attr("placeholder", "Layer#" + cnt);
                        cnt++;
                    });
                    repositionCarouselLayers(slide_id);
                    /*carouselOptions({
                    action: 'repositionLayers',
                    slideId: slide_id
                    });*/
                }
            });
            /* set in preview according to selection of sub navigation from content i.e image text or audio/video or dynamic html */
            mainContainer.on("click", ".content-subnav a", function(e) {
                e.preventDefault();
                if (jQuery(this).hasClass('kr-disabled')) {
                    return false;
                }
                layer_id = jQuery(this).parents("tr").attr("id");
                slide_id = jQuery(this).parents(".ui-tabs-panel").find(".all-layer-table").attr("slide-id");
                /* Check if child exist  If yes then copy style of it and apply it on new */
                ele_style = "";
                ele_id = "";
                ele_cls = "";
                ele_title = "";
                ele_alt = "";
                ele_rel = "";
                var previewLayer = jQuery(".preview_layer[layerid='" + layer_id + "']");
                if (previewLayer.children().length > 0) {
                    $child = previewLayer.children();
                    ele_style = $child.attr("style");
                    ele_id = $child.attr("id");
                    ele_cls = $child.attr("class");
                    ele_title = $child.attr("title");
                    ele_alt = $child.attr("alt");
                    ele_rel = $child.attr("rel");
                } else {
                    tot = mainContainer.find(".preview_layer").length + 1;
                    ele_style = "z-index:" + tot;
                }
                if (jQuery(this).attr("href") == "#layer-image") {
                    var bg = jQuery(this).parents("tr#" + layer_id).find(".layer-image").find(".click-set").css('backgroundImage');
                    if ((bg != 'undefined') && (bg != "none")) {
                        bg = bg.replace('url("', '').replace('")', '');
                        bg = bg.replace('url(', '').replace(')', '');
                        if (bg != window.location.href) {
                            previewLayer.html("<img src='" + bg + "' id='" + ele_id + "' alt='" + ele_alt + "' title='" + ele_title + "' rel='" + ele_rel + "' layerid='" + layer_id + "' class='draggable " + ele_cls + "' style='" + ele_style + "'>");
                        }
                        ele = jQuery(this);
                        dragLayer(ele, slide_id, layer_id);
                        var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']");
                        if (ele.parents("tr#" + layer_id).find(".hide-layer").attr("hide") == "1") {
                            previewSlide.find(".preview_layer[layerid='" + layer_id + "']").children().hide();
                        }
                        if (ele.parents("tr#" + layer_id).find(".highlight-layer").attr("highlight") == "1") {
                            previewSlide.find(".preview_layer").children().css("opacity", "0.5");
                            previewSlide.find(".main-bg-img").css("opacity", "0.5");
                            previewSlide.find(".preview_layer[layerid='" + layer_id + "']").children().css("opacity", "1");
                        }
                    }
                } else if (jQuery(this).attr("href") == "#layer-content-text") {
                    var layerContext = jQuery(this).parents("tr#" + layer_id).find(".layer-content-text");
                    if (!layerContext.find("a").hasClass("active")) {
                        layerContext.find("a:first-child").addClass("active");
                    }
                    layerContext.find(".content-text").trigger("keyup");
                } else if (jQuery(this).attr("href") == "#layer-html-video-audio") {
                    jQuery(this).parents("tr#" + layer_id).find(".layer-html-video-audio-textarea").find(".video-audio-text").trigger("keyup");
                } else if (jQuery(this).attr("href") == "#layer-daynamic-content") {
                    jQuery(this).parents("tr#" + layer_id).find(".layer-daynamic-html-textarea").find(".daynamic-content-text").trigger("keyup");
                }
                updatePreviewLayerStyle(layer_id);
            });
            /* display layer according to selection */
            mainContainer.on("click", ".layer-main", function() {
                mainContainer.find(".layer-tab-right").hide();
                mainContainer.find(".layer-data").hide();
                jQuery(this).find(".layer-tab-right").css("display", "inline-block");
                var parentLayer = jQuery(this).parents("div.layer-container");
                parentLayer.find(".current-layer").show();
                parentLayer.find(".main-layer-tab").hide();
                parentLayer.find(".layer-tabs > a").removeClass("active");
                parentLayer.find(".layer-tabs a:first-child").addClass("active");
                jQuery(this).parents("div.layer-container").find(".content").show();
            });
            /* display layer according to focus */
            mainContainer.on("click", ".layer-text", function(e) {
                e.stopPropagation();
                mainContainer.find(".layer-tab-right").hide();
                mainContainer.find(".layer-data").hide();
                var layerContainer = jQuery(this).parents("div.layer-container");
                layerContainer.find(".layer-tab-right").css("display", "inline-block");
                layerContainer.find(".current-layer").show();
                layerContainer.find(".main-layer-tab").hide();
                layerContainer.find(".layer-tabs > a").removeClass("active");
                layerContainer.find(".layer-tabs a:first-child").addClass("active");
                layerContainer.find(".content").show();
            });
            mainContainer.on("blur", ".layer-text", function(e) {
                slide_id = jQuery(this).parents(".all-layer-table").attr('slide-id');
                commonLayerList(slide_id);
                /*                carouselOptions({
                action: 'commonLayers',
                slideId: slide_id
                });*/
            });
            /* delete image from preview and button background */
            mainContainer.on("click", ".delete-img-icon", function(e) {
                e.preventDefault();
                lid = jQuery(this).attr("layerid");
                slide_id = jQuery(this).parents(".ui-tabs-panel").find(".all-layer-table").attr("slide-id");
                var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']");
                if (lid) {
                    if (lid == "abc") {
                        previewSlide.find(".main-bg-img").remove();
                    } else {
                        previewSlide.find("img[layerid='" + lid + "']").remove();
                    }
                }
                jQuery(this).parent().find("input[type='hidden']").val("");
                jQuery(this).parent().find(".click-set").removeAttr("style").text("Click to Set");
                jQuery(this).remove();
            })
            /* stop image open in tab */
            mainContainer.on("click", ".cloud_slider_panel img", function(event) {
                event.preventDefault();
            });
            /* set images from enter url */
            mainContainer.on("click", ".enter_url", function(e) {
                e.preventDefault();
                ans = prompt("Enter an image URL");
                slide_id = jQuery(this).parents(".ui-tabs-panel").find(".all-layer-table").attr("slide-id");
                cnt = mainContainer.find(".all-layer-table[slide-id='" + slide_id + "']").find("tr.layer").length + 1;
                if (ans) {
                    if (jQuery(this).attr("layer") == "1") {
                        layer_id = jQuery(this).parents("tr.layer").attr("id");
                        /* Check if child exist  If yes then copy style of it and apply it on new */
                        ele_style = "";
                        ele_id = "";
                        ele_cls = "";
                        ele_title = "";
                        ele_alt = "";
                        ele_rel = "";
                        var previewLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                        if (previewLayer.length > 0) {
                            previewLayerChild=previewLayer.children();
                            previewLayerChild.css({
                                "width": "auto",
                                "height": "auto"
                            });
                            var styleLayer = mainContainer.find("tr#" + layer_id).find(".style-layer-table");
                            styleLayer.find(".img-width").val("auto");
                            styleLayer.find(".img-height").val("auto");
                            ele_style = previewLayerChild.attr("style");
                            ele_id = previewLayerChild.attr("id");
                            ele_cls = previewLayerChild.attr("class");
                            ele_title = previewLayerChild.attr("title");
                            ele_alt = previewLayerChild.attr("alt");
                            ele_rel = previewLayerChild.attr("rel");
                        } else {
                            ele_style = "z-index:" + cnt + ";";
                        }
                        var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']");
                        previewSlide.find("img[layerid='" + layer_id + "']").remove();
                        previewLayer.html("<img id='" + ele_id + "' alt='" + ele_alt + "' title='" + ele_title + "' rel='" + ele_rel + "' src='" + ans + "' style='" + ele_style + "' class='drag-img pos-abs draggable " + ele_cls + "' layerid='" + layer_id + "' />");
                        var layerImgContainer = jQuery(this).parents(".layer-image-container");
                        layerImgContainer.find(".click-set").text("");
                        layerImgContainer.find(".pos-rel").children("input[type='hidden']").val(ans);
                        layerImgContainer.find(".click-set").css("background-image", "url(" + ans + ")");
                        layerImgContainer.find(".pos-rel").find(".delete-img-icon").remove();
                        layerImgContainer.find(".pos-rel").prepend("<span class='delete-img-icon' layerid='" + layer_id + "'><i class='fa fa-times-circle-o'></i></span>");
                        ele = jQuery(this);
                        dragLayer(ele, slide_id, layer_id);
                    } else {
                        if (jQuery(this).attr("preview") == "1") {
                            showBackgroundImage(ans, slide_id, jQuery(this));
                        }
                        var nextTD = jQuery(this).parent().next("td");
                        nextTD.find(".pos-rel").prepend("<span class='delete-img-icon' layerid='abc'><i class='fa fa-times-circle-o'></i></span>");
                        nextTD.find(".click-set").text("").css("background-image", "url(" + ans + ")");
                        nextTD.find(".pos-rel").children("input[type='hidden']").val(ans);
                    }
                }
            });
            /* Add media */
            mainContainer.on("click", ".layer-add-media", function() {
                ele = jQuery(this);
                var send_attachment_bkp = wp.media.editor.send.attachment;
                var custom_uploader = wp.media({
                    title: 'Add Media For Slider',
                    button: {
                        text: 'Insert into Slider'
                    },
                    library: {
                        type: 'video,audio'
                    },
                    multiple: false // Set this to true to allow multiple files to be selected
                }).on('select', function() {
                    var attachment = custom_uploader.state().get('selection').first().toJSON();
                    wp.media.editor.send.attachment = send_attachment_bkp;
                    slide_id = ele.parents(".ui-tabs-panel").find(".all-layer-table").attr("slide-id");
                    if (attachment.type == "audio") {
                        data = '<audio preload="metadata" nocontrols><source src="' + attachment.url + '"  type="' + attachment.mime + '"></audio>';
                        ele.parents(".layer-html-video-audio").find("textarea").val(data);
                    } else if (attachment.type == "video") {
                        data = '<video width="' + attachment.width + '" height="' + attachment.height + '" preload="metadata" controls><source src="' + attachment.url + '"  type="' + attachment.mime + '"></video>';
                        ele.parents(".layer-html-video-audio").find("textarea").val(data);
                    }
                    if (ele.attr("preview") == "1") {
                        var previewLayer = mainContainer.find(".preview_layer");
                        cnt = previewLayer.length + 1;
                        layer_id = ele.attr("layerid");
                        //Check if child exist  If yes then copy style of it and apply it on new
                        ele_style = "";
                        ele_id = "";
                        ele_cls = "";
                        ele_title = "";
                        ele_alt = "";
                        ele_rel = "";
                        var previewLayerChild = previewLayer.filter("[layerid='" + layer_id + "']").children();
                        if (previewLayerChild.length > 0) {
                            previewLayerChild.css("width", "auto");
                            previewLayerChild.css("height", "auto");
                            mainContainer.find("tr#" + layer_id).find(".style-layer-table").find(".img-width").val("auto");
                            mainContainer.find("tr#" + layer_id).find(".style-layer-table").find(".img-height").val("auto");
                            ele_style = previewLayerChild.attr("style");
                            ele_id = previewLayerChild.attr("id");
                            ele_cls = previewLayerChild.attr("class");
                            ele_title = previewLayerChild.attr("title");
                            ele_alt = previewLayerChild.attr("alt");
                            ele_rel = previewLayerChild.attr("rel");
                        } else {
                            ele_style = "z-index:" + cnt + ";";
                        }
                        ele.parents(".ui-tabs-panel").find(".preview[slide-id='" + slide_id + "'] .preview_layer[layerid='" + layer_id + "']").html("");
                        if (attachment.type == "audio") {
                            ele.parents(".ui-tabs-panel").find(".preview[slide-id='" + slide_id + "'] .preview_layer[layerid='" + layer_id + "']").html('<span><audio id="' + ele_id + '" alt="' + ele_alt + '" title="' + ele_title + '" rel="' + ele_rel + '" src="' + attachment.url + '" style="' + ele_style + '" class="pos-abs draggable ' + ele_cls + '" layerid="' + layer_id + '" preload="metadata" nocontrols><source src="' + attachment.url + '" type="' + attachment.mime + '"></audio></span>');
                        } else if (attachment.type == "video") {
                            ele.parents(".ui-tabs-panel").find(".preview[slide-id='" + slide_id + "'] .preview_layer[layerid='" + layer_id + "']").html('<span><video id="' + ele_id + '" alt="' + ele_alt + '" title="' + ele_title + '" rel="' + ele_rel + '" src="' + attachment.url + '" style="' + ele_style + '" class="pos-abs draggable ' + ele_cls + '" layerid="' + layer_id + '" width="' + attachment.width + '" height="' + attachment.height + '" preload="metadata" controls><source src="' + attachment.url + '" type="' + attachment.mime + '"></video></span>');
                        }
                        ele = jQuery(this);
                        dragLayer(ele, slide_id, layer_id);
                        var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']");
                        if (ele.parents("tr#" + layer_id).find(".hide-layer").attr("hide") == "1") {
                            previewSlide.find(".preview_layer[layerid='" + layer_id + "']").children().hide();
                        }
                        if (ele.parents("tr#" + layer_id).find(".highlight-layer").attr("highlight") == "1") {
                            previewSlide.find(".preview_layer").children().css("opacity", "0.5");
                            previewSlide.find(".main-bg-img").css("opacity", "0.5");
                            previewSlide.find(".preview_layer[layerid='" + layer_id + "']").children("span").css("opacity", "1");
                        }
                    }
                }).open();
                return false;
            });
            /* added text in preview with set options */
            mainContainer.on("keyup blur", ".content-text", function() {
                var ele = jQuery(this);
                var content = jQuery(this).val();
                var tag = jQuery(this).parents(".layer-content-text").find("a.active").attr("tag");
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                var slide_id = jQuery(this).parents(".all-layer-table").attr("slide-id");
                var preiviewLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                var previewLayerChild = preiviewLayer.children();
                if (previewLayerChild.length > 0) {
                    previewLayerChild.html(content);
                } else {
                    var z_index = mainContainer.find(".preview_layer").length + 1;
                    preiviewLayer.html('<span layerid="' + layer_id + '" class="draggable" style="z-index:' + z_index + '">' + content + '</span>');
                }
                dragLayer(ele, slide_id, layer_id);
                var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']");
                var parentRow = jQuery(this).parents("tr#" + layer_id);
                if (parentRow.find(".hide-layer").attr("hide") == "1") {
                    previewSlide.find(".preview_layer[layerid='" + layer_id + "']").children().hide();
                }
                if (parentRow.find(".highlight-layer").attr("highlight") == "1") {
                    previewSlide.find(".preview_layer").children().css("opacity", "0.5");
                    previewSlide.find(".main-bg-img").css("opacity", "0.5");
                    previewSlide.find(".preview_layer[layerid='" + layer_id + "']").children().css("opacity", "1");
                }
            });
            /* set short code in textarea according to click */
            mainContainer.on("click", ".layer-post-short-code a", function(e) {
                var ele = jQuery(this);
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                var slide_id = jQuery(this).parents(".all-layer-table").attr("slide-id");
                var short_code = jQuery(this).html();
                var text_val = jQuery(this).parents("tr#" + layer_id).find(".layer-daynamic-html-textarea").find("textarea").val();
                if (short_code == "[link]") short_code = '<a href="[post-url]">Read more</a>';
                jQuery(this).parents("tr#" + layer_id).find(".layer-daynamic-html-textarea").find("textarea").insertAtCaret(short_code);
                var content = jQuery(this).parents("tr#" + layer_id).find(".layer-daynamic-html-textarea").find("textarea").val();
                shortcode_data = jQuery(this).parents("tr#" + layer_id).find(".layer-daynamic-html-textarea").find("textarea").data("post_data");
                if (!jQuery.isEmptyObject(shortcode_data)) {
                    jQuery.each(shortcode_data, function(val, index, arr) {
                        str = "[" + val + "]";
                        content = content.replace(str, index);
                    });
                }
                var previewLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                var previewLayerChild = previewLayer.children();
                if (previewLayerChild.length > 0) {
                    previewLayerChild.html(content);
                } else {
                    var z_index = mainContainer.find(".preview_layer").length + 1;
                    previewLayer.html('<span layerid="' + layer_id + '" class="draggable" style="z-index:' + z_index + '">' + content + '</span>');
                }
                dragLayer(ele, slide_id, layer_id);
                var parentRow = jQuery(this).parents("tr#" + layer_id);
                var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']");
                var previewLayer = previewSlide.find(".preview_layer[layerid='" + layer_id + "']");
                if (parentRow.find(".hide-layer").attr("hide") == "1") {
                    previewLayer.children("span").hide();
                }
                if (jQuery(this).parents("tr#" + layer_id).find(".highlight-layer").attr("highlight") == "1") {
                    previewSlide.find(".preview_layer").children().css("opacity", "0.5");
                    previewSlide.find(".main-bg-img").css("opacity", "0.5");
                    previewLayer.children("span").css("opacity", "1");
                }
            });
            /* added daynamic content from post in preview with set options */
            mainContainer.on("keyup blur", ".daynamic-content-text", function() {
                var ele = jQuery(this);
                var content = strip_html_tags(jQuery(this).val());
                var tag = jQuery(this).parents(".layer-content-text").find("a.active").attr("tag");
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                var slide_id = jQuery(this).parents(".all-layer-table").attr("slide-id");
                shortcode_data = jQuery(this).data("post_data");
                if (!jQuery.isEmptyObject(shortcode_data)) {
                    jQuery.each(shortcode_data, function(val, index, arr) {
                        str = "[" + val + "]";
                        content = content.replace(str, index);
                    });
                }
                var previewLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']");
                var previewLayerChild = previewLayer.children();
                if (previewLayerChild.length > 0) {
                    previewLayer.html('<span layerid="' + layer_id + '" class="draggable" style="' + previewLayerChild.attr('style') + '">' + content + '</span>');
                } else {
                    var z_index = previewSlide.find(".preview_layer").length;
                    previewLayer.html('<span layerid="' + layer_id + '" class="draggable" style="z-index:' + z_index + '">' + content + '</span>');
                }
                dragLayer(ele, slide_id, layer_id);
                var parentRow = jQuery(this).parents("tr#" + layer_id);

                if (parentRow.find(".hide-layer").attr("hide") == "1") {
                    previewSlide.find(".preview_layer[layerid='" + layer_id + "']").children("span").hide();
                }
                if (parentRow.find(".highlight-layer").attr("highlight") == "1") {
                    previewSlide.find(".preview_layer").children().css("opacity", "0.5");
                    previewSlide.find(".main-bg-img").css("opacity", "0.5");
                    previewSlide.find(".preview_layer[layerid='" + layer_id + "']").children("span").css("opacity", "1");
                }
            });
            /* add video auudio in preview on key up and blur */
            mainContainer.on("keyup blur", ".video-audio-text", function() {
                content = strip_html_tags(jQuery(this).val());
                layer_id = jQuery(this).parents("tr.layer").attr("id");
                slide_id = jQuery(this).parents(".all-layer-table").attr("slide-id");
                ele_style = "";
                ele_id = "";
                ele_cls = "";
                ele_title = "";
                ele_alt = "";
                ele_rel = "";
                var previewLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']");
                $child = previewLayer.children();
                if ($child.length > 0) {
                    $child.css({
                        "width": "auto",
                        "height": "auto"
                    });
                    mainContainer.find("tr#" + layer_id).find(".style-layer-table").find(".img-width").val("auto");
                    mainContainer.find("tr#" + layer_id).find(".style-layer-table").find(".img-height").val("auto");
                    if (typeof $child.attr("style") != "undefined") ele_style = $child.attr("style");
                    if (typeof $child.attr("id") != "undefined") ele_id = $child.attr("id");
                    if (typeof $child.attr("class") != "undefined") ele_cls = $child.attr("class");
                    if (typeof $child.attr("title") != "undefined") ele_title = $child.attr("title");
                    if (typeof $child.attr("alt") != "undefined") ele_alt = $child.attr("alt");
                    if (typeof $child.attr("rel") != "undefined") ele_rel = $child.attr("rel");
                } else {
                    tot = previewSlide.find(".preview_layer").length;
                    ele_style = "z-index:" + tot;
                }
                previewLayer.html("<span>" + content + "</span>");
                var previewSpan = previewLayer.children("span").not('.hoverLayer');
                previewSpan.attr({
                    "id": ele_id,
                    "class": ele_cls,
                    "title": ele_title,
                    "alt": ele_alt,
                    "rel": ele_rel,
                    "style": ele_style
                });
                if(previewSpan.find('iframe,video,object').length>0 && previewSpan.find('span.hoverLayer').length<1){
                    previewSpan.append('<span class="hoverLayer"></span>');
                }
                ele = jQuery(this);
                dragLayer(ele, slide_id, layer_id);
                var parentRow = jQuery(this).parents("tr#" + layer_id);
                var previewLayer = previewSlide.find(".preview_layer");
                if (parentRow.find(".hide-layer").attr("hide") == "1") {
                    previewLayer.filter("[layerid='" + layer_id + "']").children("span").hide();
                }
                if (parentRow.find(".highlight-layer").attr("highlight") == "1") {
                    previewLayer.children().css("opacity", "0.5");
                    mainContainer.find(".preview[slide-id='" + slide_id + "']").find(".main-bg-img").css("opacity", "0.5");
                    previewLayer.filter("[layerid='" + layer_id + "']").children("span").css("opacity", "1");
                }
            });
            /* apply text style on click*/
            mainContainer.on("click", ".text-style", function(e) {
                e.preventDefault();
                jQuery(this).parents(".layer-content-text").find(".content-text").trigger("keyup");
            });
            /* allow only 0 to 9 in input for width,height,top,left etc.. */
            mainContainer.on("keydown", '.keypressFilter', function(events) {
                if (events.keyCode == 46 || events.keyCode == 8 || events.keyCode == 9 || events.keyCode == 27 || events.keyCode == 13 ||
                // allow decimals
                events.keyCode == 190 || events.keyCode == 110 ||
                // Allow: Ctrl+A
                ((events.keyCode == 65 && events.ctrlKey === true) || events.keyCode == 97) ||
                // allow minus
                events.keyCode == 173 || events.keyCode == 109 || events.keyCode == 189 ||
                /*// Allow Copy
                ((events.keyCode == 67 && events.ctrlKey === true) || events.keyCode == 99) ||
                // Allow paste
                ((events.keyCode == 86 && events.ctrlKey === true) || events.keyCode == 118) ||*/
                // Allow: home, end, left, right, up and down
                (events.keyCode >= 35 && events.keyCode <= 40)) {
                    // let it happen, don't do anything
                    return;
                } else {
                    // Ensure that it is a number and stop the keypress
                    if (events.shiftKey || (events.keyCode < 48 || events.keyCode > 57) && (events.keyCode < 96 || events.keyCode > 105)) {
                        events.preventDefault();
                    }
                }
            });
            // Styles
            /* apply width to image */
            mainContainer.on("keyup blur mouseup", ".img-width", function() {
                if (jQuery(this).val() == '' && jQuery(this).data('default')) jQuery(this).val(jQuery(this).data('default'));
                img_width = jQuery(this).val();
                layer_id = jQuery(this).parents("tr.layer").attr("id");
                var previewLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                previewLayer.children().css("width", img_width);
                if (previewLayer.children().find("iframe")) {
                    ele = jQuery(this);
                    slide_id = previewLayer.parents(".preview").attr("slide-id");
                    dragLayer(ele, slide_id, layer_id);
                }
            });
            /* apply height to image */
            mainContainer.on("keyup blur mouseup", ".img-height", function() {
                if (jQuery(this).val() == '' && jQuery(this).data('default')) jQuery(this).val(jQuery(this).data('default'));
                img_height = jQuery(this).val();
                layer_id = jQuery(this).parents("tr.layer").attr("id");
                var previewLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                previewLayer.children().css("height", img_height);
                if (previewLayer.children().find("iframe")) {
                    ele = jQuery(this);
                    slide_id = previewLayer.parents(".preview").attr("slide-id");
                    dragLayer(ele, slide_id, layer_id);
                }
            });
            /* apply image top position */
            mainContainer.on("keyup blur mouseup", ".img-top", function() {
                if (jQuery(this).val() == '' && jQuery(this).data('default')){ jQuery(this).val(jQuery(this).data('default'));}
                img_top = jQuery(this).val();                
                type = jQuery(this).parent().find(".img-top-px").val();
                layer_id = jQuery(this).parents("tr.layer").attr("id");
                mainContainer.find(".preview_layer[layerid='" + layer_id + "']").children().css("top", img_top + type);

            });
            /* apply image top position in px or % */
            mainContainer.on("change", ".img-top-px", function() {
                img_top = jQuery(this).prev(".img-top").val();
                type = jQuery(this).val();
                layer_id = jQuery(this).parents("tr.layer").attr("id");
                mainContainer.find(".preview_layer[layerid='" + layer_id + "']").children().css("top", img_top + type);

            });
            /* apply image left position */
            mainContainer.on("keyup blur mouseup", ".img-left", function() {
                if (jQuery(this).val() == '' && jQuery(this).data('default')) jQuery(this).val(jQuery(this).data('default'));
                img_left = jQuery(this).val();
                type = jQuery(this).next(".img-left-px").val();
                layer_id = jQuery(this).parents("tr.layer").attr("id");
                mainContainer.find(".preview_layer[layerid='" + layer_id + "']").children().css("left", img_left + type);
            });
            /* apply image left position in px or % */
            mainContainer.on("change", ".img-left-px", function() {
                img_left = jQuery(this).prev(".img-left").val();
                type = jQuery(this).val();
                layer_id = jQuery(this).parents("tr.layer").attr("id");
                mainContainer.find(".preview_layer[layerid='" + layer_id + "']").children().css("left", img_left + type);
            });
            /* apply image padding top */
            mainContainer.on("keyup blur mouseup", ".img-padding-top", function() {
                if (jQuery(this).val() == '' && jQuery(this).data('default')) jQuery(this).val(jQuery(this).data('default'));
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                var preLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                if (jQuery(this).val() != '') {
                    preLayer.children().css("padding-top", jQuery(this).val() + 'px');
                } else {
                    preLayer.children().css("padding-top", '');
                }
                if (preLayer.children().find("iframe")) {
                    ele = jQuery(this);
                    slide_id = preLayer.parents(".preview").attr("slide-id");
                    dragLayer(ele, slide_id, layer_id);
                }
            });
            /* apply image padding bottom */
            mainContainer.on("keyup blur mouseup", ".img-padding-bottom", function() {
                if (jQuery(this).val() == '' && jQuery(this).data('default')) jQuery(this).val(jQuery(this).data('default'));
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                var preLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                if (jQuery(this).val() != '') {
                    preLayer.children().css("padding-bottom", jQuery(this).val() + 'px');
                } else {
                    preLayer.children().css("padding-bottom", '');
                }
                if (preLayer.children().find("iframe")) {
                    ele = jQuery(this);
                    slide_id = preLayer.parents(".preview").attr("slide-id");
                    dragLayer(ele, slide_id, layer_id);
                }
            });
            /* apply image left padding */
            mainContainer.on("keyup blur mouseup", ".img-padding-left", function() {
                if (jQuery(this).val() == '' && jQuery(this).data('default')) jQuery(this).val(jQuery(this).data('default'));
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                var preLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                if (jQuery(this).val() != '') {
                    preLayer.children().css("padding-left", jQuery(this).val() + 'px');
                } else {
                    preLayer.children().css("padding-left", '');
                }
                if (jQuery(".preview_layer[layerid='" + layer_id + "']").children().find("iframe")) {
                    ele = jQuery(this);
                    slide_id = preLayer.parents(".preview").attr("slide-id");
                    dragLayer(ele, slide_id, layer_id);
                }
            });
            /* apply image right padding */
            mainContainer.on("keyup blur mouseup", ".img-padding-right", function() {
                if (jQuery(this).val() == '' && jQuery(this).data('default')) jQuery(this).val(jQuery(this).data('default'));
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                var preLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                if (jQuery(this).val() != '') {
                    preLayer.children().css("padding-right", jQuery(this).val() + 'px');
                } else {
                    preLayer.children().css("padding-right", '');
                }
                if (jQuery(".preview_layer[layerid='" + layer_id + "']").children().find("iframe")) {
                    ele = jQuery(this);
                    slide_id = preLayer.parents(".preview").attr("slide-id");
                    dragLayer(ele, slide_id, layer_id);
                }
            });
            /* apply font on text */
            mainContainer.on("keyup blur mouseup", ".text-font-family", function() {
                if (jQuery(this).val() == '' && jQuery(this).data('default')) jQuery(this).val(jQuery(this).data('default'));
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                var preLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                preLayer.children().css("font-family", jQuery(this).val());
            });
            /* apply font size on text */
            mainContainer.on("keyup blur mouseup", ".text-font-size", function() {
                if (jQuery(this).val() == '' && jQuery(this).data('default')) jQuery(this).val(jQuery(this).data('default'));
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                var preLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                if (jQuery(this).val() != '') {
                    preLayer.children().css("font-size", jQuery(this).val() + 'px');
                } else {
                    preLayer.children().css("font-size", '');
                }
            });
            /* apply line-height on text */
            mainContainer.on("keyup blur mouseup", ".text-line-height", function() {
                if (jQuery(this).val() == '' && jQuery(this).data('default')) jQuery(this).val(jQuery(this).data('default'));
                var line_height = jQuery(this).val();
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                var preLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                if (line_height == "") {
                    if (jQuery(this).parents(".style-layer-table").find(".text-font-size").val()) {
                        jQuery(this).val(jQuery(this).parents(".style-layer-table").find(".text-font-size").val());
                        preLayer.children().css("line-height", jQuery(this).val() + "px");
                    } else {
                        preLayer.children().css("line-height", 'Normal');
                    }
                } else if(line_height == "Normal"){
                    preLayer.children().css("line-height","Normal");
                } else {
                    preLayer.children().css("line-height", line_height + "px");
                }
            });
            /* apply font color */
            mainContainer.on("focus blur", ".text-color", function() {
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                var preLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                if (jQuery(this).val() != "") {
                    preLayer.children().css('color', hex2rgba(jQuery(this).val(), jQuery(this).attr('data-opacity')));
                } else {
                    preLayer.children().css("color", "#000000");
                }
            });
            /* apply background color */
            mainContainer.on("focus blur", ".bg-color", function() {
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                var preLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");
                if (jQuery(this).val() != "") {
                    preLayer.children().css("background-color", hex2rgba(jQuery(this).val(), jQuery(this).attr('data-opacity')));
                } else {
                    preLayer.children().css("background-color", "transparent");
                }
            });
            /* apply radius to text or image */
            mainContainer.on("keyup blur mouseup", ".rounded-corner", function() {
                if (jQuery(this).val() == '' && jQuery(this).data('default')) jQuery(this).val(jQuery(this).data('default'));
                var radius = jQuery(this).val();
                var layer_id = jQuery(this).parents("tr.layer").attr("id");
                mainContainer.find(".preview_layer[layerid='" + layer_id + "']").children().css("border-radius", radius + "px");
            });
            /* aply custom style on text or image */
            mainContainer.on("blur", ".custom-style", function() {
                style_css = jQuery(this).val();
                layer_id = jQuery(this).parents("tr.layer").attr("id");
                jQuery(this).parents(".styles").find(".img-width", ".img-height", ".img-top", ".img-left", ".img-padding-top", ".img-padding-right", ".img-padding-bottom", ".img-padding-left", ".text-font-fam", ".text-font-size", ".text-line-height", ".text-color", ".bg-color", ".rounded-corner").trigger("blur");
                var style_options = ['position', 'z-index', 'width', 'height', 'top', 'left', 'padding', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right', 'font-family', 'font-size', 'line-height', 'color', 'background-color', 'border-radius'];
                var previewLayer = mainContainer.find(".preview_layer[layerid='" + layer_id + "']");

                if (previewLayer.hasClass('preview-carousel')) {
                    previewLayer = previewLayer;
                } else {
                    previewLayer = previewLayer.children();
                }
                var style_string = previewLayer.attr('style');
                if (typeof style_string != 'undefined') {
                    style_arr = style_string.split(";");
                    for (i = 0; i < style_arr.length; i++) {
                        style_val = style_arr[i].split(":");
                        if (jQuery.trim(style_val[0]) != '' && jQuery.inArray(jQuery.trim(style_val[0]), style_options) == -1) {
                            previewLayer.css(jQuery.trim(style_val[0]), '');
                        }
                    }
                }
                var customString=jQuery(this).val();
                if (customString != "") {                                        
                    if(style_string!=''){style_string+=customString}else{style_string=customString}                    
                    previewLayer.attr('style',style_string);                    
                }
            });

            /* apply id attribute */
            mainContainer.on("keyup blur mouseup", ".layer-id", function() {
                if (jQuery(this).val() != "") {
                    id = jQuery(this).val();
                    layer_id = jQuery(this).parents("tr.layer").attr("id");
                    mainContainer.find(".preview_layer[layerid='" + layer_id + "']").children().attr("id", id);
                }
            });
            /* apply class attribute */
            mainContainer.on("blur", ".layer-class", function() {
                if (jQuery(this).val() != "") {
                    cls = jQuery(this).val();
                    layer_id = jQuery(this).parents("tr.layer").attr("id");
                    mainContainer.find(".preview_layer[layerid='" + layer_id + "']").children().addClass(cls);
                }
            });
            /* apply title attribute */
            mainContainer.on("keyup blur mouseup", ".layer-title", function() {
                if (jQuery(this).val() != "") {
                    title = jQuery(this).val();
                    layer_id = jQuery(this).parents("tr.layer").attr("id");
                    mainContainer.find(".preview_layer[layerid='" + layer_id + "']").children().attr("title", title);
                }
            });
            /* apply alt attribute */
            mainContainer.on("keyup blur mouseup", ".layer-alt", function() {
                if (jQuery(this).val() != "") {
                    alt = jQuery(this).val();
                    layer_id = jQuery(this).parents("tr.layer").attr("id");
                    mainContainer.find(".preview_layer[layerid='" + layer_id + "']").children().attr("alt", alt);
                }
            });
            /* apply rel attribute */
            mainContainer.on("keyup blur mouseup", ".layer-rel", function() {
                if (jQuery(this).val() != "") {
                    rel = jQuery(this).val();
                    layer_id = jQuery(this).parents("tr.layer").attr("id");
                    mainContainer.find(".preview_layer[layerid='" + layer_id + "']").children().attr("rel", rel);
                }
            });
            /* enable/disable dragging layer in preview */
            mainContainer.on("click", ".lock-layer", function(e) {
                e.preventDefault();
                slide_id = jQuery(this).parents(".all-layer-table").attr("slide-id");
                layer_id = jQuery(this).parents("tr.layer").attr("id");
                var previewLayer = mainContainer.find(".preview[slide-id='" + slide_id + "'] .preview_layer[layerid='" + layer_id + "']");
                // if this is a carousel layer
                if (mainContainer.find('tr.layer[id="' + layer_id + '"] .carousel-layer').is(':checked') && jQuery(this).hasClass('active-lock')) return false;
                if (jQuery(this).attr("lock") == "0") {
                    previewLayer.children().draggable();
                    previewLayer.children().draggable("disable");
                    jQuery(this).attr("lock", "1");
                    jQuery(this).next().val("1");
                    jQuery(this).addClass("active-lock");
                } else {
                    data = previewLayer.children().html();
                    if (data && data.indexOf("iframe") >= 0) {
                        previewLayer.children("p").find('.dragme').remove();
                        temp = previewLayer.children("p");
                        if (jQuery(temp).outerWidth() == 0) {
                            ow = jQuery(temp).find("iframe").outerWidth();
                        } else {
                            ow = jQuery(temp).outerWidth();
                        }
                        if (jQuery(temp).outerHeight() == 0) {
                            oh = jQuery(temp).find("iframe").outerHeight();
                        } else {
                            oh = jQuery(temp).outerHeight();
                        }
                        previewLayer.children("span").append('<div class="dragme"></div>');
                        var dragMe = previewLayer.children("span").find('.dragme');
                        dragMe.css({
                            "width": ow + "px",
                            "position": "absolute",
                            "top": "0",
                            "left": "0",
                            "zIndex": jQuery(temp).css("zIndex")
                        });
                    }
                    previewLayer.children().draggable();
                    previewLayer.children().draggable("enable");
                    /*jQuery(".preview[slide-id='"+slide_id+"'] .preview_layer[layerid='"+layer_id+"']").find('.no-draggable').remove();*/
                    jQuery(this).attr("lock", "0");
                    jQuery(this).next().val("0");
                    jQuery(this).removeClass("active-lock");
                }
            });
            /* highlight layer in preview */
            mainContainer.on("click", ".highlight-layer", function(e) {
                e.preventDefault();
                if (!jQuery(this).hasClass('disabled')) {
                    slide_id = jQuery(this).parents(".all-layer-table").attr("slide-id");
                    layer_id = jQuery(this).parents("tr.layer").attr("id");
                    var highlightLayer = jQuery(this).parents(".all-layer-table").find(".highlight-layer");
                    var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']");
                    var previewLayer = previewSlide.find(".preview_layer");
                    if (jQuery(this).attr("highlight") == "0") {
                        // remove highlight form other layer and apply on selected one;
                        highlightLayer.attr("highlight", "0");
                        highlightLayer.next().val(0);
                        highlightLayer.removeClass("active-highlight");
                        previewLayer.children().css("opacity", "0.5");
                        previewSlide.find(".main-bg-img").css("opacity", "0.5");
                        previewLayer.filter("[layerid='" + layer_id + "']").children().css("opacity", "1");
                        jQuery(this).attr("highlight", "1");
                        jQuery(this).next().val("1");
                        jQuery(this).addClass("active-highlight");
                    } else {
                        previewLayer.children().css("opacity", "1");
                        previewSlide.find(".main-bg-img").css("opacity", "1");
                        jQuery(this).attr("highlight", "0");
                        jQuery(this).next().val("0");
                        jQuery(this).removeClass("active-highlight");
                    }
                }
            });
            /* hide layer in preview */
            mainContainer.on("click", ".hide-layer", function(e) {
                e.preventDefault();
                slide_id = jQuery(this).parents(".all-layer-table").attr("slide-id");
                layer_id = jQuery(this).parents("tr.layer").attr("id");
                var previewLayer = mainContainer.find(".preview[slide-id='" + slide_id + "'] .preview_layer[layerid='" + layer_id + "']");
                if (jQuery(this).attr("hide") == "0") {
                    previewLayer.children().hide();
                    jQuery(this).attr("hide", "1");
                    jQuery(this).next().val("1");
                    jQuery(this).addClass("active-hide");
                } else {
                    previewLayer.children().show();
                    jQuery(this).attr("hide", "0");
                    jQuery(this).next().val("0");
                    jQuery(this).removeClass("active-hide");
                }
            });
            mainContainer.find('.all-layer-table').on('mousedown',".layer-container .move",function(e){
                jQuery(this).parents('.all-layer-table').find('.layer-container .current-layer').hide();                
            });

            /* configure post */
            mainContainer.on("click", ".configure-post", function() {
                $hidden_data = jQuery(this).parents(".limit-text");
                jQuery("#configure_post_data").dialog({
                    modal: true,
                    width: 900,
                    height: 500,
                    draggable: false,
                    open: function(event, ui) {
                        postid = $hidden_data.find(".cs-post-id").val();
                        posttype = $hidden_data.find(".cs-post-type").val();
                        postcat = $hidden_data.find(".cs_post_cat").val();
                        posttag = $hidden_data.find(".cs-post-tag").val();
                        orderby = $hidden_data.find(".cs-orderby").val();
                        order = $hidden_data.find(".cs-order").val();
                        var csPostType = jQuery("#cs_post_type");
                        if (posttype != "" && posttype != undefined) {
                            if (posttype.indexOf(",") != -1) {
                                posttype = posttype.split(",");
                                jQuery(posttype).each(function(index, value) {
                                    csPostType.find("option[value='" + value + "']").attr("selected", "selected");
                                });
                            } else csPostType.find("option[value='" + posttype + "']").attr("selected", "selected");
                        }
                        if (postcat != "" && postcat != undefined) {
                            if (postcat.indexOf(",") != -1) {
                                postcat = postcat.split(",");
                                jQuery(postcat).each(function(index, value) {
                                    csPostType.find("option[value='" + value + "']").attr("selected", "selected");
                                });
                            } else csPostType.find("option[value='" + postcat + "']").attr("selected", "selected");
                        }
                        if (posttag != "" && posttag != undefined) {
                            if (posttag.indexOf(",") != -1) {
                                posttag = posttag.split(",");
                                jQuery(posttag).each(function(index, value) {
                                    csPostType.find("option[value='" + value + "']").attr("selected", "selected");
                                });
                            } else csPostType.find("option[value='" + posttag + "']").attr("selected", "selected");
                        }

                        jQuery("#cs_order_by option[value='" + orderby + "']").attr("selected", "selected");
                        jQuery("#cs_order option[value='" + order + "']").attr("selected", "selected");
                        csPostType.trigger('click');
                        jQuery(this).find("#cs_order").data("post-id", postid).trigger("change");
                        
                    },
                    close: function(event, ui) {
                        post_id = jQuery(this).find("input[name='cs_post_id']:checked").val();
                        $hidden_data.find(".cs-post-id").val(post_id);
                        if (jQuery(this).find("#cs_post_type").val()) {
                            post_type = jQuery(this).find("#cs_post_type").val()
                            ptype = post_type.join(",");
                            $hidden_data.find(".cs-post-type").val(ptype);
                        }
                        if (jQuery(this).find("#cs_post_cat").val()) {
                            post_cat = jQuery(this).find("#cs_post_cat").val()
                            pcat = post_cat.join(",");
                            $hidden_data.find(".cs-post-cat").val(pcat);
                        }
                        if (jQuery(this).find("#cs_post_tags").val()) {
                            post_tag = jQuery(this).find("#cs_post_tags").val()
                            ptag = post_tag.join(",");
                            $hidden_data.find(".cs-post-tag").val(ptag);
                        }
                        cs_order_by = jQuery(this).find("#cs_order_by").val()
                        $hidden_data.find(".cs-orderby").val(cs_order_by);
                        cs_order = jQuery(this).find("#cs_order").val()
                        $hidden_data.find(".cs-order").val(cs_order);
                        cs_order = jQuery(this).find("#cs_order").val()
                        $hidden_data.find(".cs-order").val(cs_order);
                        textlen = $hidden_data.find(".textlength").val();
                        sdata = setShortcodeData(post_id, textlen, $hidden_data.parents(".layer-daynamic-content").find(".daynamic-content-text"));
                        $hidden_data.parents(".layer-daynamic-content").find(".daynamic-content-text").trigger('blur');
                    }
                });
            });
            /* Set text length in daynamic text */
            mainContainer.on("blur", ".textlength", function() {
                postid = jQuery(this).parents(".layer-daynamic-content").find(".cs-post-id").val();
                textlen = jQuery(this).val();
                sdata = setShortcodeData(postid, textlen, jQuery(this).parents(".layer-daynamic-content").find(".daynamic-content-text"));
                jQuery(this).parents(".layer-daynamic-content").find(".daynamic-content-text").trigger("blur");
            });
            /* filter post on daynamic text */
            mainContainer.find('#configure_post_data').on("click ", ".ordercls,.select-small", function() {
                post_type = "";
                post_cat = "";
                post_tags = "";
                if (jQuery("#cs_post_type option:selected").length){ post_type = jQuery("#cs_post_type").val();}
                if (jQuery("#cs_post_cat option:selected").length) {post_cat = jQuery("#cs_post_cat").val();}
                if (jQuery("#cs_post_tags option:selected").length) {post_tags = jQuery("#cs_post_tags").val();}
                orderby = jQuery("#cs_order_by").val();
                order = jQuery("#cs_order").val();
                var data = {
                    'action': 'cloud_post_data',
                    'cs_post_type': post_type + '',
                    'cs_post_cat': post_cat + '',
                    'cs_post_tags': post_tags + '',
                    'cs_order_by': orderby + '',
                    'cs_order': order + ''
                };
                
                postid = jQuery(this).data("post-id");
                mainContainer.find('#filter_posts').find('table').append(jQuery('<tr>').append(jQuery('<td>', {
                    'class': 'text-center'
                }).append('<img src="' + CS_ROOT_URL + '/images/loading.gif" />')));
                jQuery.post(ajaxurl, data, function(response) {
                    var parsed = jQuery.parseJSON(response);                    
                    filterPost(parsed, postid);
                });
            });
            /* prevent a in preview layer */
            mainContainer.on("click", ".preview_layer a", function(e) {
                e.preventDefault();
                return false;
            });
            /* toggle layer in layer area when clicked layer in preview panel */
            mainContainer.on("click", ".preview_layer h1, .preview_layer h2, .preview_layer h3, .preview_layer h4, .preview_layer h5, .preview_layer h6, .preview_layer span, .preview_layer img,.preview_layer a", function(e) {
                layer_id = jQuery(this).parents(".preview_layer").attr("layerid");
                slide_id = jQuery(this).parents(".preview").attr("slide-id");
                //$(this).parents(".ui-tabs-panel[slide-id='"+slide_id+"']").find(".slides-options").find(".options[setting='layer-options']").show();
                mainContainer.find(".slide-options[setting='layer-options']").trigger("click");
                mainContainer.find(".all-layer-table[slide-id='" + slide_id + "']").find("tr#" + layer_id).find(".layer-main").trigger("click");
            });
            /* set slider width according to valuer enter */
            mainContainer.on("keyup blur mouseup", ".slider-width,.slider-height", function() {
                changeSliderWidthHeight();
            });
            /* apply custome styles*/
            mainContainer.on("keyup blur mouseup", ".custom-styles", function() {

                var str = jQuery(this).val();                
                var pattern = new RegExp(/([^{}]+)\s*{\s*([^{}]+)\s*\}/gm);
                while ((match = pattern.exec(str)) != null) {
                    var selector = match[1].trim();
                    var rule = {};
                    match[2] = match[2].trim();
                    var parts = match[2].split(";");
                    parts.forEach(function(part) {
                        part = part.trim();
                        if (part == "") {
                            return true;
                        }
                        var attr = "";
                        var val = "";
                        if (part.indexOf("filter") === 0) {
                            attr = "filter";
                            val = part.replace(/^filter\s*:\s*/, "");
                        } else {
                            var subpart = part.split(":");
                            attr = subpart[0].trim();
                            val = subpart[1].trim();
                        }
                        if (attr == "") {
                            return true;
                        }
                        jQuery(selector).css(attr, val);
                    });
                }

            });
            /* duplicate slide*/
            mainContainer.on("click", ".duplicate-slide", function(e) {
                e.preventDefault();
                loaderPopup.show();
                objSlide=jQuery(this);
                slide_id = objSlide.attr("slide-id");                
                setTimeout(function(){
                    var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']");                
                    var tabCounter = slideTabs.find('ul li').length + 1;
                    id = "tabs-" + tabCounter;
                    label = "Slide#" + tabCounter;
                    li = jQuery(settings.tabTemplate.replace(/#\{href\}/g, "#" + id).replace(/#\{label\}/g, label))
                    settings.tabs.find(".ui-tabs-nav").append(li);
                    slideTabs.find("li").removeClass("ui-tabs-active ui-state-active");
                    li.addClass('ui-tabs-active ui-state-active');
                    var tabContent = objSlide.parents(".ui-tabs-panel").children().clone();
                    var old_slide_index=parseInt(slide_id.slice(6))-1;
                    new_slide_id = "slide-" + tabCounter;
                    $div = jQuery("<div id='" + id + "' slide-id='" + new_slide_id + "'>").append(tabContent);
                    slide = (parseInt(tabCounter) - 1);
                    try {
                        slideno = 0;
                        $div.find('.slide-property input,.slide-property select,.slide-property textarea').each(function() {
                            if (jQuery(this).parents(".carousel-level").length > 0) {
                                slideno = jQuery(this).parents("table.carousel-multi-level").find("tr").index(jQuery(this).parents("tr"));
                                input_name = jQuery(this).attr('name');                            
                                if (input_name.indexOf('slides[layers][' + old_slide_index + '][properties][carousel-level]') == -1) {
                                    jQuery(this).attr('name', 'slides[layers][' + slide + '][properties][carousel-level][' + slideno + '][' + input_name + ']');
                                    jQuery(this).attr('data-name',input_name);
                                    slideno++;
                                } else {
                                    jQuery(this).attr('name', 'slides[layers][' + slide + '][properties][carousel-level][' + slideno + '][' + jQuery(this).attr('data-name') + ']');                                
                                }
                            } else {
                                name = jQuery(this).attr('name');                            
                                if (name.indexOf('slides[layers][' + old_slide_index + '][properties]') == -1) {
                                    jQuery(this).attr('name', 'slides[layers][' + slide + '][properties][' + name + ']');
                                    jQuery(this).attr('data-name',name);
                                } else {
                                    jQuery(this).attr('name', 'slides[layers][' + slide + '][properties][' + jQuery(this).attr('data-name') + ']');
                                }
                            }
                        });
                    } catch (exception) {
                        console.log(exception);
                        return false;
                    }
                    try {
                        $div.find('.all-layer-table .layer').each(function(slide_no) {
                            jQuery(this).find('input,select,textarea,checkbox').each(function() {
                                if (!jQuery(this).hasClass("attach-layer") && !jQuery(this).hasClass("attr-value")) {
                                    name = jQuery(this).attr('name');
                                    if (name.indexOf('slides[layers][' + old_slide_index + '][sub_layer]') == -1) {
                                        jQuery(this).attr('name', 'slides[layers][' + slide + '][sub_layer][' + slide_no + '][properties][' + jQuery(this).attr('name') + ']');
                                        jQuery(this).attr('data-name',name);
                                    } else {
                                        jQuery(this).attr('name', 'slides[layers][' + slide + '][sub_layer][' + slide_no + '][properties][' + jQuery(this).attr('data-name') + ']');                                    
                                    }
                                }
                            });
                            jQuery(this).find('.carousel-attr select,.carousel-attr textarea').each(function() {
                                //jQuery(this).attr('data-name', jQuery(this).attr('name') );
                                no = jQuery(this).parents("table.carousel-attr").find("tr").index(jQuery(this).parents("tr"));
                                input_name = jQuery(this).attr('name');
                                if (input_name.indexOf('slides[layers][' + old_slide_index + '][sub_layer]') == -1) {
                                    jQuery(this).attr('name', 'slides[layers][' + slide + '][sub_layer][' + slide_no + '][properties][carousel_attr][' + no + '][' + input_name + ']');
                                    jQuery(this).attr('data-name',input_name);
                                } else {
                                    jQuery(this).attr('name', 'slides[layers][' + slide + '][sub_layer][' + slide_no + '][properties][carousel_attr][' + no + '][' + jQuery(this).attr('data-name') + ']');                                
                                }
                            });                                                                                  
                        });
                    } catch (exception) {
                        console.log(exception);
                        return false;
                    }
                    $div.find(".2d_trans_ids,.3d_trans_ids,.slide-transition,.duplicate-slide,.preview,.all-layer-table").attr("slide-id", "slide-" + tabCounter);
                    mainContainer.find(".main-settings li > ul li").find("a").each(function() {
                        if (jQuery(this).attr("setting")) {
                            old_href = jQuery(this).attr("setting");
                            jQuery(this).attr("href", "#" + old_href + "-" + tabCounter);
                        }
                    });
                    $div.find(".options").each(function() {
                        old_id = jQuery(this).attr("setting");
                        jQuery(this).attr("id", old_id + "-" + tabCounter);
                    });
                    $div.find('.jquery-checkbox').remove();
                    settings.tabs.append($div);
                    $div.find(".add-new-layer").attr("id", "slide-" + tabCounter);
                    $div.find('.all-layer-table input.checkbox').each(function() {
                        jQuery(this).checkbox({
                            empty: CS_ROOT_URL + "/images/empty.png"
                        });
                    });
                    //////////////////////////////////////////////$div.find('.tooltip').tooltipster();
                    $div.find(".preview .preview_layer").each(function() {
                        layer_id = jQuery(this).attr("layerid");                        
                        rno = new Date().getTime();
                        rno += Math.floor((Math.random() * 100) + 1) + '';
                        $div.find("tr#" + layer_id).attr("id", rno);
                        var tableRow = jQuery("tr#" + rno);
                        tableRow.find(".remove-layer,.delete-img-icon,.layer-add-img,.layer-add-media").attr("layerid", rno);
                        jQuery(this).find("img").attr("layerid", rno);
                        jQuery(this).attr("layerid", rno);
                        jQuery(this).children().attr("layerid", rno);
                        tableRow.find('input[data-name="layer_id"],[name="layer_id"]').val(rno);
                        tableRow.find('.duplicate-layer').attr('layerid', rno);
                        ele = tableRow.find(".layer-container");
                        dragLayer(ele, "slide-" + tabCounter, rno);
                        textlen = tableRow.find(".content").find('.layer-daynamic-content').find(".textlength").val();
                        postid = tableRow.find(".content").find('.layer-daynamic-content').find(".cs-post-id").val();
                        sdata = setShortcodeData(postid, textlen, tableRow.find(".daynamic-content-text"));
                        tableRow.find(".daynamic-content-text").data("post_data", sdata);
                    });
                    refreshTabs();
                    mainContainer.find("#" + id).find('input.checkbox').each(function() {
                        title = "";
                        if (jQuery(this).data("title") != "") title = jQuery(this).data("title");
                        jQuery(this).checkbox({
                            empty: CS_ROOT_URL + "images/empty.png"
                        });
                        if (title != "") {
                            jQuery(this).next(".jquery-checkbox").addClass("tooltip").data("title", title);
                        }
                    });
                    li.find("a").trigger("click");
                    slideTabs.find('ul').sortable({
                        stop: moveTabDiv
                    });
                    mainContainer.find(".ui-tabs-panel").hide();
                    mainContainer.find("#" + id).show();

                    mainContainer.find(".all-layer-table[slide-id='" + new_slide_id + "'] tbody").sortable({
                        helper: fixHelperModified,
                        stop: updateIndex,
                        start: hidediv,
                        handle: ".move"
                    });
                    tabCounter++;

                    jQuery('#'+id).find('input.minicolors').each(function() {
                        var color_value = jQuery(this).val();
                        jQuery(this).minicolors('destroy');
                        jQuery(this).minicolors({
                            control: 'hue',
                            defaultValue: color_value,
                            inline: false,
                            opacity: jQuery(this).attr('data-opacity'),
                            position: 'bottom left',
                            theme: 'default'
                        });
                    }); 
                    loaderPopup.hide();

                },100);

            });
            /* display slider preview in popup */
            mainContainer.on("click", ".enter-preview", function(e) {
                e.preventDefault();
                mainContainer.find('form').find('input[name="hdnPreview"]').val('preview');
                mainContainer.find('input[name="save_data"]').trigger('click');
            });
            /* stop preview when click on other tab */
            slideTabs.on("tabsactivate", function(event, ui) {
                if (ui.oldPanel.find(".preview-container").next(".enter-preview").text() == "Exit Preview") {
                    ui.oldPanel.find(".preview-container").next(".enter-preview").trigger("click");
                }
            });
            /* set selected skin default values in inut fields */
            mainContainer.on("change", ".slider-skin", function() {
                curskin = jQuery(this).val();
                var conBgColor = mainContainer.find(".container-bg-clr");
                if (settings.skins[curskin]['containerBgColor'].indexOf('rgb') != -1) {
                    var color = rgb2hex(settings.skins[curskin]['containerBgColor']);
                    conBgColor.attr('data-opacity', color.opacity);
                    conBgColor.minicolors('value', color.hex);
                } else {
                    conBgColor.attr('data-opacity', 1);
                    conBgColor.minicolors('value', settings.skins[curskin]['containerBgColor']);
                }
                mainContainer.find(".container-border").val(settings.skins[curskin]['containerBorder']);
                mainContainer.find(".container-box-shadow").val(settings.skins[curskin]['containerBoxShadow']);
                mainContainer.find(".progressbar-pos").val(settings.skins[curskin]['progressBarPosition']);
                var progressBar = jQuery(".progressbar-clr");
                if (settings.skins[curskin]['progressBarColor'].indexOf('rgb') != -1) {
                    var color = rgb2hex(settings.skins[curskin]['progressBarColor']);
                    progressBar.attr('data-opacity', color.opacity);
                    progressBar.minicolors('value', color.hex);
                } else {
                    progressBar.attr('data-opacity', 1);
                    progressBar.minicolors('value', settings.skins[curskin]['progressBarColor']);
                }
                thick = settings.skins[curskin]['progressBarThick'];
                thick = thick.replace("px", "");
                mainContainer.find(".progressbar-thick").val(thick);
                mainContainer.find(".img-loader").val(settings.skins[curskin]['imgLoader']);
                var MyArray = {
                    ".prev-arrow-img": settings.skins[curskin]['arrow']['imgPrev'],
                    ".next-arrow-img": settings.skins[curskin]['arrow']['imgNext'],
                    ".prev-hover-arrow-img": settings.skins[curskin]['arrow']['imgPrevActivated'],
                    ".next-hover-arrow-img": settings.skins[curskin]['arrow']['imgNextActivated'],
                    ".arrow-pos-offset": settings.skins[curskin]['arrow']['positionOffset'],
                    ".arrow-responsive-level": settings.skins[curskin]['arrow']['responsiveLevel'],
                    ".bullet-pos": settings.skins[curskin]['bullet']['position'],
                    ".bullet-horizontal-offset": settings.skins[curskin]['bullet']['horizontalOffset'],
                    ".bullet-vertical-offset": settings.skins[curskin]['bullet']['verticalOffset'],
                    ".bullet-opacity": settings.skins[curskin]['bullet']['itemOpacity'],
                    ".bullet-margin": settings.skins[curskin]['bullet']['itemMargin'],
                    ".bullet-img": settings.skins[curskin]['bullet']['imgItem'],
                    ".bullet-active-img": settings.skins[curskin]['bullet']['imgItemActivated'],
                    ".bullet-left-container-img": settings.skins[curskin]['bullet']['imgContainerLeft'],
                    ".bullet-right-container-img": settings.skins[curskin]['bullet']['imgContainerRight'],
                    ".bullet-active-opacity": settings.skins[curskin]['bullet']['activatedOpacity'],
                    ".bullet-responsive-level": settings.skins[curskin]['bullet']['responsiveLevel'],
                    ".thumb-position-offset": settings.skins[curskin]['thumb']['positionOffset'],
                    ".thumb-container-padding": settings.skins[curskin]['thumb']['containerPadding']
                };
                for (var key in MyArray) {
                    mainContainer.find(key).val(MyArray[key]);
                }
                var thumbBgColor = mainContainer.find(".thumb-bg-color");
                if (settings.skins[curskin]['containerBgColor'].indexOf('rgb') != -1) {
                    var color = rgb2hex(settings.skins[curskin]['containerBgColor']);
                    thumbBgColor.attr('data-opacity', color.opacity);
                    thumbBgColor.minicolors('value', color.hex);
                } else {
                    thumbBgColor.attr('data-opacity', 1);
                    thumbBgColor.minicolors('value', settings.skins[curskin]['containerBgColor']);
                }
                mainContainer.find(".thumb-opacity").val(settings.skins[curskin]['thumb']['itemOpacity']);
                mainContainer.find(".thumb-margin").val(settings.skins[curskin]['thumb']['itemMargin']);
                bwidth = settings.skins[curskin]['thumb']['itemBorderWidth'];
                bwidth = bwidth.replace("px", "");
                mainContainer.find(".thumb-border-width").val(bwidth);
                var thumbBorderColor = mainContainer.find(".thumb-border-color");
                if (settings.skins[curskin]['thumb']['itemBorderColor'].indexOf('rgb') != -1) {
                    var color = rgb2hex(settings.skins[curskin]['thumb']['itemBorderColor']);
                    thumbBorderColor.attr('data-opacity', color.opacity);
                    thumbBorderColor.minicolors('value', color.hex);
                } else {
                    thumbBorderColor.attr('data-opacity', 1);
                    thumbBorderColor.minicolors('value', settings.skins[curskin]['thumb']['itemBorderColor']);
                }
                var thumbActiveBorderColor = mainContainer.find(".thumb-active-border-color");
                if (settings.skins[curskin]['thumb']['activatedBorderColor'].indexOf('rgb') != -1) {
                    var color = rgb2hex(settings.skins[curskin]['thumb']['activatedBorderColor']);
                    thumbActiveBorderColor.attr('data-opacity', color.opacity);
                    thumbActiveBorderColor.minicolors('value', color.hex);
                } else {
                    thumbActiveBorderColor.attr('data-opacity', 1);
                    thumbActiveBorderColor.minicolors('value', settings.skins[curskin]['thumb']['activatedBorderColor']);
                }
                mainContainer.find(".thumb-active-opacity").val(settings.skins[curskin]['thumb']['activatedOpacity']);
                mainContainer.find(".no-thumb-img").val(settings.skins[curskin]['thumb']['imgNoThumb']);
                mainContainer.find(".thumb-responsive-level").val(settings.skins[curskin]['thumb']['responsiveLevel']);
                mainContainer.find(this).focus();
            });

            mainContainer.on("keyup blur mouseup",'.container-bg-clr',function(){
                changeBGColor(jQuery(this));               
            });

            mainContainer.on("change",'.backsize',function(){
                changeSliderWidthHeight(function() {
                });
            });

            /* check file is selcted or not */
            mainContainer.on("click", ".importfile", function() {
                if (mainContainer.find("#import_file").val() == "") {
                    alert("Please select file to import");
                    return false;
                }
                mainContainer.find("#hidden_action").val("ImportSlider");
                mainContainer.find("#frm_import_export").submit();
            });
            /* submit form on export slider */
            mainContainer.on("click", ".exportslider", function() {
                if (!mainContainer.find("#export_sliders option:selected").length) {
                    alert("Please select any slider to export");
                    return false;
                }
                mainContainer.find("#hidden_action").val("ExportSlider");
                mainContainer.find("#frm_import_export").submit();
            });
            /* check/uncheck all checkbox on listing */
            mainContainer.on("click", ".checkall", function() {
                if (jQuery(this).is(":checked")) jQuery(".checkone").attr("checked", true);
                else jQuery(".checkone").attr("checked", false);
            });
            /* check checkbox is checked or not befor duplicate slider */
            mainContainer.on("click", "#duplicate-slider", function() {
                if (jQuery(".checkone:checked").length == 0) {
                    alert("Select at least one slider to duplicate");
                    return false;
                }
                ans = confirm("Are you sure you want to duplicate slider(s)?");
                if (ans) {
                    mainContainer.find("#hiddenaction").val("duplicateall");
                    mainContainer.find('#frmslider_list').submit();
                } else return false;
            });
            /* check checkbox is checked or not befor delete slider */
            mainContainer.on("click", "#delete-slider", function() {
                if (mainContainer.find(".checkone:checked").length == 0) {
                    alert("Select at least one slider to delete");
                    return false;
                }
                ans = confirm("Are you sure you want to delete slider(s)?");
                if (ans) {
                    mainContainer.find("#hiddenaction").val("deleteall");
                    mainContainer.find('#frmslider_list').submit();
                } else return false;
            });
            /* checkbox for trouble and setting on list page */
            mainContainer.find(".troubleshoot-settings input.checkbox").checkbox({
                empty: CS_ROOT_URL + "/images/empty.png"
            });
            /* submit page on enter for pagination */
            mainContainer.on("keypress", "#cs_cur_page", function(e) {
                if (e.keyCode == 13) {
                    document.location = "admin.php?page=cloud-slider-list&paged=" + jQuery(this).val();
                }
            });
            /* submit for access permission */
            mainContainer.on("click", "#frm_cs_permission #update-access", function(e) {
                e.preventDefault();
                ans = confirm('WARNING: This option controls who can access to this plugin, you can easily lock out yourself by accident. Please, make sure that you have entered a valid capability without whitespaces or other invalid characters. Do you want to proceed?');
                if (ans) {
                    mainContainer.find("#frm_cs_permission").submit();
                }
            });
            /* check purchase code and update auto update settings */
            mainContainer.on('click', '#cs-update', function(e) {
                var cUpdate = mainContainer.find('#cs-update');
                e.preventDefault();
                if (mainContainer.find("#cs-code").val() != "") {
                    jQuery(this).next().text('Validating ...').css('color', '#333');
                    jQuery.post(ajaxurl, mainContainer.find("#frm_cs_update").serialize(), function(data) {
                        data = jQuery.parseJSON(data);
                        cUpdate.next().html(data['message']);
                        if (data['success'] == true) {
                            cUpdate.next().css('color', '#4b982f');
                        } else {
                            cUpdate.next().css('color', '#c33219');
                        }
                    });
                } else {
                    alert("Enter purchase code");
                    mainContainer.find("#cs-code").focus();
                    return false;
                }
            });
            mainContainer.on('click', '#cs-googlefont-add', function(e) {
                e.preventDefault();
                mainContainer.find('.table-googlefonts').append('<tr><td width="95%"><input type="text" name="cs_googlefonts[]" class="input-long" value=""/></td><td><a href="#" class="cs-googlefont-remove action-icon" title="Remove Google Font"><i class="fa fa-trash"></i></a></td></tr>');
            });
            mainContainer.on('click', '.cs-googlefont-remove', function(e) {
                e.preventDefault();
                jQuery(this).closest('tr').remove();
            });
            /* display tooltip */
            mainContainer.on("mouseover", ".tooltip", function() {
                // Hover over code
                /*if($(this).parents(".main-settings").length > 0 || $(this).parents(".update-cloudslider").length > 0)
                return false;*/
                var title = jQuery(this).data('title');
                ///$(this).data('tipText', title).removeAttr('title');
                jQuery('<div class="showtooltip"></div>').text(title).appendTo('body').fadeIn('slow');
            });
            mainContainer.find('#frmslider input, #frmslider select').on("keyup keypress", function(e) {
                var code = e.keyCode || e.which;
                if (code == 13) {
                    e.preventDefault();
                    return false;
                }
            });
            mainContainer.on("click", ".content-subnav a", function(e) {
                e.preventDefault();
                if (jQuery(this).hasClass('kr-disabled')) return false;
                jQuery(this).parents(".content-subnav").find('input').val(jQuery(this).attr("data-type"));
            });
            mainContainer.on("click", ".layer-content-text a", function(e) {
                e.preventDefault();
                jQuery(this).parents(".content-nav").find('.content-subnav input').val(jQuery(this).attr("tag"));
            });
            mainContainer.on('click', '.delete_slider', function(e) {
                e.preventDefault();
                var flag = confirm('Are you sure want to delete slider?');
                //console.log(flag);
                if (flag) {
                    window.location = jQuery(this).attr('href');
                } else {
                    return false;
                }
            });
            /* set position of tooltip on mouse move */
            mainContainer.on("mousemove", ".tooltip", function(e) {
                var tootip = jQuery(".showtooltip");
                if (jQuery(this).parents(".main-settings").length > 0) {
                    var mousex = e.pageX - tootip.outerWidth() - 20; //Get X coordinates
                    var mousey = e.pageY - 12; //Get Y coordinates
                } else {
                    var mousex = e.pageX - (tootip.outerWidth() / 2); //Get X coordinates
                    var mousey = e.pageY + 25; //Get Y coordinates
                }
                tootip.css({
                    top: mousey,
                    left: mousex
                })
            });
            /* remove tooltip on mouse out */
            mainContainer.on("mouseout", ".tooltip", function() {
                // Hover out code
                jQuery(this).data('title', jQuery(this).data('tipText'));
                jQuery('.showtooltip').remove();
            });
            /* remove tooltip on mouse focus */
            mainContainer.on("focus click", ".tooltip", function() {
                jQuery('.showtooltip').remove();
            });
            mainContainer.find('.slides-options .minicolors').live('change', function() {
                if (jQuery(this).data('opacity') < 1) {
                    jQuery(this).data('value', jQuery(this).minicolors('rgbaString'));
                } else {
                    jQuery(this).data('value', jQuery(this).val());
                }
                jQuery(this).trigger('blur');
            });
            jQuery(document).ready(function() {   
                mainContainer.find('input.minicolors').each(function() {
                    var color_value = jQuery(this).val();
                    jQuery(this).minicolors('destroy').minicolors({
                        control: 'hue',
                        inline: false,
                        opacity: true,
                        position: 'bottom left',
                        theme: 'default'
                    });
                });
                mainContainer.find('div.minicolors').each(function() {
                    jQuery(this).wrap("<td></td>");
                });
                if (!mainContainer.hasClass('edit')) {
                    //mainContainer.find(".add-new-slide").trigger("click");
                    mainContainer.find(".slider-skin").trigger("change");
                } else {
                    //mainContainer.find(".slider-skin").trigger("change");
                    
                    slideTabs.tabs();
                    var tabCounter = slideTabs.find('ul li').length + 1;
                    
                    mainContainer.find(".all-layer-table tbody").sortable({
                        helper: fixHelperModified,
                        stop: updateIndex,
                        start: hidediv,
                        handle: ".move"
                    });
                    
                    slideTabs.removeClass("hidden");
                    mainContainer.find('.all-layer-table .current-layer > div').hide();
                    slideTabs.find("div.ui-tabs-panel").each(function() {
                        jQuery(this).find(".slide-property").find('input.kenburn').checkbox({
                            empty: CS_ROOT_URL + "/images/empty.png"
                        });
                        jQuery(this).find(".slide-property").find('input.carousel').checkbox({
                            empty: CS_ROOT_URL + "/images/empty.png"
                        });
                        title = jQuery(this).find(".slide-property").find('input.misc-hidden').data("title");
                        jQuery(this).find(".slide-property").find('input.misc-hidden').checkbox({
                            empty: CS_ROOT_URL + "/images/empty.png"
                        });
                        if (title) {
                            jQuery(this).find('input.misc-hidden').next(".jquery-checkbox").addClass("tooltip");
                            jQuery(this).find('input.misc-hidden').next(".jquery-checkbox").data("title", title);
                        }
                        //$(this).find('.tooltip').tooltipster();
                        slide_id = jQuery(this).find(".all-layer-table").attr("slide-id");

                    });
                    slideTabs.find('ul').sortable({
                        stop: moveTabDiv
                    });                    
                }
                             
                fnCodeMirror();
            });
            jQuery(window).load(function() {
                var href=window.location.href;
                var query=href.split('?');
                var qs=window.GetQueryString(query[1]);
                if(qs['type']=='new'){
                    ChangeUrl('edit','admin.php?page=cloud-slider&action=edit&id='+jQuery('input[name=id]').val());
                }
                if (mainContainer.find(".cs_msg_right").length > 0) {
                    mainContainer.find(".cs_msg_right").slideDown(300);
                    setTimeout(function() {
                        mainContainer.find(".cs_msg_right").slideUp(300);
                    }, 5000);
                }
               
                /* Custom scroll in popups */
                mainContainer.find(".cloud_slider_settings_panel").show();
                mainContainer.find(".preview .preview_layer").not('.preview-carousel-container').each(function() {                    
                    layer_id = jQuery(this).attr("layerid");                    
                    slide_id = jQuery(this).parents(".preview").attr("slide-id");

                    if (slide_id != '' && layer_id != '') {
                        var tableRowLayer = mainContainer.find('tr#' + layer_id);
                        var rowContent = tableRowLayer.find(".content");
                        var layerContent = rowContent.find('.layer-daynamic-content');
                        dragLayer(rowContent, slide_id, layer_id);
                        arrangeCarouselLayers(slide_id);

                        title = tableRowLayer.find('input.other').data("title");
                        tableRowLayer.find('input.checkbox').checkbox({
                            empty: CS_ROOT_URL + "/images/empty.png"
                        });
                        if (title) {
                            tableRowLayer.find('input.other').next(".jquery-checkbox").addClass("tooltip").data("title", title);
                        }
                        wtitle = tableRowLayer.find('input.word-wrap').data("title");
                        if (wtitle) {
                            tableRowLayer.find('input.word-wrap').next(".jquery-checkbox").addClass("tooltip").data("title", wtitle);
                        }

                        textlen = layerContent.find(".textlength").val();
                        postid = layerContent.find(".cs-post-id").val();
                        sdata = setShortcodeData(postid, textlen, layerContent.find(".daynamic-content-text"));

                        if (rowContent.find("input.type").val() == "dynamic_text") {
                            layerContent.find(".daynamic-content-text").trigger("blur");
                        }
                        if (mainContainer.find('tr#' + layer_id + ' .layer-main').find(".highlight-layer").attr('highlight') == 1) {
                            var previewSlide = mainContainer.find(".preview[slide-id='" + slide_id + "']");
                            previewSlide.find(".preview_layer").children().css("opacity", "0.5");
                            previewSlide.find("img[layerid='abc']").css("opacity", "0.5");
                            previewSlide.find(".preview_layer[layerid='" + layer_id + "']").children().css("opacity", "1");
                        }
                        commonLayerList(slide_id);
                    }
                });
                if (slideTabs.find('ul li').length < 1) {
                    mainContainer.find('.add-new-slide').trigger('click');
                }
                changeSliderWidthHeight(function() {
                    loaderPopup.hide()
                });
                mainContainer.find('.slides-options .option-container').each(function() {
                    jQuery(this).css('max-height', jQuery(window).height() - 300);
                });

                mainContainer.find(".custom-styles").trigger("blur");                
            });
            jQuery(window).resize(function(){
                mainContainer.find('.slides-options .option-container').each(function() {
                    jQuery(this).css('max-height', jQuery(window).height() - 300);
                });           
            });
            //End of main each
        });
    }
}(jQuery));
jQuery.fn.extend({
    insertAtCaret: function(myValue) {
        return this.each(function(i) {
            if (document.selection) {
                //For browsers like Internet Explorer
                this.focus();
                var sel = document.selection.createRange();
                sel.text = myValue;
                this.focus();
            } else if (this.selectionStart || this.selectionStart == '0') {
                //For browsers like Firefox and Webkit based
                var startPos = this.selectionStart;
                var endPos = this.selectionEnd;
                var scrollTop = this.scrollTop;
                this.value = this.value.substring(0, startPos) + myValue + this.value.substring(endPos, this.value.length);
                this.focus();
                this.selectionStart = startPos + myValue.length;
                this.selectionEnd = startPos + myValue.length;
                this.scrollTop = scrollTop;
            } else {
                this.value += myValue;
                this.focus();
            }
        });
    }
});

jQuery(document).ready(function(){
    jQuery('.cloud_slider_panel').cloudSliderAdmin();    
})