﻿
// **************************************
// hide and show Service/Solution Tabs
// **************************************

function swapTab(n)
{
	//var wrapper = $('.MainContent')
	//var target1 = wrapper.find('.topImage')
	//var target2 = $('#mainOutput')
	
	//wrapper.find('.MainContent #subNav a').removeClass('subNavItemLinkHot')
	//$(btn).addClass('subNavItemLinkHot')

	$('.MainContent #subNav a').removeClass('subNavItemLinkHot');
	$('.MainContent #subNav a').addClass('subNavItemLink');

	$('.MainContent #subNav a').eq(n).removeClass('subNavItemLink');
	$('.MainContent #subNav a').eq(n).addClass('subNavItemLinkHot');


	$('.MainContent #mainOutput #contentTab li').hide();
	$('.MainContent #mainOutputService #contentTab li').hide();
	$('.MainContent .topImage li').hide();
	$('.MainContent .serviceTitle li').hide();

	$('.MainContent #mainOutput #contentTab li:nth-child(' + (n + 1) + ')').show();
	$('.MainContent #mainOutputService #contentTab li:nth-child(' + (n + 1) + ')').show();
	$('.MainContent .topImage li:nth-child(' + (n + 1) + ')').show();
	$('.MainContent .serviceTitle li:nth-child(' + (n + 1) + ')').show();

	$('.MainContent #mainOutput .checkMark li').show();
	$('.MainContent #mainOutputService .checkMark li').show();
	//var target
	//var target1Length = $(target1).find('ul').length
	//var target2Length = $(target2).find('ul').length
	/*
	if (target2Length) {
		
			$('#mainOutput ul li').hide()
			if ($('#subNav a').eq(x).hasClass('subNavItemLinkHot')) {
				$('#mainOutput ul').find('li').eq(x).show()
				
			}

		}
	}
	if (target1Length) {
		for (var x = 0; x < $('#subNav a').length; x++) {
			$('.topImage').find('ul li').eq(x).hide()
			if ($('#subNav a').eq(x).hasClass('subNavItemLinkHot')) {

				$('.topImage').find('ul li').eq(x).show()
			}

		}
	}*/
	//return false;
}

// ****************************
// slideshow / image rotators
// ****************************

var product_selectedIndex;

function product_swapNthChild(n) {
    
    $('.detail').fadeOut("slow", function() {

        $('.detail .divDetails').hide();
        $('.ProductPager ul li a').removeClass('selected');
        $('.ProductPager ul li:nth-child(' + n + ') a').addClass('selected');
        $('.detail .Slides .divDetails:nth-child(' + n + ')').show();
        $('.detail').fadeIn("slow");
        product_selectedIndex = n;

    });
}

function product_Rotate(timeout) {
    if (product_selectedIndex == null) {
        product_selectedIndex = 1;
    }
    var visibleItem = $('.detail .divDetails:nth-child(' + product_selectedIndex + ')');
    
    if ($(visibleItem).next().size() > 0) {
        product_selectedIndex = product_selectedIndex + 1;
    } else {
        product_selectedIndex = 1;
    }
    var nextItem = $('.detail .divDetails:nth-child(' + product_selectedIndex + ')');

    $('.detail').fadeOut("slow", function() {

        $('.detail .divDetails').hide();
        $('.ProductPager ul li a').removeClass('selected');
        $('.ProductPager ul li:nth-child(' + (product_selectedIndex) + ') a').addClass('selected');
        $('.detail .divDetails:nth-child(' + product_selectedIndex + ')').show();
        $('.detail').fadeIn("slow");
        setTimeout('product_Rotate(' + timeout + ');', timeout);
    });
}

var rotator_selectedIndex;

function rotator_swapNthChild(n) {
    var visibleItem = $('.ImageAutoRotator .RotateWrapper .RotatedItems .RotatedItem:visible');
    var nextItem = $('.ImageAutoRotator .RotateWrapper .RotatedItems .RotatedItem:nth-child(' + n + ')');
    $('.ImageAutoRotator .RotateWrapper').fadeOut("slow", function() {
        $('.RotatePager ul li a').removeClass('selected');
        $('.RotatePager ul li:nth-child(' + (n) + ') a').addClass('selected');
        $('.ImageAutoRotator .RotateWrapper .RotatedItems .RotatedItem').hide();
        $(nextItem).show();
        $('.ImageAutoRotator .RotateWrapper').fadeIn("slow");

        rotator_selectedIndex = n;
    });
    
}



function imageAutoRotator_Rotate(timeout) {
    if (rotator_selectedIndex == null) {
        rotator_selectedIndex = 1;
    }
    
    var visibleItem = $('.ImageAutoRotator .RotateWrapper .RotatedItems .RotatedItem:visible');
    var nextItem;
   
    if ($(visibleItem).next().size() > 0) {
        nextItem = $(visibleItem).next();
        rotator_selectedIndex = rotator_selectedIndex + 1;
    } else {
        nextItem = $('.ImageAutoRotator .RotateWrapper .RotatedItems .RotatedItem:first');
        rotator_selectedIndex = 1;
    }
    $('.ImageAutoRotator .RotateWrapper').fadeOut("slow", function() {

        // set pager (only if visible)
        $('.RotatePager ul li a').removeClass('selected');
        $('.RotatePager ul li:nth-child(' + (rotator_selectedIndex) + ') a').addClass('selected');
        //

        $('.ImageAutoRotator .RotateWrapper .RotatedItems .RotatedItem').hide();
        $(nextItem).show();
        $('.ImageAutoRotator .RotateWrapper').fadeIn("slow");
        setTimeout('imageAutoRotator_Rotate(' + timeout + ');', timeout);
    });

}

var overlayOpacity = 'alpha(opacity=60)';

// ****************************
// find a representative dialog
// ****************************
function findARepresentative(stateProvinceID) {

    WebService.FindRepresentatives(stateProvinceID, FindRepresentatives_Success, FindRepresentatives_Error);

}

function findARepresentativeByCountry(countryID) {
    WebService.FindRepresentativesByCountry(countryID, FindRepresentatives_Success, FindRepresentatives_Error);
}

function FindRepresentatives_Success(result) {

    $('.popup-contact-section').html(result);
    $('.overlay').fadeIn('fast', function() {
        $('.overlay').css('filter', overlayOpacity);
    });

    $('#popup-reps').fadeIn('fast');

}

function FindRepresentatives_Error() {
    // do nothing
}

function hidePopup() {
    $('.overlay').fadeOut();
    $('#popup-reps').fadeOut();
}


// ****************************
// contact us dialog
// ****************************

function showContactUsDialog() {
    $('.overlay').fadeIn('fast', function() {
        $('.overlay').css('filter', overlayOpacity);
    });

    $('#popup-email').fadeIn('fast');

}

function hideContactUsDialog() {
    $('.overlay').fadeOut();
    $('#popup-email').fadeOut();
    
}

function showFriendFormDialog() {
    $('.overlay').fadeIn('fast', function() {
        $('.overlay').css('filter', overlayOpacity);
    });
    
    $('#popup-friend').fadeIn('fast');
}

function hideFriendFormDialog() {
    $('.overlay').fadeOut();
    $('#popup-friend').fadeOut();
}


/* menus */

function initMenus() {
    $('.popMenu, .header-Menu').hover(function() {
        var node = $(this).children('a');
        var bottomNode = $(this).children('label').children('a');
        $(this).children('ul').show();
        $(node).css('display', 'inline');
        $(bottomNode).css('display', 'inline');
        $(this).children('ul.leftMenu').css('margin-left', $(node).outerWidth(true) + 'px');
        $(this).children('ul.bottomMenu').css('margin-left', $(bottomNode).outerWidth(true) + 'px');
        $(node).css('display', 'block');
        $(bottomNode).css('display', 'block');
    }, function() {
        $(this).children('ul').hide();
    });
   }

function expandandcollasp(element) {

   	var display = $(element).next('.careerSection').attr('style');
   	$('.careerSection').each(function() {
   		$(this).hide();
   	})

   	if (display == "display: block;") {
   		$(element).next('.careerSection').slideUp(1200).delay(300);
   		$(element).next('.careerSection').hide();
   	}
   	else {
   		$(element).next('.careerSection').slideUp(1200).delay(300).fadeIn(300);
   	}

   }
   function showdescription(element) {

   	var display = $(element).next('#careerDesc').attr('style');
   	$('#mainOutput').find('#careerDesc').each(function() {
   		$(this).hide();
   	})

   	if (display.trim().toLowerCase() == "display: block;") {
   		//$(element).next('#careerDesc').slideUp(1200).delay(300);
   		$(element).next('#careerDesc').hide();
   	}
   	else {   		
   		$(element).next('#careerDesc').attr("style", "display: block;");
   		//$(element).next('#careerDesc').slideUp(1200).delay(300).fadeIn(300);
   		$(element).next('#careerDesc').show();
   	}
}
