var vc_iframe = {
  scripts_to_wait: 0,
  time_to_call: false,
  ajax: false,
  activities_list: [],
  scripts_to_load: false,
  loaded_script: {},
  loaded_styles: {},
  inline_scripts: []
};
(function($) {
  vc_iframe.showNoContent = function(show) {
    (show === false && $('#vc-no-content-helper').addClass('vc-not-empty')) || $('#vc-no-content-helper').removeClass('vc-not-empty');
  };
  vc_iframe.scrollTo = function(id) {
    var $el, el_height, hidden = true, position_y, position,
        window_height = $(window).height(),
        window_scroll_top = $(window).scrollTop();
    if(id && ($el = $('[data-model-id=' + id +']'))) {
      position = $el.offset();
      if((position_y = position ? position.top : false) === false) return false;
      el_height = $el.height();
      if((position_y > window_scroll_top + window_height) ||
        (position_y + el_height < window_scroll_top)) {
        $.scrollTo($el, 500, {offset:-50});
      }
    }
  };
  vc_iframe.startSorting = function() {
    $('body').addClass('vc-sorting');
  };
  vc_iframe.stopSorting = function() {
    $('body').removeClass('vc-sorting')
  };
  vc_iframe.initDroppable = function() {
    $('body').addClass('vc-dragging');
    $('.vc-container').bind('mouseenter.vcDraggable', function(){
      $(this).addClass('vc-catcher');
    }).bind('mouseout.vcDraggable', function(){
      $(this).removeClass('vc-catcher');
    });
  };
  vc_iframe.killDroppable = function() {
    $('body').removeClass('vc-dragging');
    $('.vc-container').unbind('mouseover.vcDraggable mouseleave.vcDraggable');
  };
  vc_iframe.addActivity = function(callback) {
    this.activities_list.push(callback);
  };
  vc_iframe.renderPlaceholder = function(event, element) {
    var tag = $(element).data('tag'),
      $helper = $('<div class="vc-helper vc-helper-' + tag + '"><i class="vc-element-icon'
        + ( parent.vc.map[tag].icon ? ' ' + parent.vc.map[tag].icon : '' )
        + '"></i> ' + parent.vc.map[tag].name + '</div>').prependTo('body');
    return $helper;
  };
  vc_iframe.setSortable = function(app){
    $('[data-tag=vc_row]').parent().sortable({
      forcePlaceholderSize: false,
      items: '[data-tag=vc_row]',
      handle: '.vc-move-vc_row',
      cursor: 'move',
      cursorAt: {top: 20, left: 16},
      placeholder: "vc-placeholder-row",
      helper: this.renderPlaceholder,
      start: function(event, ui){
        vc_iframe.startSorting();
        ui.placeholder.height(30);
      },
      stop: this.stopSorting,
      tolerance: "pointer",
      update: function(event, ui) {
        parent.vc.app.saveRowOrder();
      }
    });
    $('.vc-element-container').sortable({
      forcePlaceholderSize: true,
      helper: this.renderPlaceholder,
      distance: 3,
      scroll: true,
      scrollSensitivity: 70,
      cursor: 'move',
      cursorAt: {top: 20, left: 16},
      connectWith:'.vc-element-container',
      items: '> [data-model-id]',
      handle: '.vc-element-move',
      start: this.startSorting,
      update: app.saveElementOrder,
      change: function(event, ui) {
        ui.placeholder.height(30);
        ui.placeholder.width(ui.placeholder.parent().width());
      },
      placeholder: 'vc-placeholder',
      tolerance: "pointer",
      over:function (event, ui) {
        var tag = ui.item.data('tag'),
            vc_map = window.parent.vc.map || false,
            parent_tag = ui.placeholder.closest('[data-tag]').data('tag'),
            allowed_container_element = vc_map[parent_tag].allowed_container_element ? vc_map[parent_tag].allowed_container_element : true;
        ui.placeholder.removeClass('hidden-placeholder');
        ui.placeholder.css({maxWidth:ui.placeholder.parent().width()});
        if(tag && vc_map) {
          if (!window.parent.vc.checkRelevance(parent_tag, tag)) {
            ui.placeholder.addClass('hidden-placeholder');
          }
          if(ui.sender) {
            var $sender_column = ui.sender.closest('.vc-element').removeClass('vc-sorting-over');
            $sender_column.find('.vc-element').length < 1 && $sender_column.addClass('vc-empty');
          }
          ui.placeholder.closest('.vc-element').addClass('vc-sorting-over');
          if (vc_map[tag].is_container && !(allowed_container_element === true || allowed_container_element === tag.replace(/_inner$/, ''))) {
            ui.placeholder.addClass('hidden-placeholder');
          }
        }
      },
      out: function() {
        // $(this).closest('.vc-element').removeClass('vc-sorting-over');
      },
      stop:function (event, ui) {
        var tag = ui.item.data('tag'),
            vc_map = window.parent.vc.map || false
            parent_tag = ui.item.parents('[data-tag]:first').data('tag'),
            allowed_container_element = vc_map[parent_tag].allowed_container_element ? vc_map[parent_tag].allowed_container_element : true;
        if (!window.parent.vc.checkRelevance(parent_tag, tag)) {
          ui.placeholder.removeClass('hidden-placeholder');
          $(this).sortable('cancel');
        }
        if (vc_map[tag].is_container && !(allowed_container_element === true || allowed_container_element === tag.replace(/_inner$/, ''))) { // && ui.item.hasClass('wpb_container_block')
          ui.placeholder.removeClass('hidden-placeholder');
          $(this).sortable('cancel');
        }
        vc_iframe.stopSorting();
      }
    });
	
    $('.wpb_row').sortable({
      forcePlaceholderSize: true,
      tolerance: "pointer",
      items: '> [data-tag=vc_column], > [data-tag=vc_column_inner]',
      handle: '> .vc-controls .vc-move-vc_column',
      start: function(event, ui) {
        vc_iframe.startSorting();
        var id = ui.item.data('modelId'),
            model = parent.vc.shortcodes.get(id),
            css_class = model.view.convertSize(model.getParam('width'));
        // ui.item.removeClass(css_class).data('removedClass', css_class);
        ui.item.appendTo(ui.item.parent().parent());
        ui.placeholder.addClass(css_class);
        ui.placeholder.width(ui.placeholder.width()-4);
      },
      cursor: 'move',
      cursorAt: {top: 20, left: 16},
      stop: function(event, ui){
        // ui.item.addClass(ui.item.data('removedClass'));
        vc_iframe.stopSorting(event, ui);
      },
      update: app.saveColumnOrder,
      placeholder: 'vc-placeholder-column',
      helper: this.renderPlaceholder
    });
  /*
    $('.vc_element_button', parent.document).draggable({
      // connectToSortable: '.vc-element-container',
      helper: 'clone',
      revert: true,
      cursor:"move"
    });
    */
    /*
    $('.vc_row_button', parent.document).draggable({
      connectToSortable: $('.entry-content'),
      helper: 'clone',
      revert: 'invalid',
      iframeFix: true
      // appendTo: "body"
    });
 /* .mouseup(function(){
        $(this).draggable( "disable" );
        $('.wpb_column > .wpb_wrapper').sortable('disable');
        $('.vc-placeholder', parent.document).remove();
        // $('.vc-placeholder').remove();
        $(this).draggable( "enable" );
      });
      */
    $('[data-tag=vc_row]').disableSelection();
    app.setFrameSize();
    $('#vc-load-new-js-block').appendTo('body');
  };
  vc_iframe.loadCustomCss = function(css) {
    if(!vc_iframe.$custom_style) {
      $('[data-type=vc-custom-css]').remove();
      vc_iframe.$custom_style = $('<style class="vc_post_custom_css_style"></style>').appendTo('body');
    }
    vc_iframe.$custom_style.html(css)
  };
  vc_iframe.setCustomShortcodeCss = function(css) {
    this.$shortcodes_custom_css = $('[data-type=vc-shortcodes-custom-css]');
    if(!this.$shortcodes_custom_css.length) {
      this.$shortcodes_custom_css = $('<style data-type="vc-shortcodes-custom-css"></style>').prependTo('body');
    }
    this.$shortcodes_custom_css.append(css);
  };
  vc_iframe.addInlineScript = function(script) {
    return this.inline_scripts.push(script)-1;
  };
  vc_iframe.loadInlineScripts = function() {
    var script,i = 0;
    while(this.inline_scripts[i]) {
      $(this.inline_scripts[i]).insertAfter('.js_placeholder_' + i);
      $('.js_placeholder_' + i).remove();
      i++;
    }
    this.inline_scripts = [];
  };
  vc_iframe.allowedLoadScript = function(src) {
    var script_url, i, scripts_string, scripts = [], scripts_to_add = [], ls_rc;
    if(src.match(/load\-scripts\.php/)) {
      scripts_string = src.match(/load%5B%5D=([^&]+)/)[1];
      if(scripts_string) scripts = scripts_string.split(',');
      for(i in scripts) {
        ls_rc = 'load-script:' + scripts[i];
        if(!vc_iframe.loaded_script[window.md5(ls_rc)]) {
          vc_iframe.loaded_script[window.md5(ls_rc)] = ls_rc;
          scripts_to_add.push(scripts[i]);
        }
      }
      return !scripts_to_add.length ? false : src.replace(/load%5B%5D=[^&]+/, 'load%5B%5D=' + scripts_to_add.join(','));
    } else if(!vc_iframe.loaded_script[window.md5(src)]) {
      vc_iframe.loaded_script[window.md5(src)] = src;
      return src;
    }
    return false;
  };

  vc_iframe.collectScriptsData = function() {
    $('script[src]').each(function(){
      vc_iframe.allowedLoadScript($(this).attr('src'));
    });
    $('link[href]').each(function(){
      var href = $(this).attr('href');
      vc_iframe.loaded_styles[window.md5(href)] = href;
    });
  };
  $('body').removeClass('admin-bar');
  $(document).ready(function(){
    $('#wpadminbar').hide();
    $('.edit-link').hide();
    window.parent.vc && !window.parent.vc.loaded && window.parent.vc.build && window.parent.vc.build();
  });
  
  vc_iframe.reload = function() {
	
    vc_iframe.reload_safety_call = false;
    $('a:not(.control-btn)').attr("target","_blank");
    window.vc_twitterBehaviour();
    window.vc_teaserGrid();
    window.vc_carouselBehaviour();
    window.vc_prettyPhoto();
    window.vc_googleplus();
    window.vc_pinterest();
    window.vc_progress_bar();
	window.vc_parallax();
	window.vc_ytp();
	window.vc_gmaps_back()
    window.vc_waypoints();
    for(var i in this.activities_list) {
      this.activities_list[i].call(window);
    }
    this.activities_list = [];
    this.collectScriptsData();
    this.loadInlineScripts();
    return true;
  };
  vc_iframe.addScripts = function($elements) {
    vc_iframe.scripts_to_wait = $elements.length;
    vc_iframe.scripts_to_load = $elements;
  };
  vc_iframe.loadScripts = function() {
    if(!vc_iframe.scripts_to_wait || !vc_iframe.scripts_to_load) {
      vc_iframe.reload();
      return;
    }
    vc_iframe.scripts_to_load.each(function(){
      var $element = $(this);
      vc_iframe.reload_safety_call = true;
      if($element.is('script')) {
        var src = $element.attr('src');
        src = vc_iframe.allowedLoadScript(src);
        if(src) {
          $.getScript(src, function() {
            vc_iframe.scripts_to_wait -=1;
            vc_iframe.scripts_to_wait < 1 && vc_iframe.reload()
          });
        } else {
          vc_iframe.scripts_to_wait -=1;
          vc_iframe.scripts_to_wait < 1 && vc_iframe.reload()
        }
      } else {
        var href = $element.attr('href');
        if(!vc_iframe.loaded_styles[window.md5(href)]) {
          $('<link/>', {
            rel: 'stylesheet',
            type: 'text/css',
            href: href
          }).appendTo('body');
        }
        vc_iframe.scripts_to_wait -=1;
        vc_iframe.scripts_to_wait < 1 && vc_iframe.reload();
      }
    });
    vc_iframe.scripts_to_load = false;
    $( document ).ajaxComplete(function(e) {
      $(e.currentTarget).unbind('ajaxComplete');
      !vc_iframe.scripts_to_wait && vc_iframe.reload();
    });
    window.setTimeout(function(){
      vc_iframe.reload_safety_call === true && vc_iframe.reload();
    }, 14000);
  };
  vc_iframe.destroyTabs = function($tabs) {
    $tabs.each(function(){
      var $t = $(this).find('.wpb_tour_tabs_wrapper');
      $t.tabs('destroy');
    });
  };
  vc_iframe.buildTabs = function($tab, active) {
    var ver = $.ui.version.split('.'),
       old_version = parseInt(ver[0])==1 &&  parseInt(ver[1]) < 9;
    // if($call.hasClass('ui-widget')) $call.tabs('destroy');
    $tab.each(function(index) {
    var $tabs,
      interval = $(this).attr("data-interval"),
      tabs_array = [],
      $wrapper = $(this).find('.wpb_tour_tabs_wrapper');
    if($wrapper.hasClass('ui-widget')) {
      active = active!==false ? active : $wrapper.tabs('option', 'active');
      $tabs = $wrapper.tabs('refresh');
      $wrapper.tabs('option', 'active', active);
    } else {
      $tabs = $(this).find('.wpb_tour_tabs_wrapper').tabs({
        active: 0,
        show: function(event, ui) {wpb_prepare_tab_content(event, ui);},
        activate: function(event, ui) {wpb_prepare_tab_content(event, ui);}
      }); // .tabs('rotate', interval*1000);
    }
    $(this).find('.vc-element').each(function(){ tabs_array.push(this.id); });
    $(this).find('.wpb_prev_slide a, .wpb_next_slide a').unbind('click').click(function(e) {
      e.preventDefault();
      if(old_version) {
        var index = $tabs.tabs('option', 'selected');
        if ( $(this).parent().hasClass('wpb_next_slide') ) { index++; }
        else { index--; }
        if ( index < 0 ) { index = $tabs.tabs("length") - 1; }
        else if ( index >= $tabs.tabs("length") ) { index = 0; }
        $tabs.tabs("select", index);
      } else {
        var index = $tabs.tabs( "option", "active"),
          length = $tabs.find('.wpb_tab').length;

        if ( $(this).parent().hasClass('wpb_next_slide') ) {
          index = (index+1) >=length ? 0 : index+1;
        } else {
          index = index-1 < 0 ? length -1 : index-1;
        }
        $tabs.tabs( "option", "active", index );
      }
    });

    });
    return true;
  };
  vc_iframe.setActiveTab = function($tabs, index) {
    $tabs.each(function(){
      $(this).find('.wpb_tour_tabs_wrapper').tabs('refresh');
      $(this).find('.wpb_tour_tabs_wrapper').tabs('option', 'active', index);
    });
  };
  vc_iframe.setTabsSorting = function(view) {
    var $controls = $(view.tabsControls().get(0));
    if($controls.hasClass('ui-sortable')) {
      $controls.sortable('destroy');
    }
    $controls.sortable({
      axis:(view.model.get('shortcode') === 'vc_tour' ? 'y' : 'x'),
      update: view.stopSorting,
      items:"> li:not(.add_tab_block)"
    });
  };
  vc_iframe.buildAccordion = function($el, active) {
    $el.each(function(index) {
      var $this = $(this),
        $tabs,
        $wrapper = $this.find('.wpb_accordion_wrapper'),
        interval = $this.attr("data-interval"),
        active_tab = !isNaN($this.data('active-tab')) && parseInt($this.data('active-tab')) >  0 ? parseInt($this.data('active-tab'))-1 : false,
        collapsible =  active_tab === false || $this.data('collapsible') === 'yes';
      //
      if($wrapper.hasClass('ui-widget')) {
       if(active===false) active = $wrapper.accordion("option", 'active');
        $wrapper.accordion("refresh");
        $wrapper.accordion('option', 'active', active);
      } else {
        $tabs = $this.find('.wpb_accordion_wrapper').accordion({
          header: "> .vc-element .acctitle",
          autoHeight: false,
          heightStyle: "content",
          active: active_tab,
          collapsible: collapsible,
          navigation: true,
          change: function(event, ui){
            if($.fn.isotope!=undefined) {
              ui.newContent.find('.isotope').isotope("reLayout");
            }
            window.vc_carouselBehaviour();
          }
        });
      }
      //.tabs().tabs('rotate', interval*1000, true);
    });
  };
  vc_iframe.setAccordionSorting = function(view) {
    $(view.$accordion.find('> .wpb_accordion_wrapper').get(0)).sortable({
      handle: '.vc-move-vc_accordion_tab',
      update: view.stopSorting
    });
  };
  vc_iframe.vc_imageCarousel = function(model_id) {
    var $el = $('[data-model-id=' + model_id + ']'),
        images_count = $el.find('img').length,
        $carousel = $el.find('[data-ride="vc-carousel"]');
    if(!$carousel.find('img:first').length) {
      $carousel.carousel($carousel.data());
      return;
    }
    if(!$carousel.find('img:first').prop('complete')) {
      window.setTimeout(function(){
        vc_iframe.vc_imageCarousel(model_id);
      }, 500);
      return;
    }
    $carousel.carousel($carousel.data());
  };
  vc_iframe.vc_gallery = function(model_id) {
    var $el = $('[data-model-id=' + model_id +']'),
      $gallery = $el.find('.wpb_gallery_slides');
    if(!$gallery.find('img:first').prop('complete')) {
      window.setTimeout(function(){
        vc_iframe.vc_gallery(model_id);
      }, 500);
      return;
    }
	 
    this.gallerySlider($gallery);
  };
  vc_iframe.vc_postsSlider = function(model_id) {
    var $el = $('[data-model-id=' + model_id +']'),
      $gallery = $el.find('.wpb_gallery_slides');
    this.gallerySlider($gallery);
  };
  
  vc_iframe.gallerySlider = function($gallery) {
    if($gallery.hasClass('wpb_flexslider')) {
      var sliderSpeed = 800,
        sliderTimeout = $gallery.find(".fslider").attr("data-pause"),
        sliderFx = $gallery.find(".fslider").attr("data-animate"),
        slideshow = $gallery.find(".fslider").attr("data-slideshow");
      if ( sliderTimeout == 0 ) slideshow = false;
      $('.fslider .flexslider').flexslider({
		selector: ".slider-wrap > .slide",  
        animation: sliderFx,
        slideshow: slideshow,
        slideshowSpeed: sliderTimeout,
        sliderSpeed: sliderSpeed,
		prevText: "<i class=\"fa-angle-left\"></i>",
		nextText: "<i class=\"fa-angle-right\"></i>",
        smoothHeight: true
      });
      $gallery.addClass('loaded');
    } 
	if ( $gallery.hasClass('wpb_image_grid') ) {
      var isotope = $gallery.find('.wpb_image_grid_ul');
      isotope.isotope({
        // options
        itemSelector : '.isotope-item',
        layoutMode : 'fitRows'
      });
      isotope.isotope("reLayout");
    }
  };
  	vc_iframe.vc_row = function(model_id) {
		var $el = $('[data-model-id=' + model_id +']');
		var $ytp = $el.find('.video_bg');
		$ytp.find('.player').mb_YTPlayer();
	};

	vc_iframe.testimonials = function(model_id) {
		var $el = $('[data-model-id=' + model_id +']');
		var $testimonials = $el.find('.testimonial-scroller');
		$testimonials.find('.testimonials').carouFredSel({
			responsive : true,
			auto : false,
            items : 1,
			width: "100%",
            scroll : {
            	items : "page",
                fx : "slide",
                duration : 300,
                wipe : true
			},					

            prev: $testimonials.find('.widget-scroll-prev'),
			next: $testimonials.find('.widget-scroll-next'),
					
			onCreate : function () {
				$(window).on('resize', function(){
					$(this).parent().add($(this)).css('height', $(this).children().first().outerHeight() + 'px');
				}).trigger('resize');
			}
		});
	};
	/*
	vc_iframe.vc_gmaps = function(model_id) {
		var $el = $('[data-model-id=' + model_id +']');
		var $gmaps = $el.find('.googlemaps');
		
		var id = $gmaps.attr('data-id');
		
		var addressEl = $gmaps.attr('data-address');
		
		var lat = $gmaps.attr('data-lat');
		var lng = $gmaps.attr('data-lng');
		
        var map_design = $gmaps.attr('data-maptype');
        var zoomEl = $gmaps.attr('data-zoom');
		
		var titleEl = $gmaps.attr('data-title');
		
		var popupEl = ( $gmaps.attr('data-popup') === "true" );
		var scrollwheelEl = ( $gmaps.attr('data-scrollwheel') === "true" );
		var panEl = ( $gmaps.attr('data-pan') === "true" );
		var zoom_controlEl = ( $gmaps.attr('data-zoom_control') === "true" );
		var type_controlEl = ( $gmaps.attr('data-type_control') === "true" );
		var streetviewEl = ( $gmaps.attr('data-streetview') === "true" );
		 
		if(titleEl) { 
			titleEl = '<h3>'+titleEl+'</h3>';
		}
		var messageEl = $gmaps.attr('data-message');
		if( messageEl ) {
			messageEl = '<p>'+messageEl+'</p>';
		}
		var phoneEl = $gmaps.attr('data-phone');
		if( phoneEl ) {
			phoneEl = '<p class="nobottommargin"><icon class="fa-phone"></icon>&nbsp;&nbsp;'+phoneEl+'</p>';
		}
		var emailEl = $gmaps.attr('data-email');
		if( emailEl ) {
			emailEl = '<p><icon class="fa-envelope"></icon>&nbsp;&nbsp;'+emailEl+'</p>';
		}
		
		function initialize() {
				  	var myLatlng = new google.maps.LatLng(lat,lng);
				  
				  	var mapOptions = {
						zoom: 8,
						center: myLatlng,	
						mapTypeId: google.maps.MapTypeId[map_design],				
						scrollwheel: scrollwheelEl,				
						panControl: panEl,
						zoomControl: zoom_controlEl,
						mapTypeControl: type_controlEl,
						overviewMapControl: false,
						streetViewControl: streetviewEl,
				  	}
				  	var map = new google.maps.Map(document.getElementById(id), mapOptions);				
				
				  	//map.setMapTypeId(google.maps.MapTypeId[map_design]);	
				  
				  	var contentString = '<div>'+titleEl+messageEl+'<p class="nobottommargin"><icon class="fa-home"></icon>&nbsp;&nbsp;'+addressEl+'</p>'+phoneEl+emailEl+'</div>';
				
				  	var infowindow = new google.maps.InfoWindow({
					  content: contentString,
					  maxWidth: 300,
					  
				  });			  
				  
				  var marker = new google.maps.Marker({
					  position: myLatlng,
					  map: map,
					  title: titleEl
				  });		  
				  
				  
				  google.maps.event.addListener(marker, 'click', function() {
					infowindow.open(map,marker);
				  });
				  if( popupEl ) {
					google.maps.event.addListenerOnce(map, 'idle', function() {
					  setTimeout(function() {
						// wait some more (...)
						google.maps.event.trigger(marker, 'click'); //still doesn't work
					  },200);
					});
				  }
				}
				
				google.maps.event.addDomListener(window, 'load', initialize);
	};
	*/
	
	vc_iframe.faqs = function(model_id) {
		var $el = $('[data-model-id=' + model_id +']');
		var $faqs = $el.find('.faqs_wrap');
		
		$(".togglec").hide();
		$(".togglec.open").show();
		
		$el.find(".togglet").unbind('click').click(function(e) {
		  var $this = $(this);
		  
		  if ( $this.hasClass('toggleta') ) {
			$this.removeClass('toggleta').next().slideUp(500);
		  } else {
			$this.addClass('toggleta').next().slideDown(500);
		  }
		});	
		
		var faqName = $faqs.attr('data-name');	
		
		var $faqItems = $('#faqs .toggle'); 

				
			$('#faq-filter a').click(function(){
							
				$('#faq-filter li').removeClass('activeFilter');
							
				$(this).parent('li').addClass('activeFilter');
							
				var faqSelector = $(this).attr('data-filter');					
							
				$faqItems.css('display', 'none');
							
				if( faqSelector != ('all') ) {
								
					$( faqSelector ).fadeIn(500);
								
				} else {
								
					$faqItems.fadeIn(500);
				}
							
				return false;
							
			}); 


	};
  
	vc_iframe.clients = function(model_id) {
		var $el = $('[data-model-id=' + model_id +']');
		var $clients = $el.find('.clients_wrapper');
		
		$clients.find('#clients-scroller').carouFredSel({
			width : "100%",
			height : "auto",
			circular : false,
			responsive : true,
			infinite : false,
			auto : false,
			items : {
				width : 160,
				visible: {
					min: 1,
					max: 6
				}
			},
			scroll : {
            	items : "page",
                fx : "slide",
                duration : 300,
                wipe : true
                },
					
			prev: $clients.find('.widget-scroll-prev'),
			next: $clients.find('.widget-scroll-next'),
					
			onCreate : function () {
				$(window).on('resize', function(){
					$(this).parent().add($(this)).css('height', $(this).children().first().outerHeight() + 'px');
				}).trigger('resize');
			}			
		});
  };
  
  vc_iframe.recent_works = function(model_id) {
	  
    var $el = $('[data-model-id=' + model_id +']'), $sit = $el.find('.col_full'); 
	
	$('.portfolio-image').hover(function(){
			$(this).find('.portfolio-overlay').filter(':not(:animated)').animate({opacity: 'show'}, 400);
		}, function () {
			$(this).find('.portfolio-overlay').animate({opacity: 'hide'}, 200);
	});
	
	$('.portfolio-overlay').each( function() { $(this).hoverdir({
				hoverDelay : 0
	}); } );
	
	if($sit.hasClass('carousel')) {

			var $portfolio = $el.find('.portfolio-wrapper');

			$portfolio.find('#portfolio-shortcode').carouFredSel({
				width : "100%",
				height : "auto",
				circular : false,
				responsive : true,
				infinite : true,
				auto: false,
				items : {
						width : 280,
						visible: {
							min: 1,
							max: 4
						}
					},
				scroll : {						
                        fx : "slide",
                        duration : 300,
						pauseOnHover: 3000,
                        wipe : true
					},	
				prev: $portfolio.find('.widget-scroll-prev'),
				next: $portfolio.find('.widget-scroll-next'),
				
				onCreate : function () {
						$(window).on('resize', function(){
							$(this).parent().add($(this)).css('height', $(this).children().first().outerHeight() + 'px');
						}).trigger('resize');
					}	
			});
	}
	if($sit.hasClass('normal')){
			var $container = $('#portfolio');
			$container.isotope();
                            
            $('#portfolio-filter a').click(function(){
                                
            	$('#portfolio-filter li').removeClass('activeFilter');
            	$(this).parent('li').addClass('activeFilter');
            	var selector = $(this).attr('data-filter');
            	$container.isotope({ filter: selector });
            	return false;
                                
            });
                            
                $(window).resize(function() {
                	$container.isotope('reLayout');
				});
	}
  };
  
  vc_iframe.vc_Flickr = function($placeholder) {
    var link = $placeholder.data('link');
    
    $.getScript(link, function() {
      $(window.b_txt).insertAfter($placeholder);
    });
  };
  vc_iframe.vc_toggle = function(model_id) {
	  
    var $el = $('[data-model-id=' + model_id +']');
	$(".togglec").hide();
	$(".togglec.open").show();
    
    $el.find(".togglet").unbind('click').click(function(e) {
      var $this = $(this);
      
      if ( $this.hasClass('toggleta') ) {
        $this.removeClass('toggleta').next().slideUp(500);
      } else {
        $this.addClass('toggleta').next().slideDown(500);
      }
    });   
  };
  // vc_iframe.setSortable(window.parent.vc.app);
})(window.jQuery);