// JavaScript Document
// this is a fix for the jQuery slide effects
jQuery.noConflict();

function slideToggle(el, doShow) {
	var $el = el, originalHeight = $el.data("originalHeight"), visible = $el.is(":visible");

	// if the doShow isn't present, get the current visibility and reverse it
	if( arguments.length == 1 )
		doShow = !visible;
	
	// if the current visiblilty is the same as the requested state, cancel
	if( doShow == visible )
		return false;
	
	// get the original height - done at the first call
	if( !originalHeight ) {
		// get original height
		originalHeight = $el.show().height();
		// update the height
		$el.data("originalHeight", originalHeight);
		// if the element was hidden, hide it again

		if( !visible ) {
			$el.hide().css({height: 0});
		}
	}

	// expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
	if( doShow ){
		$el.stop().show().animate({height: originalHeight}, {duration: 600});
	} else {
		$el.stop().animate({height: 0},
					{duration: 600, complete:function () {$el.hide();}
		});
	}
}

jQuery.fn.wait = function(time, type) {
	time = time || 500;
	type = type || "fx";
	return this.queue(type, function() {
		var self = this;
		setTimeout(function() {
			$(self).dequeue();
		}, time);
	});
};

jQuery(document).ready(function($) {
	// Sliding on Services Page - Accordion
	// Slide Open
	$('a.slideTrigger').click(function() {
		(jQuery(this).text() == "Slide For More") ? jQuery(this).text("Close") : jQuery(this).text("Slide For More");
		$slideBox = jQuery(this).parents("div.slide").children('div.slide-more');
		slideToggle($slideBox);
		return false;
	});	
});

jQuery(function() {
//	jQuery(".tabshome ul").tabs(".tabscontent > div");

	jQuery(".tabsbanners").tabs("ul.main > li", {
		effect: 'fade',
		fadeInSpeed:500,
		rotate: true,
		tabs:"span"
	}).slideshow({autoplay:true, interval:5000, clickable:false});

//	jQuery(".tabscontact ul").tabs(".tabscontactcontent > div");
});

// For the services page
jQuery(document).ready(function($) {
	var myFile = document.location.toString();
	if (myFile.match('#')) { // the URL contains an anchor
		// click the navigation item corresponding to the anchor
		var number = myFile.split('#')[1] - 1;
		$('a.slideTrigger').eq(number).click();
	}
});


// Portfolio Page
jQuery(document).ready(function($) {
	// Scrollers
	$('#thumbs img').click(function() {
		thumbId = this.id;
		$(window).scrollTo('#' + thumbId.slice(6), 1000);
	});

	$('a.back-to-top').click(function() {
		$(window).scrollTo('#top-panel', 1000);
		return false;
	});

	// These functions can get some improvement
	var $clickedProject = $("div#points a.point").click(function() {
		$('div#points a.point').removeClass('active').eq($clickedProject.index(this)).addClass('active'); // Toggle points
		$('#WonSlider img').removeClass('active').eq($clickedProject.index(this)).addClass('active'); // Toggle news
		return false;
	});
	
	jQuery("div#points a.prev").click(function() {
		// Toggle points
		index = $("div#points a.point").index($("div#points a.active"));
		if(index == 0)
			return false;
		$("div#points a.point").removeClass('active').eq(index-1).addClass('active');
		$('#WonSlider img').removeClass('active').eq(index-1).addClass('active');
		return false;
	});
	jQuery("div#points a.next").click(function() {
		// Toggle points
		index = $("div#points a.point").index($("div#points a.active"));
		if(index == ($("div#points a.point").length-1))
			return false;
		$("div#points a.point").removeClass('active').eq(index+1).addClass('active');
		$('#WonSlider img').removeClass('active').eq(index+1).addClass('active');
		return false;
	});
});
