
var $j = jQuery.noConflict();

$j(document).ready(function(){

    /* Dots Slider 1 */
    $j(function(){
    	$j('#dotsSlider')
    	.after('<div id="dotsSliderNav">')
    	.cycle({
    		fx:	'blindX',
    		speed:	800,
    		timeout: 0, 
    		pager:	'#dotsSliderNav',
    		after:	onAfter
    	});
    
    	function onAfter() {
    		//get the height of the current slide
    		var $ht = $j(this).height();
    		//set the container's height to that of the current slide
    		$j(this).parent().animate({height: $ht});
    	}
    });
    /* End Dots Slider 1 */
    
    
    /* Rondabout Slider */
    $j(function(){
    	$j('#roundaboutSlider').roundabout({
    		minScale: 0.9,
    		minOpacity: 0.9,
    		easing: 'linear',
    		duration: 1200,
    		clickToFocus: false,
    		btnNext: '.nextSlide',
    		btnPrev: '.previousSlide'
    	});
    });
    /* End Rondabout Slider */
    
    /* Dots Slider 2 */
	$j(function(){
		$j('#dotsSlider2')
		.after('<div id="dotsSlider2Nav">')
		.cycle({
    		fx:	'blindX',
    		speed:	800,
    		timeout: 5000, 
			pager:	'#dotsSlider2Nav',
			height: '401px',
			prev:   '.prevDotsSlide',
			next:   '.nextDotsSlide'
		});
	});
	/* End Dots Slider 2 */
	
	/* Single Portfolio Slider */
	$j(function(){
		$j('#portfolioSlider')
		.after('<div id="portfolioSliderNav">')
		.cycle({
			fx:		'fade',
			speed:	400,
			timeout: 3000,
			pager:	'#portfolioSliderNav',
			height: '490px'
		});
	});
	/* End Single Portfolio Slider */
	
	/* Piecemaker 3D Slider */
	$j(function(){
		var flashvars = {};
		flashvars.xmlSource = "http://www.bme.be/wp-content/themes/bme-theme/piecemaker-xml.php";
		flashvars.cssSource = "http://www.bme.be/wp-content/themes/bme-theme/piecemaker/piecemaker.css";
		flashvars.imageSource = "http://";
		var attributes = {};
		attributes.wmode = "transparent";
		swfobject.embedSWF("http://www.bme.be/wp-content/themes/bme-theme/piecemaker/piecemaker.swf", "piecemakerSlider", "1200", "500", "10", "http://www.bme.be/wp-content/themes/bme-theme/piecemaker/expressInstall.swf", flashvars, attributes);
	});
	/* End Piecemaker 3D Slider */
	
	/* Tabs Slider */
	$j(function(){
		$j.slideshow = {
			context: false,
			tabs: false,
			timeout: 5000,
			slideSpeed: 450,
			tabSpeed: 450,
			fx: 'fade',
	
			init: function() {
				this.context = $j('#tabsSlider');
				this.tabs = $j('#tabsNav li', this.context);
				this.tabs.remove();
				this.prepareSlideshow();
				this.fillEmptyGap();
			},
	
			prepareSlideshow: function() {
				$j('#tabsSlides > ul', $j.slideshow.context).cycle({
					fx: $j.slideshow.fx,
					timeout: $j.slideshow.timeout,
					speed: $j.slideshow.slideSpeed,
					fastOnEvent: $j.slideshow.tabSpeed,
					pager: $j('#tabsNav', $j.slideshow.context),
					pagerAnchorBuilder: $j.slideshow.prepareTabs,
					before: $j.slideshow.activateTab,
					pauseOnPagerHover: true,
					pause: true
				});
			},
	
			prepareTabs: function(i, slide) {
				return $j.slideshow.tabs.eq(i);
			},

			fillEmptyGap: function() {
				// fill possibly empty gap in the end
				var tabsLiWidths = 0,
					tabsUl = $j('#tabsNav').outerWidth(true);
	
				$j('#tabsNav li').each(function() {
					tabsLiWidths += $j(this).outerWidth(true);
				});
	
				var fillWidth = tabsUl - tabsLiWidths;
	
				if (fillWidth >= 1) {
					$j('#tabsNav').append('<span class="fill">&nbsp;</span>');
					$j('#tabsNav span.fill').css('width',fillWidth);
				} else {
					$j('#tabsNav li:last-child').css('-moz-border-radius-bottomright','9px');
				}
			}
			
		};
		
		$j('body').addClass('js');
		
		$j.slideshow.init();
		
	});
	/* End Tabs Slider */
	
	/* Sidebar Widget Slider */
	$j(function(){
		$j("#subpage .sidebar h6.widget-title").click(function(){
			$j(this).toggleClass("active").next().slideToggle(400);
			return false;
		});
	});
	/* End Sidebar Widget Slider */

	/* clearField */
	$j(function(){
		$j('.clearField').clearField();
	});
	/* End clearField */
	
	/* Fancybox Images */
	$j(function(){
		$j("a.single_image").fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'titlePosition'	: 'over'
		});
		$j("a.multi_images").fancybox({
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic',
			'titlePosition'	: 'over'
		});
	});
	/* End Fancybox Images */

	/* Fancybox Iframe */
	jQuery(function(){
		$j("a.iframe").fancybox({
			'width'				: '75%',
			'height'			: '75%',
			'autoScale'     	: false,
			'transitionIn'		: 'fade',
			'transitionOut'		: 'fade',
			'type'				: 'iframe',
			'titleShow'		    : false
		});
	});
	/* End Fancybox Iframe */

	/* Fancybox Youtube Video */
	jQuery(function(){
		$j(".youtube_video").click(function() {
			$j.fancybox({
					'padding'		: 0,
					'autoScale'		: false,
					'transitionIn'	: 'fade',
					'transitionOut'	: 'fade',
					'title'			: this.title,
					'width'		    : 680,
					'height'		: 495,
					'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
					'type'			: 'swf',
					'swf'			: {
						'wmode'		: 'transparent',
						'allowfullscreen'	: 'true'
					}
				});

			return false;
		});
	});
	/* End Fancybox Youtube Video */
	
	/* Zoom Icon */
	$j(function(){
		$j(".zoom a").append("<span></span>");
		$j(".zoom a").hover(function(){
			$j(this).children("img").stop(true, true).animate({opacity:0.7},300);
			$j(this).children("span").stop(true, true).fadeIn(300);
		},function(){
			$j(this).children("img").stop(true, true).animate({opacity:1},250);
			$j(this).children("span").stop(true, true).fadeOut(250);
		});
		
		$j(".gallery .gallery-icon a").hover(function(){
			$j(this).children("img").stop(true, true).animate({opacity:0.6},300);
		},function(){
			$j(this).children("img").stop(true, true).animate({opacity:1},250);
		});
	});
	/* End Zoom Icon */
	
});
