function date_time()
{
   var d = new Date();
   var c_date = d.getDate();
  
   var c_month = d.getMonth();
   c_month += 1;
   var c_year = d.getFullYear();
   
   var c_hour = d.getHours();
   var c_min = d.getMinutes();
   var c_sec = d.getSeconds();
   var c_milsec = d.getMilliseconds() / 10;
   
   if (c_date < 10) { c_date = "0" + c_date; }
   if (c_month < 10) { c_month = "0" + c_month ; }
   
   if (c_hour < 10) { c_hour = "0" + c_hour; }
   if (c_min < 10) { c_min = "0" + c_min; }
   if (c_sec < 10) { c_sec = "0" + c_sec; }
   var t = c_month + "-" + c_date + "-" + c_year + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + c_hour + ":" + c_min + ":" + c_sec;
   return t;
}
function setCamTime() {
    var curTime = date_time();
    $('#timer1').html( curTime );
    $('#timer2').html( curTime );
}

$(document).ready(function() {

    function update_date() {
        var curTime = date_time();
        $('#timer1').html( curTime );
        $('#timer2').html( curTime );
    }
    update_date();

/*
	// preload images
	QueryLoader.selectorPreload = "#preLoad";
	QueryLoader.init();
*/
	// Options for SuperBGImage
	jQuery.fn.superbgimage.defaults = {
		id: 'superbgimage', // id for the containter
		z_index: 0, // z-index for the container
		inlineMode: 0, // 0-resize to browser size, 1-do not resize to browser-size
		showimage: 1, // number of first image to display
		vertical_center: 1, // 0-align top, 1-center vertical
		transition: 0, // 0-none, 1-fade, 2-slide down, 3-slide left, 4-slide top, 5-slide right, 6-blind horizontal, 7-blind vertical, 90-slide right/left, 91-slide top/down
		transitionout: 1, // 0-no transition for previous image, 1-transition for previous image
		randomtransition: 0, // 0-none, 1-use random transition (0-7)
		showtitle: 0, // 0-none, 1-show title
		slideshow: 1, // 0-none, 1-autostart slideshow
		slide_interval: 1800, // interval for the slideshow
		randomimage: 0, // 0-none, 1-random image
		speed: 'fast', // animation speed
		preload: 1, // 0-none, 1-preload images
		onShow: superbgimage_show, // function-callback show image
		onClick: null, // function-callback click image
		onHide: null, // function-callback hide image
		onMouseenter: null, // function-callback mouseenter
		onMouseleave: null, // function-callback mouseleave
		onMousemove: null // function-callback mousemove
	};

	// initialize SuperBGImage
	//$('#thumbs').superbgimage().hide();
	
	
	var curSlideshow = 1;
	var pausedSlideshow;
	
	// New Security Camera settings
	$('#camera').html( $('#camera1').html() );
	$('#camera').superbgimage();
	
	function restartSlideshow() {
	    update_date();
	    jQuery.fn.superbgimage.defaults.slideshow = 1;
	    $('#camera').delay(2000).superbgimage({ reload: true });
	    //clearTimeout(timer);
	}	
	// function callback on showing image 06
	function superbgimage_show(img) {
	    update_date();
	    if (img == 8) {
	        $('superbgimage').stopSlideShow();
	        if (curSlideshow < 14 ) {
                curSlideshow++;
            } else {
                curSlideshow = 1;
            }
	        $('#camera').delay(4000).html( $('#camera' + curSlideshow).html() );
	        //console.log(curSlideshow);
	        restartSlideshow();
	        /*
	        
	        timer = setTimeout( function() {
	            update_date();
	            if (curSlideshow < 4 ) {
	                curSlideshow++;
	            } else {
	                curSlideshow = 1;
	            }
	            
	            $('#camera').delay(2000).html( $('#camera' + curSlideshow).html() );
	            console.log(curSlideshow);
	            alert(curSlideshow);
	            restartSlideshow();
	        }, 2000 );
	        */
	        //$('#camera').html( $('#camera2').html() );
            //$('#camera').superbgimage({ reload: true });
	        //$('#camera').html( $('#camera2').html() );
	        //setTimeout( "$('superbgimage').startSlideShow();", 4000 );
	    }
	    /*
		if ($.superbg_imgSlide == 1) {
			$('superbgimage').stopSlideShow();
			setTimeout( "$('superbgimage').startSlideShow();", 4000 );
		}
		if ($.superbg_imgSlide == 49) {
			$('superbgimage').stopSlideShow();
			setTimeout( "$('superbgimage').startSlideShow();", 3000 );
		}
		*/

	};

 $(".popup-link").colorbox({
    width: "690px", 
    transition:"none", 
    opacity: "0.6",
    onOpen:function(){  // stop slideshow 
	    pausedSlideshow = curSlideshow;

	    $('#camera').stopSlideShow();

	    $('#camera').html( $('#' + $(this).attr('rel') + '-hero').html() );
        //console.log(curSlideshow);
        jQuery.fn.superbgimage.defaults.slideshow = 0;
        $('#camera').superbgimage({reload:true}).stopSlideShow();
         },
    onClosed:function(){       // restart slideshow
     		$('#camera').html( $('#camera' + pausedSlideshow).html() );
     		restartSlideshow(); }
    });
	
	// load image set 2
	$('a.loadset2').click(function(){
		$('#thumbs1').stopSlideShow();
		$('#thumbs2').stopSlideShow();
		my_slideshowActive = false;
		$('#showtitle').hide();
		$('#thumbs1').hide().addClass('hidden');
		$('#thumbs2').superbgimage({ reload: true }).show().removeClass('hidden');
		return false;
	});

	// drop down list
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
			
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		$(this).calcSubWidth();
		//Set Width
		$(this).find(".sub").css({'width' : rowWidth + 44});			
		
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}

	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("#navMain li .sub").css({'opacity':'0'});
	$("#navMain li").hoverIntent(config);
/*
	$('#navProducts li').click(function() { 
		return false; 
	});*/
		/*
	// hover icons	
	$("#navProducts a,#navCommunity a,#navStore a").blend({ speed: 300 });

	// remove broken links
	$('img').error(function () {
		$(this).remove();
	});

	// external sites in a new window
	$("a[rel=external]").attr('target', '_blank');
*/
/*
	// product popups
	$('a.poplight[href^=#]').click(function() {
	    // stop slideshow 
	    pausedSlideshow = curSlideshow;
	    
	    $('#camera').stopSlideShow();
	    
	    $('#camera').html( $('#' + $(this).attr('rel') + '-hero').html() );
        //console.log(curSlideshow);
        jQuery.fn.superbgimage.defaults.slideshow = 0;
        $('#camera').superbgimage({reload:true}).stopSlideShow();
	    
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size
	
		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value
	
		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="images/icon-close-popup.png" class="btn-close" title="Close Window" alt="Close" /></a>');
	
		//Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;
	
		//Apply Margin to Popup
		$('#' + popID).css({
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
	
		//Fade in Background
		$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		$('#fade').css({'filter' : 'alpha(opacity=60)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 	
		return false;
	});
	
	//Close Popups and Fade Layer
	$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
		$('#fade, .popup_block').fadeOut(function() {
			$('#fade, a.close').remove();  //fade them both out
		});
		// restart slideshow
		$('#camera').html( $('#camera' + pausedSlideshow).html() );
		restartSlideshow();
		return false;
	}); 
*/
});


