/* 
 * Capture the click event of all <a> tags with rel="modal" OR 
 * all <a> tags with an href urls containing request param "modal" 
 * with value "true" e.g. "/shop/warranties.jsp?modal=true"
 */ 
$(document).ready(function () {
	$('a').live('click', function (event) {
	    var url = $(this).attr('href');
	    var fromBack = $(this).attr('modalBack') ? true : false;
	    var disableClose = $(this).attr('disableModalClose') ? true : false;
	    
	    if( $(this).attr('rel')=='modal' || jQuery.url.setUrl(url).param('modal')=='true' ){
		    // prevent default behaviour on click event
		    event.preventDefault(); 
		    
		    var modalCallBack = function (data) {
   		        openModalJQ(data,url,fromBack,disableClose);
       		};
       		modalCallBack.hideUpdatingOverlay = true;
       		
			ajaxGet(this, modalCallBack);		
		}
	});
});

$(document).ready(function() {
    $('a[rel="ajaxSubmit"]').live('click', function (event) {
    	event.preventDefault();
    	
		var urlString = $(this).attr('href'); 	
    	if (urlString == null || urlString.length == 0) { 
			urlString = $(this).parents("form").attr('action');
		}
		
		performAjaxRequest(	urlString,
							eval($(this).attr('beforeSend')),
							eval($(this).attr('completeLoading')), 
							$(this).attr('dataType'),
							$(this).parents("form").serialize(), 
							eval($(this).attr('successLoading')), 
							eval($(this).attr('errorLoading')), 
							$(this).parents("form").attr('method'),
							getUniqueClass(this)
		);
	});
});

$(document).ready(function () {
    var f = {
    	'create' : function () {  	    
	    	if($('#topNavPromo').size() == 0) {
	     	    $('body').append('<div id="topNavPromo"><a id="topNavPromoButton" href="/shop/page?pageId=3255"></a></div>');
	    	}
	    	
	    	var left = $('#topNav-1').width() + $('#topNav-1').offset().left - parseInt($('#topNavPromoButton').css('width').replace('px', ''));
	    	
	    	$('#topNavPromo').css('top', $('#topNav-1').offset().top + 'px');
	    	$('#topNavPromo').css('left', left + 'px');
	  	}
    };
    
    $(window).resize(function(){
	  	f.create();
  	});
    
  	f.create();
});
