//http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);
function openWindow(_URL,_width,_height,_scrollbars) {
    var _left=(screen.availWidth/2)-(_width/2);
    var _top=(screen.availHeight/2)-(_height/2);
    window.open(_URL,"popupWindow","directories=no,menubar=no,location=yes,resizable=yes,scrollbars="+_scrollbars+",status=no,toolbar=no,height="+_height+",width="+_width+",left="+_left+",top="+_top);
}

var inputtext = {};
$(document).ready(function(){

	$.preLoadImages(
		'assets/images/nav-home_hover.png',
		'assets/images/nav-services_hover.png',
		'assets/images/nav-products_hover.png',
		'assets/images/nav-request-quote_hover.png',
		'assets/images/nav-contact_hover.png'
	);

	// Rollover Images
	$('.hover').each(function(){
		$(this)
			.attr('title',$('a',this).text())
			.click(function(){
				src = $(this).css('background-image');
				$(this).css('background-image',src.replace(/_hover\.png/,'.png'));
				document.location.href=$('a',this).attr('href');
			})
			.hover(
				function() {
					src = $(this).css('background-image');
					$(this).css('background-image',src.replace(/\.png/,'_hover.png'));
				},
				function() {
					src = $(this).css('background-image');
					$(this).css('background-image',src.replace(/_hover\.png/,'.png'));
				}
			)
			.css('cursor','pointer')
		;
	});

	$('.cycle-fast').cycle({
		cleartype:!$.support.opacity,
		cleartypeNoBg:false,
        random:true,
		pause:true,
        timeout:2000,
        speed:400,
        requeueOnImageNotLoaded: true
    });
	$('.cycle-normal').cycle({
		cleartype:!$.support.opacity,
		cleartypeNoBg:false,
        random:true,
		pause:true,
        timeout:10000,
        speed:400,
        next:'.cycle-normal',
        requeueOnImageNotLoaded: true
    }).css('cursor','pointer');
	
	$('input.text').focus(function(){
		id = $(this).attr('id');
		if(inputtext[id] === undefined) {
			inputtext[id] = $(this).val();
		}
		if($(this).val() === inputtext[id]) {
			$(this).val('');
		}
	}).blur(function(){
		id = $(this).attr('id');
		if($(this).val() === '') {
			$(this).val(inputtext[id]);
		}
	});

	$('#logo').click(function(){window.location.href='/';}).css('cursor','pointer').attr('title','Ingold Sound Systems');
	$('#btn-view-services-list').click(function(){window.location.href='/services/';}).css('cursor','pointer').attr('title','View Complete List Of Services');
	$('#btn-request-quote').click(function(){window.location.href='/request-quote/';}).css('cursor','pointer').attr('title','Request A Quote For Your Project');
	$("#view-serving-map").colorbox({iframe:true, innerWidth:640, innerHeight:480});
});
