/*******************
 * GENERAL
 ******************/
function showDiv(divname,wording) {
    $('#more-' + divname).fadeIn();
    $('#' + divname + '-dots').hide();
    $("#show-" + divname + "-link").html('<a href="javascript:hideDiv(\'' + divname + '\',\'' + wording + '\');">hide ' + wording + '</a> &uarr;');
}
function hideDiv(divname,wording) {
    $('#more-' + divname).fadeOut();
    $('#' + divname + '-dots').show();
    $("#show-" + divname + "-link").html('<a href="javascript:showDiv(\'' + divname + '\',\'' + wording + '\');">more ' + wording + '</a> &darr;');
}

function openVirtualBook(){
	var backDiv = $('<div id="backDiv">').html('&nbsp;').click(function(){
			$('#backDiv').remove();
			$('#virtualBookIframe').hide();
		});
	$(document.body).append(backDiv);
	var left = (document.body.clientWidth - 760)/2 + "px";
	$('#virtualBookIframe').css('left',left).show();
}

function closeVirtualBook(){
	$('#backDiv').remove();
	$('#virtualBookIframe').hide();
}


function changeStatus(e){
	if($('#basket td:first').length){
		if(confirm('Proceeding with this offer will clear your shopping basket - do you wish to continue?')){
			document.location.href = $(e.target).attr('href');
			return false;
		}else{
			return false;
		}
	}else{
		document.location.href = $(e.target).attr('href');
	}
}


(function($){
	$.fn.defaultInputText = function(which,options){
		options = $.extend({
			cssClass:'gray',
			object:this.get(0)
		}, options || {});
		
		
		// register events
		$(this).focus(_onFocus).blur(_onBlur);
		
		// add clear to form
		$(this).parents('form:first').submit(_clearFromForm);
		
		if($(this).get(0).value.length == 0){
			$(this).addClass(options.cssClass).val(which);
		}
				
		function _onFocus(){
			if(this.value==which){
				$(this).removeClass(options.cssClass).val('');
			}
		};
		
		function _onBlur(){
			 if(this.value==which || this.value.length == 0){
				$(this).addClass(options.cssClass).val(which);
			}
		};
		
		function _clearFromForm(){
			if(options.object.value==which){
				options.object.value='';
			}
		}
		
	};
	
	$.fn.logClicks = function(){
		$(this).click(function(e){
			var data = {};
			var bookCode = $(this).parents('[bookCode]:first').attr('bookCode');
			var ipAddress = $('#ipAddress').text();
			if(ipAddress=="81.144.150.226" || ipAddress=="81.144.150.228" || ipAddress=="192.168.1.123")
				return true;
			//console.log(WEBROOT);			

			data['data[Click][editorial_id]'] = $(this).parents('[editorial_id]:first').attr('editorial_id');
			data['data[Click][bookCode]'] = bookCode;
			data['data[Click][url]'] = $(this).attr('href');
			
			if(data['data[Click][url]']!='#' && data['data[Click][url]']!=undefined && data['data[Click][bookCode]']!=undefined)
				$.post('http://'+WEBROOT+'clicks/record',data);
//			return false;
		});
	};
	
})(jQuery);





// Version 1.0 - October 19, 2007
// Requires http://jquery.com version 1.2.1

(function($) {
	$.fn.biggerlink = function(options) {

		// Default settings
		var settings = {
			hoverclass:'hover', // class added to parent element on hover
			clickableclass:'hot', // class added to parent element with behaviour
			follow: true	// follow link? Set to false for js popups
		};
		if(options) {
			$.extend(settings, options);
		}
		$(this).filter(function(){
			 return $('a',this).length > 0;

		}).addClass(settings.clickableclass).each(function(i){
		
			// Add title of first link with title to parent
			$(this).attr('title', $('a[title]:first',this).attr('title'));
			
			// hover and trigger contained anchor event on click
			$(this)
			.mouseover(function(){
				window.status = $('a:first',this).attr('href');
				$(this).addClass(settings.hoverclass);
			})
			.mouseout(function(){
				window.status = '';
				$(this).removeClass(settings.hoverclass);
			})
			.bind('click',function(){
				$(this).find('a:first').trigger('click');
			})
			
			// triggerable events on anchor itself
			
			.find('a').bind('focus',function(){
				$(this).parents('.'+ settings.clickableclass).addClass(settings.hoverclass);
			}).bind('blur',function(){
				$(this).parents('.'+ settings.clickableclass).removeClass(settings.hoverclass);
			}).end()
			
			.find('a:first').bind('click',function(e){
				if(settings.follow == true)
				{
					window.location = this.href;
				}
				e.stopPropagation(); // stop event bubbling to parent
			}).end()
			
			.find('a',this).not(':first').bind('click',function(){
				$(this).parents('.'+ settings.clickableclass).find('a:first').trigger('click');
				return false;
			});
		});
		return this;
	};
})(jQuery);


jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options); // clone object since it's unexpected behavior if the expired property were changed
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // NOTE Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


