/**
 * mammoetskelters.js
 *
 * @version 1.0
 * @package mammoetskelters.com
 * @author  A.J. de Vries
 *
 * Copyright (c) Malibomba
 * IT IS NOT ALLOWED TO USE OR MODIFY ANYTHING OF
 * THIS CODE, WITHOUT THE PERMISION OF THE AUTHOR.
 * Info? Mail to info@malibomba.com
 */
//<![CDATA[

/**
 * DOCUMENT READY:
 --------------------------------------------------------------------------------------------------*/
$(document).ready(function() {
	/*$.viewMap = ({'Northern Ireland' : $('#view1')});
		$('#country').change(function() {
			// hide all
			$.each($.viewMap, function() { this.hide(); });
			// show current
			$.viewMap[$(this).val()].show();
	}); */


	$(".scroll").click(function(event){
		//prevent the default action for the click event
		event.preventDefault();

		//get the full url - like mysitecom/index.htm#home
		var full_url = this.href;

		//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var parts = full_url.split("#");
		var trgt = parts[1];

		//get the top offset of the target anchor
		var target_offset = $("#"+trgt).offset();
		var target_top = target_offset.top;

		//goto that anchor by setting the body scroll top to anchor top
		$('html, body').animate({scrollTop:target_top}, 900);
	});


	/**
	 * lc map round corners:
	 ----------------------------------------------------------------------------------------------*/
    $(".move_tab").click(function(){
      $("#lc-tab").animate({"left": "350px"}, 300);
      $("#lc-tab").animate({"left": "724px"}, 400);
    });

	/**
	 * BROWSER DETECTION:
	 ----------------------------------------------------------------------------------------------*/
	var msg = '';
	for( var i in $.browser ) {
		if( i != 'browser' && i != 'OS' && 
			i != 'version' && i != 'linux' && i != 'mac' && i != 'win' ) {
			if( $.browser[i]() == true ) {
				$('body').addClass(i);
				$('body').addClass('v' + $.browser.version.number());
			}
		}
	}

	/**
	 * ENABLE FORM/BUTTONS:
	 ----------------------------------------------------------------------------------------------*/
	$('.btn').attr( {disabled:false} );

	/**
	 * CATEGORY NAVIGATION:
	 ----------------------------------------------------------------------------------------------*/
	var categories = null;
	if( (categories = $('#lc-east-nav ul li a')).length > 0 )  {

		categories.each( function(i) {

			var anchor = this;
			$(anchor).click( function(e) {
				e.preventDefault();
				if( /^c[0-9]+$/i.test(this.rel) ) {
					var c = this.rel.replace(/^c/gi, '');
					if( parseInt(c) > 0 ) {

						$.ajax( {
							type: 'POST',
							cache: false,
							data: {'c': c},
							url: '/ajax/fetchproductsbycategory.json.php',
							success:function( response ) {
								if( response !== '' &&
									(json= eval("(" + response + ')')) !== undefined ) {

									var html = [];
									for( var i in json ) {
										var p = json[i];

										var thumbnail = (p['images'].length > 0) ? p['images'][0].thumbnail : '/pics/pixel.gif';
										html.push('<div class="lc-tab-product">' + 
													'<div class="productitem">' + 
														'<a href="' + p.uri + '" title="' + p.title + '">' + 
															'<img src="/pics/pixel.gif" alt="' + p.title + '" width="100" height="80" style="background: url(' + thumbnail + ') center center no-repeat;" />' + 
														'</a>' + 
														'<div class="lc-tab-text">' + 
														'<a href="' + p.uri + '" title="' + p.title + '">' + 
															'<strong>' + p.title + '</strong>' + 
														'</a><br />' + p.currency + ' '+ p.price +
														'</div>' + 
												'</div>' + 
											'</div>')
									}
								}
								

								setTimeout( function() {
									$('#lc-tab-top h4').html('<a href="' + anchor.href + '">' + anchor.title + '</a>');
									$('#lc-tab-content').html(html.join(''));
									__initProductLinks();
								}, 400);


								categories.parent().removeClass('active');
								$(anchor).parent().addClass('active');

							}
						} );

					}
				}

			} ); // End of Click;

		} ); // End of each;
		__initProductLinks();

	}



} ); // End document Ready


/**
 * HELPERS / UTILITIES:
 --------------------------------------------------------------------------------------------------*/
function __initProductLinks() {
	var products = $('.lc-tab-product');
	products.click( function(e) {
		e.preventDefault();
		if( (a = $('a:eq(0)', $(this))).length == 1) {
			document.location.href = a.attr('href');
		}
	} );
}

/**
 * SIFR:
 ----------------------------------------------------------------------------------------------*/
var prototype = { src: "/flash/prototype.swf" };
sIFR.activate(prototype);
sIFR.replace(prototype, {
	selector: "#lc-content h1",
	css: [
		'.sIFR-root { font-weight:normal; color:#2580a2; font-size:25px; }',
		'a { text-decoration:none; color:#2580a2; }',
		'a:hover { color:#1d5cd1; }'
	],
	wmode: "transparent"
});

sIFR.replace(prototype, {
	selector: "h1",
	css: [
		'.sIFR-root { font-weight:normal; color:#aa0000; font-size:18px; }',
		'a { text-decoration:none; color:#2580a2; }',
		'a:hover { color:#1d5cd1; }'
	],
	wmode: "transparent"
});

//sIFR.replace(prototype, {
//	selector: "h2",
//	css: [
//		//'.sIFR-root { font-weight:normal; color:#c70101; }',
//		'.sIFR-root { font-weight:normal; color:#2580a2; }',
//		'a { text-decoration:none; color:#c70101; }',
//		'a:hover { color:#1d5cd1; }'
//	],
//	wmode: "transparent"
//});

sIFR.replace(prototype, {
	//selector: ".aoptions, .acolors",
	selector: ".sifr",
	css: [
		//'.sIFR-root { font-weight:normal; color:#c70101; }',
		'.sIFR-root { font-weight:normal; color:#2580a2; }',
		'a { text-decoration:none; color:#c70101; }',
		'a:hover { color:#1d5cd1; }'
	],
	wmode: "transparent"
});

sIFR.replace(prototype, {
	selector: ".price",
	css: [
		'.sIFR-root { font-weight:normal; color:#ffffff; text-align: center; }',
		'a { text-decoration:none; color:#c70101; }',
		'a:hover { color:#1d5cd1; }'
	],
	wmode: "transparent"
});


/**
 * Slide Vieuwer for product page:
 ----------------------------------------------------------------------------------------------
$(window).bind("load", function() {
 $("div#productslider").slideView()  
});*/


$(window).bind("load", function() {
	$("div#slideViewer").slideViewerPro({
		autoslide: true,
		asTimer: 3500,
		galBorderWidth: 0,
		thumbsVis: false
	}); 
});


/**
 * HELPER FUNCTIONS:
 --------------------------------------------------------------------------------------------------*/
function word() {
	var re;
	var args = arguments;	
	var word = words[args[0]];	
	for(var x = 1; x < args.length; x++) {
		re = new RegExp('#' + x);
		word = word.replace(re, args[x]);
	}
	return word;
}

function number_format( number, decimals, dec_point, thousands_sep ) {
    // Formats a number with grouped thousands
    //
    // version: 906.1806
    // discuss at: http://phpjs.org/functions/number_format
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival
    // +     input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +     improved by: davook
    // +     improved by: Brett Zamir (http://brett-zamir.me)
    // +     input by: Jay Klehr
    // +     improved by: Brett Zamir (http://brett-zamir.me)
    // +     input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');
    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'
    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);
    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'
    // *     example 10: number_format('1.20', 2);
    // *     returns 10: '1.20'
    // *     example 11: number_format('1.20', 4);
    // *     returns 11: '1.2000'
    // *     example 12: number_format('1.2000', 3);
    // *     returns 12: '1.200'
    var n = number, prec = decimals;
 
    var toFixedFix = function (n,prec) {
        var k = Math.pow(10,prec);
        return (Math.round(n*k)/k).toString();
    };
 
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
    var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
 
    var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
 
    var abs = toFixedFix(Math.abs(n), prec);
    var _, i;
 
    if (abs >= 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;
 
        _[0] = s.slice(0,i + (n < 0)) +
              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
        s = _.join(dec);
    } else {
        s = s.replace('.', dec);
    }
 
    var decPos = s.indexOf(dec);
    if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) {
        s += new Array(prec-(s.length-decPos-1)).join(0)+'0';
    }
    else if (prec >= 1 && decPos === -1) {
        s += dec+new Array(prec).join(0)+'0';
    }
    return s;
}





//]]>