jQuery.noConflict();


var slideTimer = null;
var btnTimer   = null;

jQuery(document).ready(function () {

	var resizeTimer = null;
/*
	jQuery(window).bind('resize', function() {
	    if (resizeTimer) clearTimeout(resizeTimer);
	    resizeTimer = setTimeout(doSomething, 100);
	});
*/

	buildSlideShowNav();

	jQuery(".get-started img").hover(
		function() {
			this.src = this.src.replace("started","started-over");
		},
		function() {
			this.src = this.src.replace("started-over","started");
		}
	);

	slideTimer = setInterval("slideSwitch()", 4500);
	btnTimer   = setInterval("btnSwitch()", 4500);

	if(qs.length>0) {
		jQuery('.microLink').each(function(){
		var thisHref = jQuery(this).attr('href');
		
			if(thisHref.match(/\?(.+)$/)) { 
				jQuery(this).attr('href', thisHref + '&' + qs);
			} else {
				jQuery(this).attr('href', thisHref + '?' + qs);
			}
	   });
	}
	
}); // End jQuery(document).ready();

function slideSwitch(idx) {
	var active = jQuery('.slides .slide.act');
	var next   = "";
	
	if (idx){
		next = jQuery(".slides .slide:eq("+idx+")");	
	
	} else {
	    if ( active.length == 0 ) active = jQuery('.slides .slide:last');		
		next =  active.next().length ? active.next() : jQuery('.slides .slide:first');	

	}

    next.css({opacity: 0.0})
        .addClass('act')
        .animate({opacity: 1.0}, 1000, function() {
            active.removeClass('act');
        });
}

function btnSwitch(idx) {
	var active = jQuery('.slideshow-nav li.act-btn');
	var next   = "";

	if (idx){
		next = jQuery(".slideshow-nav li:eq("+idx+")");
	} else {
	    if ( active.length == 0 ) active = jQuery('.slideshow-nav li:last');
    	next =  active.next().length ? active.next() : jQuery('.slideshow-nav li:first');	
	}

    next.addClass('act-btn').animate({opacity: 1.0}, 0, 
    	function() {
           	active.removeClass('act-btn');
		}
	);
}

function resetTimer() {

	if (slideTimer) clearInterval(slideTimer);
	if (btnTimer) clearInterval(btnTimer);
	
	slideTimer = setInterval("slideSwitch()", 4500);
	btnTimer   = setInterval("btnSwitch()", 4500);
	
}

function buildSlideShowNav() {

	jQuery(".slides").each( function() {
	
		var elem = jQuery(this);
		var num_slides = elem.find(".slide").length;
		
		jQuery("#slideshow").append("<ul class=\"slideshow-nav\"></ul>");
		var slide_nav = jQuery(".slideshow-nav");
		
		for (var i=0;i<num_slides;i++) {
			slide_nav.append("<li><a href=\"#\">Slide "+i+"</a></li>");
		}
		
		slide_nav.find("li:first").addClass("act-btn");
		
		slide_nav.find("li a").click( function() {
			resetTimer();
			var item = jQuery(this).parent();
			var index = jQuery(".slideshow-nav li").index(item);
	
			slideSwitch(index);
			btnSwitch(index);
	
			return false;
		});
		
	});

}

// overlay function
function openOverlayWin(wchId,w,h) {
	jQuery('#'+wchId).colorbox({width:w+"px", height:h+"px", iframe:true});
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
return "";
}

//open chat
function openChatWindow(chatUrl) {
	window.open (chatUrl, "liveChatSess","menubar=0,resizable=0,toolbar=0,scrollbars=0,directories=0,status=0,width=640,height=480");
}
