var amount = false;
var dateNow = new Date();
var currentHour = dateNow.getHours();

$(function(){
	
	$("#demo-bar").jixedbar();
	
	setTimeout("processCountDownClock()", 1000);
	
	$('#contactUsBtn').click (function () {
		var barleft = parseInt ($('#demo-bar').css('margin-left'));
		var left = $(this).position ().left;
		var newLeft = (barleft + left - 178);
		
		$('.jx-nav-menu').hide ();
		$('#jx-ttip-con-id').html ('');
		$('#ratingContentBox').hide ();
		$('#commentsContentBox').hide ();
		$('#reinstallContentBox').hide ();
		
		$('.unit-rating').css('margin', '0 auto');
		$('#contactusContentBox').css('margin-left', newLeft+'px');
		$('#contactusContentBox').toggle (0);
	});
	
	$('#contactSendBtn').click (function () {
		$('#contactUsFormContent').slideUp (300, function () {
			$('#contactUsThankYou').slideDown (300);
			$.post ('/demo/include/js/contactus.php', {
				name : $('#contactName').val (),
				email : $('#contactEmail').val (),
				comment : $('#contactComment').val ()}, function () {
					setTimeout ("$('#contactusContentBox').hide ();$('#contactUsThankYou').slideUp (300);$('#contactUsFormContent').show ();", 5000);
				});
		});
	});
	
	$('#reinstallBtn').click (function () {
		var barleft = parseInt ($('#demo-bar').css('margin-left'));
		var left = $(this).position ().left;
		var newLeft = (barleft + left - 175);
		
		$('.jx-nav-menu').hide ();
		$('#jx-ttip-con-id').html ('');
		$('#commentsContentBox').hide ();
		$('#ratingContentBox').hide ();
		$('#contactusContentBox').hide ();
		$('#reinstallContentBox').css('margin-left', newLeft+'px');
		$('#reinstallContentBox').toggle (0);
	});
	
	$('#demo-bar ul li a').click (function () {
		$('.customBarPopup').hide ();
	});
	
	
	$('#reinstallRequestBtn').click (function () {
		$.post ('/demo/include/js/reinstallrequest.php', {scriptid: scriptid, email: $('#reinstallEmail').val ()}, function (data) {
			$('#reinstallAsk').slideUp (300, function () {
				$('#reinstallThankyou').slideDown (300);
				$('#reinstallContentBox').delay (5000).slideUp (500);
				$('#reinstallThankyou').delay (5000).slideUp (500);
				$('#reinstallAsk').delay (5000).slideDown (500);
			});
		});		
	});
	
	$('#ratingBtn').click (function () {
		var barleft = parseInt ($('#demo-bar').css('margin-left'));
		var left = $(this).position ().left;
		var newLeft = (barleft + left - 78);
		
		$('.jx-nav-menu').hide ();
		$('#jx-ttip-con-id').html ('');
		$('#commentsContentBox').hide ();
		$('#reinstallContentBox').hide ();
		$('#contactusContentBox').hide ();
		
		$('.unit-rating').css('margin', '0 auto');
		$('#ratingContentBox').css('margin-left', newLeft+'px');
		$('#ratingContentBox').toggle (0);
	});
	
	$('#topBannerBtn').click (function () {
		if ($('#bannerBar').is (':visible'))
		{
			$('#bannerBar').slideUp (300, function () {
				$('#mainFrame').css('height', '100%');	
			});
		}
		else
		{
			$('#bannerBar').slideDown (300, function () {
				$('#mainFrame').css('height', '85.5%');	
			});
		}
	});
	
	$('#commentsBtn').click (function () {
		$('.jx-nav-menu').hide ();
		$('#jx-ttip-con-id').html ('');
		$('#ratingContentBox').hide ();
		
		var barleft = parseInt ($('#demo-bar').css('margin-left'));
		var left = $(this).position ().left;
		var newLeft = (barleft + left - 178);
		
		
		$('.unit-rating').css('margin', '0 auto');
		$('#commentsContentBox').css('margin-left', newLeft+'px');
		
		$('#commentsContentBox').toggle (0);
		
		$('#reinstallContentBox').hide ();
		$('#contactusContentBox').hide ();
		
	});
	
	$('.commentPage').click (function () {
		var nameId = $(this).attr('id');
		var splitNameId = nameId.split ('-');
		var page = splitNameId[1];
		
		$('.commentPage').css ('color', '#0071B3');
		$('.commentContentPage').hide ();
		$('#commentContentPage-'+page).show ();
		$('#commentPage-'+page).css ('color', '#000');
		
		return false;
	});
	
	$('#postCommentLink').click (function () {
		$('#commentsContentBox').css ('overflow', 'hidden');

		$('#commentsContentBox').css ('max-height', 'none');
		$('#showComments').slideUp (300, function () {
			$('#postComment').slideDown (300);
		});
	});
	
	$('#postCommentCancel').click (function () {
		$('#commentsContentBox').css ('overflow', 'scroll');
		$('#commentsContentBox').css ('max-height', '400px');
		$('#postComment').slideUp (300, function () {
			$('#showComments').slideDown (300);
		});
	});
	
	$('#postCommentBtn').click (function () {
		$.post ('/demo/include/js/comment.php', {scriptid: scriptid, name: $('#name').val (), comment: $('#commentInput').val ()}, function () {
			$('#name').val ('');
			$('#commentInput').val ('');
			$('#postComment').slideUp (300, function () {
				$('#postCommentThankyou').slideDown (300);
			});
			
			
		
			setTimeout ("$('#postCommentThankyou').hide ();$('#showComments').show ();$('#commentsContentBox').hide ();$('#commentsContentBox').css ('overflow', 'scroll');$('#commentsContentBox').css ('max-height', '400px');", 5000);
			
			
		});
	});
	
	$('.closeIcon, .closeIcon img').click (function () {
		closePopUps ();
	});
	
	$('.closeIconImage').click (function () {
		closePopUps ();
	});
	

});


function processCountDownClock ()
{
	dateNow = new Date();							
	amount = dateFuture.getTime() - dateNow.getTime();
	var microSecondsAdd = 7200000;
	
	if (minutesAdd)
		microSecondsAdd = minutesAdd * 60000;
		
	if(amount < 1000)
	{
		tempDate = dateFuture;
	 	dateFuture.setTime(tempDate.getTime()+microSecondsAdd);
		amount = dateFuture.getTime() - dateNow.getTime();
		setTimeout("processCountDownClock()", 1000);	
	}
	
	days=0;hours=0;mins=0;secs=0;out="";
	amount = Math.floor(amount/1000);
	days=Math.floor(amount/86400);
	amount=amount%86400;
	hours=Math.floor(amount/3600);
	amount=amount%3600;
	mins=Math.floor(amount/60);
	amount=amount%60;
	secs=Math.floor(amount);
	
	if (hours < 10)
		hours = '0'+hours;		
	if (mins < 10)
		mins = '0'+mins;
	if (secs < 10)
		secs = '0'+secs;
	if (hours == 0)
		hours = "00";
	if (mins == 00)
		mins = '00';
	if (secs == 00)
		secs = '00';	
				
	out += hours+":";
	out += mins+":";
	out += secs;

	hr= hours;
	mn=mins;
	se= secs;
	
	tot=''+hr+mn+se;
	
	document.hr1.src = '/demo/images/democlock/0.png';
	document.hr2.src = '/demo/images/democlock/'+tot.substring(1,2)+'.png';
	document.mn1.src = '/demo/images/democlock/'+tot.substring(2,3)+'.png';
	document.mn2.src = '/demo/images/democlock/'+tot.substring(3,4)+'.png';
	document.se1.src = '/demo/images/democlock/'+tot.substring(4,5)+'.png';
	document.se2.src = '/demo/images/democlock/'+tot.substring(5,6)+'.png';	
	
	
	var text = 'This demo will be reinstalled in ';
	if (hr != '00')
		text += hr + ' hour, ';	
	
	if (mn == '01')
		text += mn + ' minute';
	else if (mn == '0' || mn == '00')
		text += 'less than 1 minute';
	else
		 text += mn +' minutes';	
	$('#countDownClock').attr('title', text);
	
	
	setTimeout("processCountDownClock()", 1000);
}

function closePopUps ()
{
	$('#reinstallContentBox').hide ();
	$('#commentsContentBox').hide ();
	$('#ratingContentBox').hide ();
	$('.jx-nav-menu').hide ();
	$('#contactusContentBox').hide ();
}

function privateDemoLink (item)
{
	$('#mainFrame').attr ('src', $(item).attr('href'));
	$('#jx-menu-con-id').css ('display', 'none');
	return false;	
}
