﻿/// <reference path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.4-vsdoc.js" />
var url = window.location.pathname;
$('a[href$=' + url.substring(1, url.length) + '], a[href$=' + url + ']').addClass("current");

var section = url.split("/")[1];

if (section.toLowerCase() === "what-is-periowave.aspx" || section.toLowerCase() === "what-is-periowave") {
	$('#nav a[href$=what-is-periowave.aspx]').addClass("current");
} else if (section.toLowerCase() === "departments" || section.toLowerCase() === "products") {
	$('#nav a[href$=departments/lasers.aspx]').addClass("current");
} else if (section.toLowerCase() === "find-a-dental-professional.aspx" || section.toLowerCase() === "find-a-dentist-results.aspx" || section.toLowerCase() === "dentistsignup.aspx") {
	$('#nav a[href$=find-a-dental-professional.aspx]').addClass("current");
} else if (section.toLowerCase() === "periowave-in-your-clinic.aspx" || section.toLowerCase() === "periowave-in-your-clinic") {
	$('#nav a[href$=periowave-in-your-clinic.aspx]').addClass("current");
} else if (section.toLowerCase() === "testimonials.aspx" || section.toLowerCase() === "testimonials") {
	$('#nav a[href$=testimonials.aspx]').addClass("current");
} else if (section.toLowerCase() === "news.aspx" || section.toLowerCase() === "news") {
	$('#nav a[href$=news.aspx]').addClass("current");
} else if (section.toLowerCase() === "contactus.aspx") {
	$('#nav a[href$=ContactUs.aspx]').addClass("current");
} else {
	$('#nav a').removeClass("current");	
}


(function($) {

    $.fn.extend({

        //pass the options variable to the function
        tprotator: function(options) {


            //Set the default values, use comma to separate the settings, example:
            var defaults = {
                rotationSpeed: 10000,
                transitionSpeed: 1000,
                nav: "#rotator-nav",
                navitem: "#rotator-nav li",
                dynamicNav: false
            }

            var options = $.extend(defaults, options);
            var o = options;
            var obj = $(this);
            var rt;

            function rotateSlides(newslide) {
                $("#" + obj.attr("id") + " > div:not(" + o.nav + ")").fadeOut(o.transitionSpeed);
                $("#" + obj.attr("id") + " div.slide" + newslide).fadeIn(o.transitionSpeed);
                //$("#highlight").animate({ left: (newslide * 35) + "px" });
                $(o.navitem).removeClass("active");
                //console.log(newslide - 1);
                $(o.navitem + ":nth-child(" + (newslide + 1) + ")").addClass("active");

                currentslide = 0;
                slideid = newslide;
                if (newslide < slidecount - 1) {
                    currentslide = newslide + 1;
                }
                rt = setTimeout(function() { rotateSlides(currentslide) }, o.rotationSpeed);
            }

            function initializeNav() {
                //$("<div/>").attr("id", "highlight").appendTo(o.nav);
                $(o.nav).css("display", "block");
                $(o.navitem + ":first-child").addClass("active");
                $(o.navitem).click(function() {
                    clearTimeout(rt);
                    var id = $(this).index();
                    if (parseInt(slideid) !== parseInt(id)) {
                        rotateSlides(parseInt(id));
                    } else {
                        if (slideid < slidecount - 1) {
                            currentslide = slideid + 1;
                        }
                        rt = setTimeout(function() { rotateSlides(currentslide) }, o.rotationSpeed);
                    }
                });
            }

            function initialize() {
                var i = 0;
                var nav = null;
                if (o.dynamicNav) {
                    nav = $("<ul/>").attr("id", o.nav.replace("#", "")).css("display", "none").appendTo(obj);
                }
                obj.children().not(o.nav).each(function() {
                    $(this).addClass("slide" + i);
                    if (i > 0) {
                        $(this).css("display", "none");
                    }
                    $(this).css("position", "absolute");
                    if (o.dynamicNav) {
                        $("<li/>").text(i + 1).appendTo(nav);
                    }
                    i++;
                });
                slidecount = i;
                slideid = 0;
                if (slidecount > 1) {
                    initializeNav();
                    rt = setTimeout(function() { rotateSlides(1) }, o.rotationSpeed);
                }

            }

            initialize();

        }
    });

})(jQuery);

$("#banner").tprotator({
    dynamicNav: true
});

$(document).ready(function() {

	/* This is basic - uses default settings */
	if ($("a.single_image").length) {
		$("a.single_image").fancybox();
	}

});




