$(function(){
	makeSlider('#slider', 'boxRain', 500, 6000, 'num');
	
	
	$('footer #footer-inner nav.footer li.last').removeClass('last');
	$('footer #footer-inner nav.footer a.lone').appendTo('footer #footer-inner nav.footer ul').wrap('<li class="last"></li>');


			$('.rndImg').hide();	
			var whichImage = Math.floor(Math.random()*8);
			$('.rndImg_' + whichImage).show();
	$('#home-video iframe').fadeIn(1000);
	
	
	var config = {
		siteURL		: 'sitesafeonline.com',	// Change this to your site
		type		: 'web',
		append		: false,
		perPage		: 8,			// A maximum of 8 is allowed by Google
		page		: 0				// The start page
	}

	// Focusing the input text box:
	$('#search-form input').focus();

	$('#search-form').submit(function(){
		googleSearch();
		return false;
	});

	
	$('#resultsDiv a#res-close').click(function() {
		$('#resultsDiv').slideUp();
		return false;
	});
	
	function googleSearch(settings){

		// If no parameters are supplied to the function,
		// it takes its defaults from the config object above:
	
		settings = $.extend({},config,settings);
		//settings.term = settings.term || $('#search-form input').val();
		settings.term = $('#search-form input[name="qfront"]').val();
	
		// Using the Google site:example.com to limit the search to a
		// specific domain:
		settings.term = 'site:'+settings.siteURL+' '+settings.term;
	
		// URL of Google's AJAX search API
		var apiURL = 'http://ajax.googleapis.com/ajax/services/search/'+settings.type+
						'?v=1.0&callback=?';
		var resultsDiv = $('#resultsDiv #results');
	
		$.getJSON(apiURL,{
			q	: settings.term,
			rsz	: settings.perPage,
			start	: settings.page*settings.perPage
		},function(r){
			var results = r.responseData.results;
			$('#more').remove();
	
			if(results.length){
	
				// If results were returned, add them to a pageContainer div,
				// after which append them to the #resultsDiv:
	
				var pageContainer = $('<div>',{className:'pageContainer'});
	
				for(var i=0;i<results.length;i++){
					// Creating a new result object and firing its toString method:
					pageContainer.append(new result(results[i]) + '');
				}
	
				if(!settings.append){
					// This is executed when running a new search,
					// instead of clicking on the More button:
					resultsDiv.empty();
				}
				//var resultsHeight = $('#resultsDiv').height();
				//$('#resultsDiv').css('top', '-'+resultsHeight+'px');
					pageContainer.append('<div class="clear"></div>')
								 .hide().appendTo(resultsDiv)
								 .fadeIn('slow', function(){
									 $('#resultsDiv').slideDown();
								 });
				var cursor = r.responseData.cursor;
	
				// Checking if there are more pages with results,
				// and deciding whether to show the More button:
	
				if( +cursor.estimatedResultCount > (settings.page+1)*settings.perPage){
					$('<div>',{id:'more'}).appendTo(resultsDiv).click(function(){
						googleSearch({append:true,page:settings.page+1});
						$(this).fadeOut();
					});
				}
			}
			else {
	
				// No results were found for this search.
	
				resultsDiv.empty();
				$('<p>',{
					className	: 'notFound',
					html		: 'No Results Were Found!'
				}).hide().appendTo(resultsDiv).fadeIn('slow', function(){
									 $('#resultsDiv').slideDown();
								 });
			}
		});
	}
	
	function result(r){

		// This is class definition. Object of this class are created for
		// each result. The markup is generated by the .toString() method.

		var arr = [];

		// GsearchResultClass is passed by the google API
		arr = [
			'<div class="webResult">',
			'<h3><a href="',r.url,'">',r.title,'</a></h3>',
			'<p>',r.content,'</p>',
			'<a href="',r.url,'">',r.visibleUrl,'</a>',
			'</div>'
		];

		// The toString method.
		this.toString = function(){
			return arr.join('');
		}
	}
});

(function () {

      /*
          1. Inject CSS which makes iframe invisible
      */

    var div = document.createElement('div'),
        ref = document.getElementsByTagName('base')[0] ||
              document.getElementsByTagName('script')[0];

    div.innerHTML = '&shy;<style> iframe { visibility: hidden; } </style>';

    ref.parentNode.insertBefore(div, ref);

    /*
        2. When window loads, remove that CSS,
           making iframe visible again
    */

    window.onload = function() {
        div.parentNode.removeChild(div);
    }

})();
