// JavaScript Document

	function getUrlVars(str) {
		var vars = new Array();
		var hashes = str.slice(str.indexOf('?') + 1).split('&');
	 	
		for (var i = 0; i < hashes.length; i++) {
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		
		return vars;
	}


$(document).ready(function() {
	
	$("a.zoom1").fancybox({
		'overlayOpacity'	:	.75,
		'overlayColor'		:	'#000',
		'type'				: 'iframe'
	});
	
	$(".inline").fancybox({
			'overlayOpacity'	: .75,
			'overlayColor'		: '#000',
			'padding'			: 0
	});
	
	$(".iframe").click(function () {
		var vars = getUrlVars($(this).attr('href'));
		var url = $(this).attr('href');
		var dWidth = Number(vars['w']);
		var dHeight = Number(vars['h']);
		$.fancybox({
			'href'				: url,
			'width'				: dWidth,
			'height'			: dHeight,
			'type'				: 'iframe',
			'overlayOpacity'	:	.75,
			'overlayColor'		:	'#000'
		});
		return false;
	});
	
	// hide and show products menu
	$('#products_menu').bind('mouseover', function () { 
		$('.btn_blue').css('background-image','url(\'http://www.easysoft-usa.com/img/page_parts/btn_blue_over.gif\')');
		var offset = $('.btn_blue').offset();
		$('.products_menu').show();
		$('.products_menu').css('left', offset.left);
		$('.products_menu').css('top', offset.top + 30);
	});
	$('.products_menu').bind('mouseleave', function () { 
		$('.btn_blue').css('background-image','url(\'http://www.easysoft-usa.com/img/page_parts/btn_blue.gif\')');
		$('.products_menu').hide(); 
	});
	
	// hide and show buy drop menu
	$('.btn_grey_drop').bind('mouseover', function () {
		var offset = $('.btn_grey_drop').offset();
		$('.choose').show();
		$('.choose').css('left', offset.left);
		$('.choose').css('top', offset.top);
	});
	$('.choose').bind('mouseleave', function () {
		$('.choose').hide(); 
	});
	
	$('.btn_grey_small_2').bind('mouseover', function () {
		var offset = $('.btn_grey_small_2').offset();
		$('.choose_2').show();
		$('.choose_2').css('left', offset.left);
		$('.choose_2').css('top', offset.top - 45);
	});
	$('.choose_2').bind('mouseleave', function () {
		$('.choose_2').hide(); 
	});
	
	// show cloud bar
	/*$('.cld_trigger').click(function () {
		$('.cld_bar').animate({ height: '620px'}, "slow");
		$('.cld_close').css('display','block');
	});
	
	$('.cld_close').click(function () {
		$('.cld_bar').animate({ height: '30px'}, "slow");	
		$('.cld_close').css('display','none');
	});*/
	
	var nav = new Array();
	var div = new Array();
	
	function assignTabs () {
		$('.tabtab ul').children().each( function (index) {			
			// add to nav array
			nav[index] = $(this);
			
			// assign click
			$(this).click(function () {
				pg = index;
				tabhilite(pg);
			});
			
		});
		
		$('#tabs').children().each( function (index) {
			div[index] = $(this);									  
		});
		
		// initialize
		tabhilite(0);
	}
	
	function tabhilite (pg) {
		$('.tabtab').css('display','block');
		for (i = 0;i < nav.length;i++) {
			if (i == pg) {
				$(nav[pg]).addClass("on");
				$(nav[pg]).css('color', '#fff');
				$(nav[pg]).css('font-weight', 'bold');
				$(nav[pg]).css('text-decoration', 'none');
				$(div[pg]).show();
			} else {
				$(nav[i]).removeClass("on");
				$(nav[i]).css('color', '#000');
				$(nav[i]).css('font-weight', 'normal');
				$(nav[i]).css('text-decoration', 'underline');
				$(div[i]).hide();
			}
		}
	}
	
	assignTabs();
	
	if ($('#slider').length != 0) {
		$('#slider').nivoSlider({
			effect:'slideInLeft', // Specify sets like: 'fold,fade,sliceDown'
			slices:15, // For slice animations
			boxCols: 12, // For box animations
			boxRows: 4, // For box animations
			animSpeed:500, // Slide transition speed
			pauseTime:7000, // How long each slide will show
			startSlide:0, // Set starting Slide (0 index)
			directionNav:false, // Next & Prev navigation
			directionNavHide:true, // Only show on hover
			controlNav:true, // 1,2,3... navigation
			controlNavThumbs:false, // Use thumbnails for Control Nav
			controlNavThumbsFromRel:false, // Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', // Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
			keyboardNav:true, // Use left & right arrows
			pauseOnHover:true, // Stop animation while hovering
			manualAdvance:false, // Force manual transitions
			captionOpacity:1, // Universal caption opacity
			prevText: 'Prev', // Prev directionNav text
			nextText: 'Next', // Next directionNav text
			beforeChange: function(){}, // Triggers before a slide transition
			afterChange: function(){}, // Triggers after a slide transition
			slideshowEnd: function(){}, // Triggers after all slides have been shown
			lastSlide: function(){}, // Triggers when last slide is shown
			afterLoad: function(){} // Triggers when slider has loaded
		});
	}
	
});
