$(document).ready(function () {
    
		switch(getUrlVarsFrom(window.location.href, false)['tabid']) {
		case '6':
			//toggleVisibility();
			
			break;
		case '1':
		
    		initSlideshow();
			break;
		case undefined:
		
    		initSlideshow();
			break;
		}
})

/* Search Functions */

function submitQuickSearch() {
    var keyWords = document.getElementById('inpQuickSearch').value;
    document.location.href = document.location.href.split('?')[0] + '?tabid=5&keyword=' + keyWords;
}

function submitCategory() {
    var url = document.getElementById('selCategory').value;
    document.location.href = document.location.href.substr(0, document.location.href.indexOf('DesktopDefault.aspx')) + url;
}

function entsub(e) {
    var evt = window.event ? e.keyCode : e.which;
    var keyPressed = evt;

    if (keyPressed == 13) {
        submitQuickSearch();
        return false;
    } else {
        return true;
    }
}

function handlePlaceHolderText() {
	if ($('input[type=text]').length >0) {
    $('input[type=text]').focus(function () {
        if ($(this).val() == $(this).attr('defaultValue')) {
            $(this).val('');

        }
    });

    $('input[type=text]').blur(function () {
        if ($(this).val() == '') {
            $(this).val($(this).attr('defaultValue'));

        }
    });
	
	
	}
	
}

function getUrlVarsFrom(url, preventUnwantedVars) {
    var vars = [],
        hash;
    var hashes = url.split('#')[0].slice(url.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
		if (preventUnwantedVars) {
			if (hash[0] != 'lg' && hash[0] != 'objectid' && hash[0] != 'tabindex' && hash[0] != 'page' && hash[0] != 'keyword'  && hash[0] != 'mediaid' && hash[0] != 'switchportal') {
        		vars.push(hash[0]);
        		vars[hash[0]] = hash[1];
			}
		} else {
			vars.push(hash[0]);
        	vars[hash[0]] = hash[1];
		}
    }
    return vars;
}


function toggleVisibility() {
	$('div.trigger').each(function (index, domEle) {

			
			$('div.trigger').click(function(){
					$(domEle).next().slideToggle();
					//$('div.trigger').toggle();
				});
        



    });
	
}

function initSlideshow() {
	
	$('.slideshow > a').css('opacity', 0);
	$('.slideshow > a.active').css('opacity', 1);
	setInterval( "slideSwitch()", 5000 );
	var w, h;
	$(window).width() < 1800 ? w = $(window).width() : w = 1800;
	$(window).height() < 1800 ? h = $(window).height() : h = 1800;
	
	w -= 74;
	h -= 74;
	
	$("a[rel='slideshow1']").each(function(index,domEle) {
		$(domEle).attr('href', $(domEle).attr('href').replace(/cell=[^&]*&/,'cell=' + w + ',' + h + '&'));
		
		$(domEle).children('img').css('margin-left', (330 - $(this).width()) / 2);
		$(domEle).children('img').css('margin-top', (221 - $(this).height()) / 2);
		
		$(domEle).children('img').load(function(){
		
			$(this).css('margin-left', (330 - $(this).width()) / 2);
			$(this).css('margin-top', (221 - $(this).height()) / 2);
			
		})
	})
	
	$("a[rel='slideshow1']").colorbox({slideshow:true, transition:"fade", speed : "3000", slideshowSpeed : "6000"});
	
	$('.slideshow div.button a').bind('click',function(){
		$('.slideshow > a.active').trigger('click')
		return false;
	});
	
}

function slideSwitch() {
    var $active = $('.slideshow > a.active');

    if ( $active.length == 0 ) $active = $('.slideshow > a:last');

    var $next =  $active.next().length ? $active.next()
        : $('.slideshow > a:first');

	$active.addClass('last-active')
	.animate({opacity: 0}, 1000, function() {
		$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
	});

   
}



