/***********************************************
* jQuery functions execute
***********************************************/

//bookmark function

function bookmarksite(title,url){
	if (window.sidebar) 
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ 
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)
		window.external.AddFavorite(url, title);
}

jQuery(document).ready(function(){                  
              
	/*cmx form */
	if(jQuery.browser.mozilla) {
		$('form.cmxform').hide().find('label:not(.nocmx)').each(function(){
                          	var $labelContent = $(this).html();
                                       var $labelWidth = $(this).css('width');
                                       $(this).empty();
                                       $(this).append('<span style="display: block; width: '+$labelWidth+';">');
                                       $(this).prepend('</span>');
                                       $(this).css('display', '-moz-inline-box');
                                       $(this).find('span').html($labelContent);
                                       $('form.cmxform').show();
                                });
                };          
  
	/*email protect*/
		$("span.safermailing").each(function(){
			exp = $(this).text().search(/\((.*?)\)/) != -1 ? new RegExp(/(.*?) \((.*?)\)/) : new RegExp(/.*/);
			match = exp.exec($(this).text());
			addr = match[1] ? match[1].replace(/ at /,"@").replace(/ dot /g,".") : match[0].replace(/ at /,"@").replace(/ dot /g,".");
			link = match[2] ? match[2] : addr;
			subject = $(this).attr('title') ? "?subject="+$(this).attr('title').replace(/ /g,"%20") : "";
			$(this).after('<a href="mailto:'+addr+subject+'">'+ link + '</a>');
			$(this).remove();
		});
	
	/*non css2.1*/$('body').css('overflow-x', 'hidden');
	/*external link*/$('a[rel*=external]').click( function(){this.target = "_blank";});
	/*slimbox*/$('#lbOverlay').css('cursor', 'pointer');
	/*image link*/	$("#logo").css('cursor', 'pointer').click( function() { window.location = './';});

	/*on focus for input boxes*/
	$.fn.search = function() {
		return this.focus(function() {if( this.value == this.defaultValue ) {this.value = "";}})
		.blur(function() {if( !this.value.length ) {this.value = this.defaultValue;}});};
	$(".focus").search();

	/*accordion navigation*/
	/*
	$('#equipment-catalogue ul').accordion({
			active: false,
			header: '.firstlevel',
			navigation: true,
			event: 'click',
			autoheight: false,
			alwaysOpen: false
		});*/
	
	/*set hover class for anything*/
	$('input.go, input.send, input.inputhover, a.hoverlink').css('cursor', 'pointer');
	$('a.hoverlink').hover(function() {$(this).addClass('linkhover');}, function() {$(this).removeClass('linkhover');});
	$('input.send').hover(function() {$(this).addClass('inputhover');}, function() {$(this).removeClass('inputhover');});
	$('ul.listings li').css('cursor', 'pointer').click(function(){window.location = $(this).find('a').attr("href");});
	
	/*dimming images on hover*/
	$('.dimmer, li#socials a, .cta-socials a, li#hub a').css('opacity', '0.55').css('cursor', 'pointer');
	$('.dimmer, li#socials a, .cta-socials a, li#hub a').hover(function() {$(this).css('opacity', '1.0');}, function() {$(this).css('opacity', '0.55')});
	$('.thumbs a, ul#gallery a').css('opacity', '0.75').css('cursor', 'pointer');
	$('.thumbs a, ul#gallery a').hover(function() {$(this).css('opacity', '1.0');}, function() {$(this).css('opacity', '0.75')});
	
	/*dropdown fix*/
	$('ul#address-bar li').hover(function() {$(this).addClass('firstover');}, function() {$(this).removeClass('firstover');});
	$('ul#address-bar ul').hover(function() {$('li.firstover a').addClass('activestate');}, function() {$('li.firstover a').removeClass('activestate');});
	$('ul#address-bar li').hover(function(){$(this).find('ul').slideDown('slow');}, function(){$(this).find('ul').fadeOut('fast');});
	$('ul#nav li').hover(function() {$(this).addClass('over');}, function() {$(this).removeClass('over');});
	$('ul#nav li').hover(function() {$(this).find('ul').fadeIn('slow');}, function() {$(this).find('ul').fadeOut('fast');});
	$('ul#nav ul').hover(function() {$('li.over a').addClass('onsection');}, function() {$('li.over a').removeClass('onsection');});
	/*if hover li linking to the a href address
	$('ul#nav li').click(function(){window.location = $(this).find('a').attr("href");});*/
	
	/*advanced hide and show*/
	$('ul.product_range li> ul').hide();
	$('ul.product_range li> a').click(function() {
	$(this).next('ul').slideToggle('fast')
	.parent().siblings('li').find('ul:visible').slideUp('fast');});
		
	$("#EnquiryForm, #compressors-form, #cable-hauling-form, #torque_tools-form, #cable-hauling-form, #hydraulic_power-form, #hydraulic-jacking-form, #load-cell-form, #mooring-form, #pipe-rolling-form, #winch-form, #rigging-form, #pipe-rolling-form, #spoolers-form").submit(function() {
      var s1 = 'hire';
      var s2 = '@';
      var s3 = 'jackswinches.com';
      $(this).append('<input type="hidden" name="recipient" value="' + s1 + s2 + s3 + '" />');
    });

});

