

$(function() {

    //set the page height as 100%
    $('div#mainWrapper').css('height', function() {
        return $(window).height();
    });

    $('input[title!=""]').hint();


    setMenu(); setVideo();setPlayVideo();

    //    navMenu

});

$(window).resize(function() {
setMenu(); setVideo();
});


//Placing menus
function setMenu() {
    $('div#navMenu').css('left', function() {
        var width = $(window).width();        
        $('div#divBottom').css('width',width);
        
        var mainWrapperWidth = $("div#mainWrapper").width();
        var navWidth = $("div#navMenu").width();
        var temp = (width - mainWrapperWidth) / 2;
        if (width > mainWrapperWidth) {
            width = width - navWidth - temp - 10;
        }
        else if (width <= mainWrapperWidth) {
        width = mainWrapperWidth - navWidth - 10;
        }

        return width;

    });

}

function setVideo() {
    $('div#playVideo').css('left', function() {
        var width = $(window).width();
        var mainWrapperWidth = $("div#mainWrapper").width();
        var navWidth = $("div#playVideo").width();
        var temp = (width - mainWrapperWidth) / 2;
        if (width > mainWrapperWidth) {
            width = width - navWidth - temp - 10;
        }
        else if (width <= mainWrapperWidth) {
            width = mainWrapperWidth - navWidth - 10;
        }

        return width;

    });

}

function setPlayVideo() {
    $('div#divplayVideo').css('left', function() {
        var width = $(window).width();
        var mainWrapperWidth = $("div#mainWrapper").width();
        var navWidth = $("div#playVideo").width();
        var temp = (width - mainWrapperWidth) / 2;
        if (width > mainWrapperWidth) {
            width = width - navWidth - temp - 123;
        }
        else if (width <= mainWrapperWidth) {
            width = mainWrapperWidth - navWidth - 123;
        }

        return width;

    });

}
///Watermark text box

jQuery.fn.hint = function(blurClass) {
    if (!blurClass) {
        blurClass = 'blur';
    }

    return this.each(function() {
        // get jQuery version of 'this'
        var $input = jQuery(this),

        // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = jQuery(this.form),
      $win = jQuery(window);

        function remove() {
            if ($input.val() === title && $input.hasClass(blurClass)) {
                $input.val('').removeClass(blurClass);
            }
        }

        // only apply logic if the element has the attribute
        if (title) {
            // on blur, set value to title attr if text is blank
            $input.blur(function() {
                if (this.value === '') {
                    $input.val(title).addClass(blurClass);
                }
            }).focus(remove).blur(); // now change all inputs to title

            // clear the pre-defined text when form is submitted
            $form.submit(remove);
            $win.unload(remove); // handles Firefox's autocomplete
        }
    });
};

/* Testimonials slide show script
**********************************/

var showing;

jQuery(document).ready(function(){	
	showing = jQuery('#rotating_items div.rotating_item:first'); // Initiate the 'showing' variable as the first rotating_item
	showing.siblings('div').hide(); // Hide all other rotating_items
	setInterval("show_next_rotating_item(showing)", 5000); // Set the rotate time to 5 seconds
	
	
	jQuery('#rotating_items').show();
	
	// When a link in the rotating_item is clicked
	// we want to instead treat it as if the whole
	// box was clicked.
	jQuery('#rotating_items a').click(function(){
		jQuery('#rotating_items').click();
		return false;
	});
	
	
	// Now, when the box is clicked, track the click
	// as an event in Google Analytics and then direct
	// the user to the intended URL.
	jQuery('#rotating_items').click(function(){
		var link = showing.contents().find('a').attr('href');
		if(!link) return false; // if there is no link, theres nothing to do here
		var testi_title = showing.find('h3').html();

		if(link!=''){
			window.open(link);
		}
		try {
			pageTracker._trackEvent('rotating_item','click','Following link for ' + testi_title); 
		} catch(err) {
		}							
	}).mouseover(function(){
		jQuery(this).addClass('hover');
	}).mouseout(function(){
		jQuery(this).removeClass('hover');
	});
});


// Below is the code that picks an item at random to display
jQuery.jQueryRandom = 0;  
jQuery.extend(jQuery.expr[":"],  
{  
    random: function(a, i, m, r) {  
        if (i == 0) {  
            jQuery.jQueryRandom = Math.floor(Math.random() * r.length);  
        };  
        return i == jQuery.jQueryRandom;  
    }  
}); 


// The below function repeatedly gets called, to do the rotating
function show_next_rotating_item(t){
	jQuery(t).fadeOut('slow');

	var next_rotating_item = jQuery(t).siblings('.rotating_item:random');
	if(!next_rotating_item.attr('class')){
		next_rotating_item = jQuery('#rotating_items div.rotating_item:first');
	}
	next_rotating_item.fadeIn('slow');
	
	showing = next_rotating_item;	
}

//document.write(unescape("%3Cscript src='" + document.location.protocol + "//zopim.com/?MPqfJhFgWroHfjhHHkgjonxYdpqX70Zc' charset='utf-8' type='text/javascript'%3E%3C/script%3E"));document.write(unescape("%3Cscript src='" + document.location.protocol + "//zopim.com/?MPqfJhFgWroHfjhHHkgjonxYdpqX70Zc' charset='utf-8' type='text/javascript'%3E%3C/script%3E"));