function addMega(){$(this).addClass("hovering");}
function removeMega(){$(this).removeClass("hovering");}
var megaConfig = { interval: 100, sensitivity: 4, over: addMega, timeout: 100, out: removeMega };

/* onLoad code STARTS */
$(document).ready(function(){
	
	/* Homepage */
	$("#home .accordion").accordion({fillSpace: true});
	$("#reviews .review_main").hide(); // hide all
	$("#reviews .review_main:first").show(); // show first one only
	$("#review_categories a:first").addClass("active");
	$("#review_categories a").click(function() {
		$("#review_categories a").removeClass("active");
		$(this).addClass("active");
		$("#review_categories a").css("border-right-width", "1px");
		$(this).css("border-right-width", "0");
		$("#reviews .review_main").hide(); // hide all
		$("#reviews " + this.hash).show();
		return false;
	});
	// extra review hide/show
	$("#reviews .review_extra").each(function(){
		$(this).children("ul").children("li:first").children("div").show();
		$(this).children("ul").children("li:first").children("span").css('background-position', '-10px 50%');
	});
	$("#reviews .review_extra ul li > a").click(function(){
		// if div is opened, follow link
		if( $(this).parent().children("div").css('display') == "block" )
		{
			// follow link
		}
		// else, default behaviour: hide/show
		else
		{
			$(this).parent().parent().parent().children("ul").children("li").children("div").hide();
			$(this).parent().parent().parent().children("ul").children("li").children("span").css('background-position', '0 50%');
			$(this).siblings("div").toggle();
			$(this).parent().children('span').css('background-position', '-10px 50%');
			return false;
		}
	});
	
	bestcat_scroller("#bestsellers", "#bestsellers_content", ".categorylisting");
	function bestcat_scroller (_ps,content_conveyor,e) {
		//vars
		var conveyor = $(content_conveyor, $(_ps));
		var item = $(e, $(_ps));
		var firstVisibleItem = $(e).filter(':visible:eq(0)');
		if(firstVisibleItem.length == 0) return;
		var itemWidth = parseInt(firstVisibleItem.outerWidth(true));
		//set length of conveyor
		conveyor.css("width", item.length * itemWidth);
		//config
		var sliderOpts = {
			max: (item.length * itemWidth) - parseInt($(_ps).css("width")),
			change: function(e, ui) {
				conveyor.animate({ left : "-" + ui.value + "px" }, 500);
			},
			step: itemWidth,
			animate: true
		};
		$(_ps).find(".slider").slider(sliderOpts);
		$(_ps).find(".btn-next").bind('click', function(){
			var curr_value = $(_ps).find(".slider").slider("value");
			$(_ps).find(".slider").slider("value", curr_value + itemWidth);
			return false;
		});
		$(_ps).find(".btn-prev").bind('click', function(){
			var curr_value = $(_ps).find(".slider").slider("value");
			$(_ps).find(".slider").slider("value", curr_value - itemWidth);
			return false;
		});
	};
	
	
	/* search page */
	var cache = {};
	$("#search_simple").autocomplete({
		minLength: 3,
		source: function(request, response) {
			if ( request.term in cache ) {
				response( cache[ request.term ] );
				return;
			}
			$.ajax({
				url: "/search/autocomplete/"+request.term,
				dataType: "json",
				success: function( data ) {
					cache[ request.term ] = data;
					response( data );
				}
			});
		},
		focus: function(event, ui) {
			$("#search_simple").val(ui.item.label);
			return false;
		},
		select: function(event, ui) {
			$("#search_simple").val(ui.item.label);
			window.location = ui.item.value;
			return false;
		}
	});
	
	/* Product page */
	
	/* Product page 'GoTo' functions (open correct tab and scroll to content) */
	$('.gotoReview').click(function(){
		$("a[href='#user']").click(); // simulate tab click
		window.location.href = '#user';
		return false;
	});
	$('.gotoWriteReview').click(function(){
		$("a[href='#user']").click(); // simulate tab click
		window.location.href = '#writeReview';
		return false;
	});
	
	/* direct rating */
	$('.directRating').rating({
		required: true,
		focus: function(value, link){
			var tip = $('#directRatingTip');
			if(tip[0])
			{
				tip[0].data = tip[0].data || tip.html();
				tip.html(link.title || 'value: '+value);
			}
		},
		blur: function(value, link){
			var tip = $('#directRatingTip');
			if(tip[0])
			{
				$('#directRatingTip').html(tip[0].data || '');
			}
		},
		callback: function(value, link){
			$(this.form).ajaxSubmit({
				target: '#directRatingTip'
			});
			//$('.directRating').rating('disable');
			//$('#directRatingTip').html('Thanks!');
			$('#directRatingForm').html('<div style="line-height:1.5em;"><span class="rating-large"><span class="stars" style="width: '+(value*20)+'%;">'+value+'.00 stars</span></span> Thanks!</div>');
		}
	});
	
	/* Product page user review form handling */
	$('#review_advantages').keyup(function(){ limitChars('review_advantages', 1000, 'review_advantages_strlen') });
	$('#review_disavantages').keyup(function(){ limitChars('review_disavantages', 1000, 'review_disavantages_strlen') });
	$('#review_overall').keyup(function(){ limitChars('review_overall', 80, 'review_overall_strlen') });
	/* review rating */
	$('input.starRating').rating({
		required: true,
		focus: function(value, link){
			var tip = $('#ratingTip');
			tip[0].data = tip[0].data || tip.html();
			tip.html(link.title || 'value: '+value);
		},
		blur: function(value, link){
			var tip = $('#ratingTip');
			$('#ratingTip').html(tip[0].data || '');
		},
		callback: function(value, link){
			$('input.starRating[name=rating]').val(value);
		}
	});
	$('#reviewForm').ajaxForm({
		beforeSubmit: 	validateReview,
		success: 	reviewNotification
	});
	/* shorten review strings */
	$('#user .comment p').truncate({max_length: 500});
	
	/* embed youtube video */
	$('#popupEmbedForm').submit(function(){
		$('#review_embed').val($('#popupEmbed').val());
		$("#youtube-embed").dialog("close");
		return false;
	});
	
	/* paginated user reviews */
	$('#user_reviews_container .pagination a').live("click", function(){
		var resourceLink = $(this).attr("href");
		$.ajax({
			type: "GET",
			url: resourceLink,
			dataType: "html",
			beforeSend: function(){
				$('#user_reviews_container').fadeOut('fast').html('<img src="/img/frontend/ajax-loader.gif" alt="...please wait..." class="ajaxLoader" />').fadeIn('slow');
			},
			success: function(response){
				$('#user_reviews_container').hide().html(response).fadeIn('slow');
			}
		});
		return false;
	});
	
	/* Product page QnA user question form handling */
	$('#questionForm').ajaxForm({
		beforeSubmit:	validateQuestion,
		success:	questionNotification
	});
	$('#qna_question').keyup(function(){ limitChars('qna_question', 250, 'qna_q_strlen') });
	/* hide extra QnA answers (x > 2) */
	$('#qna .wrapper').each(function(j){
		$(this).children('dl').children('dd.item').each(function(i){
			if(i > 1) $(this).hide();
		});
	});
	// Show extra answers
	$("#qna .answers a").live("click", function(){
		$(this).parent().parent().siblings().show();
		return false;
	});
	/* shorten QnA answer strings */
	$('#qna .wrapper dd.item span').truncate({max_length: 500});
	
	/* paginated QnAs */
	$('#qnas_container .pagination a').live("click", function(){
		var resourceLink = $(this).attr("href");
		$.ajax({
			type: "GET",
			url: resourceLink,
			dataType: "html",
			beforeSend: function(){
				$('#qnas_container').hide().html('<img src="/img/frontend/ajax-loader.gif" alt="...please wait..." class="ajaxLoader" />').fadeIn('slow');
			},
			success: function(response){
				$('#qnas_container').hide().html(response).fadeIn('slow');
				
				/* hide extra QnA answers (x > 2) */
				$('#qna .wrapper').each(function(j){
					$(this).children('dl').children('dd.item').each(function(i){
						if(i > 1) $(this).hide();
					});
				});
			}
		});
		return false;
	});

	var slept = false;
	/* post download screen */
	$(".downloadProduct").click(function(e) {
		$("#productDetailcontainer").hide(); // hide product details
		$("#postDownload").fadeIn(); // show post download screen
		
		var url = $('.downloadProduct').attr('href');
		
		if( url.indexOf('8307') == '-1' ) // no popup for Babylon
		{
			$("#downloadPopup").dialog( {width:617, dialogClass:'popup-downloadPopup', resizable: false, closeText: 'close', modal: true });
		}
		
		
		// MSIE bug fix: throw in marker as referer is not carried over via js
		if ( $.browser.msie ) {
			url = url+'/ie';
		}
		// Chrome & MSIE bug fix: wait 1sec before going to link
		setTimeout("redirect('" + url + "')", 1000);
		return false;
	});
	
	/* -discount & -coupon pages: reveal/hide more discount */
	$('.toggleLimit').click(function() {
		$(this).parent().prev('.children').toggleClass('limit');
		return false;
	});
	
	/* publisher listing */
	$("#publisherIndexA").show();
	$("#publisherJumpTo a").click(function(){
		$("div.publisherGroup").hide(); // hide all
		$(this.hash).show();
		return false;
	});
	
	/* category pages */
	$(".product-table tr:nth-child(even)").css("background-color", "#f6f6f6");
	
	/* FB logout */
	$('#logout').click(function(){
		FB.logout(function(response){});
		setTimeout("redirect('/auth/logout')", 1500);
		return false;
	});
	
	/* Sign in */
	$("#signInLocal").click(function() {
		$('#signInForm').toggle('slow');
	});
	
	/* Black Friday */
	$('.showitall').click(function(){
		$('#bf_like').hide();
		$('#bf_mask').hide();
	});
	
	$(".tabs").tabs(); // initialise tabs
	
	price_watcher.init('#price-watcher','ol a.remove');
	site_content.init('#site-map','ol a.remove');
	
	/*
	// initialise product scroller
	$("#spotlight #fragment-1, #spotlight #fragment-2, #spotlight #fragment-3").each(function() {
		product_scroller.init(this,'.content-conveyor','.product');
	});
	// initialise product scroller
	$("#category #pane1").each(function() {
		product_scroller.init(this, '.content-conveyor', '.product');
	});
	$("#featured-reviews").each(function() {
		product_scroller.init(this,".content-conveyor","ul.featured li");
	});
	*/
	
	$("#other-softwares .viewer, #other-editions .viewer, #related-software .viewer").each(function() {
		product_scroller.init(this,".content-conveyor","ul.sidebar");
	});

	// Top Nav Dropdown
	$("li.mega > a").click(function(){ return false; });
	$("li.mega").hoverIntent(megaConfig);

	// Sign in Dropdown
	$("#sign-in > a").click(function(){
		$(this).parent().toggleClass("open");
		if ($(this).parent().hasClass("open")){ $(this).parent().children("div").show(); }
		else { $(this).parent().children("div").hide(); }
		return false;
	});
	// New Customers Dropdown
	$("#new-customers a").click(function(){
		$(this).parent().toggleClass("open");
		if ($(this).parent().hasClass("open")){ $(this).parent().children("div").show(); }
		else { $(this).parent().children("div").hide(); }
		return false;
	});

	/* vtip(); topdownloads(); */
	
	// Initialise Popups
	$("a.sign-in").click(function(){ $("#popup-sign-in").dialog( {width:617, dialogClass:'popup-sign-in', resizable: false, closeText: 'close', modal: true }); return false; });
	$("a.youtube").click(function(){ $("#youtube-embed").dialog( {width:447, dialogClass:'popup-youtube', resizable: false, closeText: 'close', modal: true }); return false; });
	$("a.submitted").click(function(){ $("#submitted").dialog( {width:447, dialogClass:'popup-submitted', resizable: false, closeText: 'close', modal: true }); return false; });
	$("a.variation").click(function(){ $("#variation").dialog( {width:617, dialogClass:'popup-sign-in', resizable: false, closeText: 'close', modal: true }); return false; });
	$("a.checker").click(function(){ $("#popup-software-checker .popup").dialog( {width:530, dialogClass:'popup-software-checker', resizable: false, closeText: 'close', modal: true }); return false; });
	
	// Initialise Remove Buttons
	/* remove_element.init("#accounts #price-watcher-list a.remove","li");
	remove_element.init("#shopping-cart a.remove","tr"); */
});
/* onLoad code ENDS */

/* url redirection */
function redirect(url) { location.href = url; }

/* User Review validation */
function validateReview(formData, jqForm, options) {
	var advantages = $('#review_advantages').val();
	var disavantages = $('#review_disavantages').val();
	var overall = $('#review_overall').val();
	var rating = $('.starRating[name=rating]:checked').val();
	if (!advantages || !disavantages || !overall || !rating) {
		alert('Please fill in all fields'); return false;
	}
	// all good, disable submit button to avoid double-posting
	$("#reviewForm .btn-submit").fadeOut('fast');
	$("#reviewForm").append('<p style="float:right;margin-top: 15px;">please wait&hellip; <img src="/img/frontend/ajax-loader-small.gif" alt="" style="vertical-align:middle;" /></p>').fadeIn('slow');
}
/* QnA validation */
function validateQuestion(formData, jqForm, options) {
	var content = $(jqForm[0]).children('textarea').val();
	if (!content) {
		alert('Please enter your question'); return false;
	}
	// all good, disable submit button to avoid double-posting
	$("#questionForm .btn-submit").fadeOut('fast');
	$("#questionForm").append('<img src="/img/frontend/ajax-loader-small.gif" alt="please wait" />').fadeIn('slow');
}
function validateAnswer(formData, jqForm, options) {
	var content = $(jqForm[0]).children('textarea').val();
	if (!content) {
		alert('Please enter your answer'); return false;
	}
	// all good, disable submit button to avoid double-posting
	$(jqForm[0]).children(".btn-submit").fadeOut('fast');
	$(jqForm[0]).children('textarea').after('<img src="/img/frontend/ajax-loader-small.gif" alt="please wait" />').fadeIn('slow');
}


function reviewNotification() {
	var str1 = 'Your review has been submitted';
	var str2 = 'Reviews are moderated and generally will be posted if they are on-topic and not abusive.';
	// replace form
	$("#reviewForm").html('<p>'+str1+'</p><p>'+str2+'</p>');
	// popup notification
	$("#submitted .popup").html('<h3>'+str1+'</h3><p>'+str2+'</p>');
	$("#submitted").dialog( {width:447, dialogClass:'popup-submitted', resizable: false, closeText: 'close', modal: true });
}
function questionNotification() {
	var str1 = 'Your question has been submitted, thank you.';
	var str2 = 'Questions are moderated and generally will be posted if they are on-topic and not abusive.';
	// replace form
	$("#questionForm").html('<p>'+str1+'</p><p>'+str2+'</p>');
	// popup notification
	$("#submitted .popup").html('<h3>'+str1+'</h3><p>'+str2+'</p>');
	$("#submitted").dialog( {width:447, dialogClass:'popup-submitted', resizable: false, closeText: 'close', modal: true });
}
function answerNotification(a,b,c,d) {
	var str1 = 'Your answer has been submitted, thank you.';
	var str2 = 'Answers are moderated and generally will be posted if they are on-topic and not abusive.';
	// replace form
	$(d).html('<p>'+str1+'</p><p>'+str2+'</p>');
	// popup notification
	$("#submitted .popup").html('<h3>'+str1+'</h3><p>'+str2+'</p>');
	$("#submitted").dialog( {width:447, dialogClass:'popup-submitted', resizable: false, closeText: 'close', modal: true });
}

/* product variations */
function select_variation(product_id) {
	/* 0=>name, 1=>locale, 2=>buy_url, 3=>currency, 4=>price, 5=>msrp, 6=>coupon_text, 7=>licence, 8=>version */
	$("#product_main_name").text(variationData[product_id][0]);
	$("#product_main_download a.buy").attr('href', variationData[product_id][2]);
	$("#product_variation_details #license").text(variationData[product_id][7]);
	$("#product_variation_details #edition").text( variationData[product_id][1].charAt(0).toUpperCase() + variationData[product_id][1].slice(1) ); // ucfirst
	$("#product_variation_details #version").text(variationData[product_id][8]);
	$("#product_main_price .price").text(variationData[product_id][3] + variationData[product_id][4]);
	
	if(variationData[product_id][4] < variationData[product_id][5]) {
		
		//var diff = Math.round(variationData[product_id][5] - variationData[product_id][4]);
		var diff = Math.round((variationData[product_id][5] - variationData[product_id][4])*Math.pow(10,2))/Math.pow(10,2);

		var off = Math.round( (diff) * (100 / variationData[product_id][5]) ); // compute discount in %
		
		$("#product_main_price .retail-price").html('MSRP: <strike>' + variationData[product_id][3] + variationData[product_id][5] + '</strike>');
		
		$("#productDetailcontainer .prod-details div.coupon.group").remove(); // remove before adding
		$("#product_main_price").after('<div class="coupon group"><a href="' + variationData[product_id][2] + '" rel="nofollow" onclick="_gaq.push([\'_trackPageview\', \'' + variationData[product_id][2] + '\']);">Save ' + variationData[product_id][3] + diff + ' (' + off + '%)</a></div>');
	}
	else {
		$("#product_main_price .retail-price").empty();
		$("#productDetailcontainer .prod-details div.coupon.group").remove();
	}
	
	if(variationData[product_id][6].length > 0) { $("#product_main_discount").text('Discount: '+variationData[product_id][6]); }
	else { $("#product_main_discount").text(''); }
	
	$("#variation").dialog("close");
	return false;
}


/* quick find box */
function quickfind() {
	var array = $('#input_category').val().split('|');
	if ($('#input_mac:checked').length > 0) // mac
		var url = array[1];
	else // windows
		var url = array[0];
	window.location = url;
}

var remove_element = { init: function(e, p) {
	$(e).bind('click', function(){
		if((p) == "tr") { $(this).parents(p).css('display','none'); }
		else { $(this).parents(p).slideUp('slow'); }
		return false;
	});
}};

var product_scroller = {
	init: function(_ps,content_conveyor,e) {
		
		//vars
		var conveyor = $(content_conveyor, $(_ps));
		var item = $(e, $(_ps));
		var firstVisibleItem = $(e).filter(':visible:eq(0)');
		if(firstVisibleItem.length == 0) return;
		var itemWidth = parseInt(firstVisibleItem.outerWidth(true));
		
		//set length of conveyor
		conveyor.css("width", item.length * itemWidth);
		
		//config
		var sliderOpts = {
		  	max: (item.length * itemWidth) - parseInt($(_ps).css("width")),
			change: function(e, ui) {
				conveyor.animate({ left : "-" + ui.value + "px" }, 1000);
			},
			step: itemWidth,
			animate: true
		};
		
		$(_ps).find(".slider").slider(sliderOpts);	
		$(_ps).find(".btn-next").bind('click', function(){
			var curr_value = $(_ps).find(".slider").slider("value");
			$(_ps).find(".slider").slider("value", curr_value + itemWidth);
			return false;
		});
		$(_ps).find(".btn-prev").bind('click', function(){
			var curr_value = $(_ps).find(".slider").slider("value"); 						  
			$(_ps).find(".slider").slider("value", curr_value - itemWidth);
			return false;
		});
	}
};

var price_watcher = {
	init: function(_pw,_remove) {
		$(_pw +' '+_remove).bind('click', function(){
			var pwlink = $(this); price_watcher.remove(_pw,pwlink); return false;
		});
		$(_pw +' a.toggle').bind('click', function(){
			var pwtoggle = $(this); price_watcher.toggle(pwtoggle); return false;
		});
	},
	toggle: function(pwtoggle) {
		$(pwtoggle).next().slideToggle('slow').parent().parent().toggleClass('close');
		if((pwtoggle).parent().parent().hasClass('close')){
			$(pwtoggle).html('+');
		}else{
			$(pwtoggle).html('&ndash;');
		}
	},	
	remove: function(_pw,pwlink) {
		$(pwlink).parent().slideUp('slow');
		var child_count = $(pwlink).parent().parent().children("li:visible").size()-2;
		var status_update = $(pwlink).parent().parent().parent().parent()
			status_update.find('.status').html('You have ('+child_count+') items in your price watcher')
			status_update.find('h3').html('Price watcher ('+child_count+' items)');
		return false;
	}	
};

var site_content = {
	init: function(_pw,_remove) {
		$(_pw +' a.toggle').bind('click', function(){
			var pwtoggle = $(this); site_content.toggle(pwtoggle); return false;
		});
	},
	toggle: function(pwtoggle) {
		if( $('.site-map-inner').is(':visible') ) {
			$('.site-map-inner').hide(); $(pwtoggle).html('+'); return false;
		}else{
			$('.site-map-inner').slideDown('slow'); $(pwtoggle).html('-'); return false;
		};
	}
};

// HTML Truncator for jQuery
// by Henrik Nyh <http://henrik.nyh.se> 2008-02-28.
// Free to modify and redistribute with credit.
(function(d){function g(b,c){b=d(b);var a=b.clone().empty(),e;b.contents().each(function(){var f=c-a.text().length;if(f!=0)(e=this.nodeType==3?h(this,f):g(this,f))&&a.append(e)});return a}function h(b,c){var a=i(b.data);if(j)a=a.replace(/^ /,"");j=!!a.match(/ $/);a=a.slice(0,c);return a=d("<div/>").text(a).html()}function i(b){return b.replace(/\s+/g," ")}function k(b){var c=d(b),a=c.children(":last");if(!a)return b;b=a.css("display");if(!b||b=="inline")return c;return k(a)}function l(b){var c=d(b).children(":last");
if(c&&c.is("p"))return c;return b}var j=true;d.fn.truncate=function(b){var c=d.extend({},d.fn.truncate.defaults,b);d(this).each(function(){if(!(d.trim(i(d(this).text())).length<=c.max_length)){var a=this.nodeType==3?h(this,c.max_length-c.more.length-3):g(this,c.max_length-c.more.length-3),e=d(this).hide();a.insertAfter(e);k(a).append(' <a href="#show more content">'+c.more+"</a>");l(e).append(' <a href="#show less content">'+c.less+"</a>");a.find("a:last").click(function(){a.hide();e.show();return false});
e.find("a:last").click(function(){a.show();e.hide();return false})}})};d.fn.truncate.defaults={max_length:100,more:"&hellip;more",less:"less"}})(jQuery);

// Chararcter limiter
function limitChars(b,a,c){var d=$("#"+b).val(),e=d.length;if(e>a){$("#"+c).html("(You cannot write more than "+a+" characters!)");$("#"+b).val(d.substr(0,a));return false}else{$("#"+c).html("(You have "+(a-e)+" characters left)");return true}};

// jQuery Star Rating Plugin v3.13 - Dual MIT & GPL licenses
// Home : http://www.fyneworks.com/jquery/star-rating/
window.jQuery&&function(a){if(a.browser.msie)try{document.execCommand("BackgroundImageCache",false,true)}catch(m){}a.fn.rating=function(c){if(this.length==0)return this;if(typeof arguments[0]=="string"){if(this.length>1){var d=arguments;return this.each(function(){a.fn.rating.apply(a(this),d)})}a.fn.rating[arguments[0]].apply(this,a.makeArray(arguments).slice(1)||[]);return this}c=a.extend({},a.fn.rating.options,c||{});a.fn.rating.calls++;this.not(".star-rating-applied").addClass("star-rating-applied").each(function(){var b,
e=a(this),k=(this.name||"unnamed-rating").replace(/\[|\]/g,"_").replace(/^\_+|\_+$/g,""),j=a(this.form||document.body),h=j.data("rating");if(!h||h.call!=a.fn.rating.calls)h={count:0,call:a.fn.rating.calls};var g=h[k];if(g)b=g.data("rating");if(g&&b)b.count++;else{b=a.extend({},c||{},(a.metadata?e.metadata():a.meta?e.data():null)||{},{count:0,stars:[],inputs:[]});b.serial=h.count++;g=a('<span class="star-rating-control"/>');e.before(g);g.addClass("rating-to-be-drawn");if(e.attr("disabled"))b.readOnly=
true;g.append(b.cancel=a('<div class="rating-cancel"><a title="'+b.cancel+'">'+b.cancelValue+"</a></div>").mouseover(function(){a(this).rating("drain");a(this).addClass("star-rating-hover")}).mouseout(function(){a(this).rating("draw");a(this).removeClass("star-rating-hover")}).click(function(){a(this).rating("select")}).data("rating",b))}var f=a('<div class="star-rating rater-'+b.serial+'"><a title="'+(this.title||this.value)+'">'+this.value+"</a></div>");g.append(f);this.id&&f.attr("id",this.id);
this.className&&f.addClass(this.className);if(b.half)b.split=2;if(typeof b.split=="number"&&b.split>0){var i=(a.fn.width?f.width():0)||b.starWidth,l=b.count%b.split;i=Math.floor(i/b.split);f.width(i).find("a").css({"margin-left":"-"+l*i+"px"})}b.readOnly?f.addClass("star-rating-readonly"):f.addClass("star-rating-live").mouseover(function(){a(this).rating("fill");a(this).rating("focus")}).mouseout(function(){a(this).rating("draw");a(this).rating("blur")}).click(function(){a(this).rating("select")});
if(this.checked)b.current=f;e.hide();e.change(function(){a(this).rating("select")});f.data("rating.input",e.data("rating.star",f));b.stars[b.stars.length]=f[0];b.inputs[b.inputs.length]=e[0];b.rater=h[k]=g;b.context=j;e.data("rating",b);g.data("rating",b);f.data("rating",b);j.data("rating",h)});a(".rating-to-be-drawn").rating("draw").removeClass("rating-to-be-drawn");return this};a.extend(a.fn.rating,{calls:0,focus:function(){var c=this.data("rating");if(!c)return this;if(!c.focus)return this;var d=
a(this).data("rating.input")||a(this.tagName=="INPUT"?this:null);c.focus&&c.focus.apply(d[0],[d.val(),a("a",d.data("rating.star"))[0]])},blur:function(){var c=this.data("rating");if(!c)return this;if(!c.blur)return this;var d=a(this).data("rating.input")||a(this.tagName=="INPUT"?this:null);c.blur&&c.blur.apply(d[0],[d.val(),a("a",d.data("rating.star"))[0]])},fill:function(){var c=this.data("rating");if(!c)return this;if(!c.readOnly){this.rating("drain");this.prevAll().andSelf().filter(".rater-"+c.serial).addClass("star-rating-hover")}},
drain:function(){var c=this.data("rating");if(!c)return this;c.readOnly||c.rater.children().filter(".rater-"+c.serial).removeClass("star-rating-on").removeClass("star-rating-hover")},draw:function(){var c=this.data("rating");if(!c)return this;this.rating("drain");if(c.current){c.current.data("rating.input").attr("checked","checked");c.current.prevAll().andSelf().filter(".rater-"+c.serial).addClass("star-rating-on")}else a(c.inputs).removeAttr("checked");c.cancel[c.readOnly||c.required?"hide":"show"]();
this.siblings()[c.readOnly?"addClass":"removeClass"]("star-rating-readonly")},select:function(c,d){var b=this.data("rating");if(!b)return this;if(!b.readOnly){b.current=null;if(typeof c!="undefined"){if(typeof c=="number")return a(b.stars[c]).rating("select",undefined,d);typeof c=="string"&&a.each(b.stars,function(){a(this).data("rating.input").val()==c&&a(this).rating("select",undefined,d)})}else b.current=this[0].tagName=="INPUT"?this.data("rating.star"):this.is(".rater-"+b.serial)?this:null;this.data("rating",
b);this.rating("draw");var e=a(b.current?b.current.data("rating.input"):null);if((d||d==undefined)&&b.callback)b.callback.apply(e[0],[e.val(),a("a",b.current)[0]])}},readOnly:function(c,d){var b=this.data("rating");if(!b)return this;b.readOnly=c||c==undefined?true:false;d?a(b.inputs).attr("disabled","disabled"):a(b.inputs).removeAttr("disabled");this.data("rating",b);this.rating("draw")},disable:function(){this.rating("readOnly",true,true)},enable:function(){this.rating("readOnly",false,false)}});
a.fn.rating.options={cancel:"Cancel Rating",cancelValue:"",split:0,starWidth:19};a(function(){a("input[type=radio].star").rating()})}(jQuery);

/**
* hoverIntent r5 // 2007.03.27
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY;};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev]);}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev]);};var handleHover=function(e){var p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob);},cfg.interval);}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob);},cfg.timeout);}}};return this.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

/**
 * jQuery Form Plugin
 * version: 2.43 (12-MAR-2010)
 * @requires jQuery v1.3.2 or later
 * Dual licensed under the MIT and GPL licenses
 */
(function(b){function o(){if(b.fn.ajaxSubmit.debug){var a="[jquery.form] "+Array.prototype.join.call(arguments,"");if(window.console&&window.console.log)window.console.log(a);else window.opera&&window.opera.postError&&window.opera.postError(a)}}b.fn.ajaxSubmit=function(a){function e(){function s(){var q=h.attr("target"),n=h.attr("action");k.setAttribute("target",z);k.getAttribute("method")!="POST"&&k.setAttribute("method","POST");k.getAttribute("action")!=g.url&&k.setAttribute("action",g.url);g.skipEncodingOverride||
h.attr({encoding:"multipart/form-data",enctype:"multipart/form-data"});g.timeout&&setTimeout(function(){C=true;t()},g.timeout);var m=[];try{if(g.extraData)for(var v in g.extraData)m.push(b('<input type="hidden" name="'+v+'" value="'+g.extraData[v]+'" />').appendTo(k)[0]);u.appendTo("body");u.data("form-plugin-onload",t);k.submit()}finally{k.setAttribute("action",n);q?k.setAttribute("target",q):h.removeAttr("target");b(m).remove()}}function t(){if(!D){var q=true;try{if(C)throw"timeout";var n,m;m=w.contentWindow?
w.contentWindow.document:w.contentDocument?w.contentDocument:w.document;var v=g.dataType=="xml"||m.XMLDocument||b.isXMLDoc(m);o("isXml="+v);if(!v&&(m.body==null||m.body.innerHTML=="")){if(--G){o("requeing onLoad callback, DOM not available");setTimeout(t,250);return}o("Could not access iframe DOM after 100 tries.");return}o("response detected");D=true;j.responseText=m.body?m.body.innerHTML:null;j.responseXML=m.XMLDocument?m.XMLDocument:m;j.getResponseHeader=function(H){return{"content-type":g.dataType}[H]};
if(g.dataType=="json"||g.dataType=="script"){var E=m.getElementsByTagName("textarea")[0];if(E)j.responseText=E.value;else{var F=m.getElementsByTagName("pre")[0];if(F)j.responseText=F.innerHTML}}else if(g.dataType=="xml"&&!j.responseXML&&j.responseText!=null)j.responseXML=A(j.responseText);n=b.httpData(j,g.dataType)}catch(B){o("error caught:",B);q=false;j.error=B;b.handleError(g,j,"error",B)}if(q){g.success(n,"success");x&&b.event.trigger("ajaxSuccess",[j,g])}x&&b.event.trigger("ajaxComplete",[j,g]);
x&&!--b.active&&b.event.trigger("ajaxStop");if(g.complete)g.complete(j,q?"success":"error");setTimeout(function(){u.removeData("form-plugin-onload");u.remove();j.responseXML=null},100)}}function A(q,n){if(window.ActiveXObject){n=new ActiveXObject("Microsoft.XMLDOM");n.async="false";n.loadXML(q)}else n=(new DOMParser).parseFromString(q,"text/xml");return n&&n.documentElement&&n.documentElement.tagName!="parsererror"?n:null}var k=h[0];if(b(":input[name=submit]",k).length)alert('Error: Form elements must not be named "submit".');
else{var g=b.extend({},b.ajaxSettings,a),r=b.extend(true,{},b.extend(true,{},b.ajaxSettings),g),z="jqFormIO"+(new Date).getTime(),u=b('<iframe id="'+z+'" name="'+z+'" src="'+g.iframeSrc+'" onload="(jQuery(this).data(\'form-plugin-onload\'))()" />'),w=u[0];u.css({position:"absolute",top:"-1000px",left:"-1000px"});var j={aborted:0,responseText:null,responseXML:null,status:0,statusText:"n/a",getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){},abort:function(){this.aborted=
1;u.attr("src",g.iframeSrc)}},x=g.global;x&&!b.active++&&b.event.trigger("ajaxStart");x&&b.event.trigger("ajaxSend",[j,g]);if(r.beforeSend&&r.beforeSend(j,r)===false)r.global&&b.active--;else if(!j.aborted){var D=false,C=0;if(r=k.clk){var y=r.name;if(y&&!r.disabled){g.extraData=g.extraData||{};g.extraData[y]=r.value;if(r.type=="image"){g.extraData[y+".x"]=k.clk_x;g.extraData[y+".y"]=k.clk_y}}}g.forceSync?s():setTimeout(s,10);var G=100}}}if(!this.length){o("ajaxSubmit: skipping submit process - no element selected");
return this}if(typeof a=="function")a={success:a};var c=b.trim(this.attr("action"));if(c)c=(c.match(/^([^#]+)/)||[])[1];c=c||window.location.href||"";a=b.extend({url:c,type:this.attr("method")||"GET",iframeSrc:/^https/i.test(window.location.href||"")?"javascript:false":"about:blank"},a||{});c={};this.trigger("form-pre-serialize",[this,a,c]);if(c.veto){o("ajaxSubmit: submit vetoed via form-pre-serialize trigger");return this}if(a.beforeSerialize&&a.beforeSerialize(this,a)===false){o("ajaxSubmit: submit aborted via beforeSerialize callback");
return this}var f=this.formToArray(a.semantic);if(a.data){a.extraData=a.data;for(var d in a.data)if(a.data[d]instanceof Array)for(var l in a.data[d])f.push({name:d,value:a.data[d][l]});else f.push({name:d,value:a.data[d]})}if(a.beforeSubmit&&a.beforeSubmit(f,this,a)===false){o("ajaxSubmit: submit aborted via beforeSubmit callback");return this}this.trigger("form-submit-validate",[f,this,a,c]);if(c.veto){o("ajaxSubmit: submit vetoed via form-submit-validate trigger");return this}d=b.param(f);if(a.type.toUpperCase()==
"GET"){a.url+=(a.url.indexOf("?")>=0?"&":"?")+d;a.data=null}else a.data=d;var h=this,i=[];a.resetForm&&i.push(function(){h.resetForm()});a.clearForm&&i.push(function(){h.clearForm()});if(!a.dataType&&a.target){var p=a.success||function(){};i.push(function(s){var t=a.replaceTarget?"replaceWith":"html";b(a.target)[t](s).each(p,arguments)})}else a.success&&i.push(a.success);a.success=function(s,t,A){for(var k=0,g=i.length;k<g;k++)i[k].apply(a,[s,t,A||h,h])};d=b("input:file",this).fieldValue();l=false;
for(c=0;c<d.length;c++)if(d[c])l=true;if(d.length&&a.iframe!==false||a.iframe||l||0)a.closeKeepAlive?b.get(a.closeKeepAlive,e):e();else b.ajax(a);this.trigger("form-submit-notify",[this,a]);return this};b.fn.ajaxForm=function(a){return this.ajaxFormUnbind().bind("submit.form-plugin",function(e){e.preventDefault();b(this).ajaxSubmit(a)}).bind("click.form-plugin",function(e){var c=e.target,f=b(c);if(!f.is(":submit,input:image")){c=f.closest(":submit");if(c.length==0)return;c=c[0]}var d=this;d.clk=c;
if(c.type=="image")if(e.offsetX!=undefined){d.clk_x=e.offsetX;d.clk_y=e.offsetY}else if(typeof b.fn.offset=="function"){f=f.offset();d.clk_x=e.pageX-f.left;d.clk_y=e.pageY-f.top}else{d.clk_x=e.pageX-c.offsetLeft;d.clk_y=e.pageY-c.offsetTop}setTimeout(function(){d.clk=d.clk_x=d.clk_y=null},100)})};b.fn.ajaxFormUnbind=function(){return this.unbind("submit.form-plugin click.form-plugin")};b.fn.formToArray=function(a){var e=[];if(this.length==0)return e;var c=this[0],f=a?c.getElementsByTagName("*"):c.elements;
if(!f)return e;for(var d=0,l=f.length;d<l;d++){var h=f[d],i=h.name;if(i)if(a&&c.clk&&h.type=="image"){if(!h.disabled&&c.clk==h){e.push({name:i,value:b(h).val()});e.push({name:i+".x",value:c.clk_x},{name:i+".y",value:c.clk_y})}}else if((h=b.fieldValue(h,true))&&h.constructor==Array)for(var p=0,s=h.length;p<s;p++)e.push({name:i,value:h[p]});else h!==null&&typeof h!="undefined"&&e.push({name:i,value:h})}if(!a&&c.clk){a=b(c.clk);f=a[0];if((i=f.name)&&!f.disabled&&f.type=="image"){e.push({name:i,value:a.val()});
e.push({name:i+".x",value:c.clk_x},{name:i+".y",value:c.clk_y})}}return e};b.fn.formSerialize=function(a){return b.param(this.formToArray(a))};b.fn.fieldSerialize=function(a){var e=[];this.each(function(){var c=this.name;if(c){var f=b.fieldValue(this,a);if(f&&f.constructor==Array)for(var d=0,l=f.length;d<l;d++)e.push({name:c,value:f[d]});else f!==null&&typeof f!="undefined"&&e.push({name:this.name,value:f})}});return b.param(e)};b.fn.fieldValue=function(a){for(var e=[],c=0,f=this.length;c<f;c++){var d=
b.fieldValue(this[c],a);d===null||typeof d=="undefined"||d.constructor==Array&&!d.length||(d.constructor==Array?b.merge(e,d):e.push(d))}return e};b.fieldValue=function(a,e){var c=a.name,f=a.type,d=a.tagName.toLowerCase();if(typeof e=="undefined")e=true;if(e&&(!c||a.disabled||f=="reset"||f=="button"||(f=="checkbox"||f=="radio")&&!a.checked||(f=="submit"||f=="image")&&a.form&&a.form.clk!=a||d=="select"&&a.selectedIndex==-1))return null;if(d=="select"){var l=a.selectedIndex;if(l<0)return null;c=[];d=
a.options;var h=(f=f=="select-one")?l+1:d.length;for(l=f?l:0;l<h;l++){var i=d[l];if(i.selected){var p=i.value;p||(p=i.attributes&&i.attributes.value&&!i.attributes.value.specified?i.text:i.value);if(f)return p;c.push(p)}}return c}return a.value};b.fn.clearForm=function(){return this.each(function(){b("input,select,textarea",this).clearFields()})};b.fn.clearFields=b.fn.clearInputs=function(){return this.each(function(){var a=this.type,e=this.tagName.toLowerCase();if(a=="text"||a=="password"||e=="textarea")this.value=
"";else if(a=="checkbox"||a=="radio")this.checked=false;else if(e=="select")this.selectedIndex=-1})};b.fn.resetForm=function(){return this.each(function(){if(typeof this.reset=="function"||typeof this.reset=="object"&&!this.reset.nodeType)this.reset()})};b.fn.enable=function(a){if(a==undefined)a=true;return this.each(function(){this.disabled=!a})};b.fn.selected=function(a){if(a==undefined)a=true;return this.each(function(){var e=this.type;if(e=="checkbox"||e=="radio")this.checked=a;else if(this.tagName.toLowerCase()==
"option"){e=b(this).parent("select");a&&e[0]&&e[0].type=="select-one"&&e.find("option").selected(false);this.selected=a}})}})(jQuery);

/* Easy Slider 1.7 - jQuery plugin - by Alen Grakalic - Modified by ced
 * http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
 */
(function(b){b.fn.easySlider=function(a){a=b.extend({prevId:"prevBtn",prevText:"Previous",nextId:"nextBtn",nextText:"Next",controlsShow:true,controlsBefore:"",controlsAfter:"",controlsFade:true,firstId:"firstBtn",firstText:"First",firstShow:false,lastId:"lastBtn",lastText:"Last",lastShow:false,vertical:false,speed:800,auto:false,pause:2E3,continuous:false,numeric:false,numericId:"controls",hoverPause:false},a);this.each(function(){function q(g){g=parseInt(g)+1;b("li","#"+a.numericId).removeClass("current");
b("li#"+a.numericId+g).addClass("current")}function l(){if(c>i)c=0;if(c<0)c=i;a.vertical?b("ul",d).css("margin-left",c*m*-1):b("ul",d).css("margin-left",c*h*-1);n=true;a.numeric&&q(c)}function f(g,r){if(n){n=false;var j=c;switch(g){case "next":c=j>=i?a.continuous?c+1:i:c+1;break;case "prev":c=c<=0?a.continuous?c-1:0:c-1;break;case "first":c=0;break;case "last":c=i;break;case "stop":c=c;break;default:c=g}j=Math.abs(j-c);var s=j*a.speed;if(g=="last"){p=c*h*-1;b("ul",d).animate({marginLeft:p},{queue:false,
duration:50,complete:l})}else if(a.vertical){p=c*m*-1;b("ul",d).animate({marginTop:p},{queue:false,duration:s,complete:l})}else{p=c*h*-1;b("ul",d).animate({marginLeft:p},{queue:false,duration:s,complete:l})}if(!a.continuous&&a.controlsFade){if(c==i){b("a","#"+a.nextId).hide();b("a","#"+a.lastId).hide()}else{b("a","#"+a.nextId).show();b("a","#"+a.lastId).show()}if(c==0){b("a","#"+a.prevId).hide();b("a","#"+a.firstId).hide()}else{b("a","#"+a.prevId).show();b("a","#"+a.firstId).show()}}r&&clearTimeout(o);
if(a.auto&&g=="next"&&!r)o=setTimeout(function(){f("next",false)},j*a.speed+a.pause)}}var d=b(this),k=b("li",d).length,h=b("li",d).width(),m=b("li",d).height(),n=true;d.width(h);d.height(m);d.css("overflow","hidden");var i=k-1,c=0;b("ul",d).css("width",k*h);if(a.continuous){b("ul",d).prepend(b("ul li:last-child",d).clone().css("margin-left","-"+h+"px"));b("ul",d).append(b("ul li:nth-child(2)",d).clone());b("ul",d).css("width",(k+1)*h)}a.vertical||b("li",d).css("float","left");if(a.controlsShow){var e=
a.controlsBefore;if(a.numeric)e+='<ol id="'+a.numericId+'"></ol>';else{if(a.firstShow)e+='<span id="'+a.firstId+'"><a href="javascript:void(0);">'+a.firstText+"</a></span>";e+=' <span id="'+a.prevId+'"><a href="#">'+a.prevText+"</a></span>";e+=' <span id="'+a.nextId+'"><a href="#">'+a.nextText+"</a></span>";if(a.lastShow)e+=' <span id="'+a.lastId+'"><a href="#">'+a.lastText+"</a></span>"}e+=a.controlsAfter;b(d).after(e)}if(a.numeric)for(e=0;e<k;e++)b(document.createElement("li")).attr("id",a.numericId+
(e+1)).html("<a rel="+e+' href="#">'+(e+1)+"</a>").appendTo(b("#"+a.numericId)).click(function(){f(b("a",b(this)).attr("rel"),true);return false});else{b("a","#"+a.nextId).click(function(){f("next",true);return false});b("a","#"+a.prevId).click(function(){f("prev",true);return false});b("a","#"+a.firstId).click(function(){f("first",true);return false});b("a","."+a.lastId).click(function(){f("last",true);return false})}if(a.hoverPause===true){b("#slider").mouseenter(function(){f("stop",true)});b("#slider").mouseleave(function(){f("next",
true)})}var o;if(a.auto)o=setTimeout(function(){f("next",false)},a.pause);a.numeric&&q(0);if(!a.continuous&&a.controlsFade){b("a","#"+a.prevId).hide();b("a","#"+a.firstId).hide()}})}})(jQuery);

