//jQuery.noConflict();
jQuery(document).ready(function($){
//jQuery(function(){ 
	//display text if item has Special Instructions textarea box
	if ( $('.productTextarea').length > 0 ) {
		$('#load').load("/place-order.txt");
	} 
	
	$('.add_cart').click( function() {
		//if ( $('.productTextarea').length > 0 ) {
			//$('#load').load("/place-order.txt");
		//}
		location.reload();
	});
	
	
	//view cart positioning
	if ( $("table.viewProducts").length > 0 ) {
		$('#container #rightCol').css('position', 'absolute').css('right', '0px').css('bottom', '0px');
	}
	else if ( $("div.item_v").length > 0 ) {
		$('#container #rightCol').remove('position', 'absolute').remove('right', '0px').remove('bottom', '0px');
	}
	else {
		$('#container #rightCol').css('position', 'absolute').css('right', '0px').css('bottom', '0px');
	}
	
	//shopping cart
	if ( $("span:contains('quote')").length > 0 ) {
		$('#catshopquote').css('visibility','visible');
		$('#catshopbuy').css('display','none').css('visibility','hidden');
		//$('.shippingDiv').css('display','none').css('visibility','hidden');
		$('img#sendOrder').removeAttr('onclick');
		$('span#shipOpt').css('display','none').css('visibility','hidden');
	} 
	else if ( $("span:contains('buy')").length > 0 ) {
		$('#catshopbuy').css('visibility','visible');
		//$('.shippingDiv').css('visibility','visible');
		$('#catshopquote').css('display','none').css('visibility','hidden');
		$('span#shipOpt').css('visibility','visible');
	} 
	else if ( $("span:contains('both')").length > 0 ) {
		$('#catshopbuy').css('visibility','visible');
		$('#catshopquote').css('visibility','visible');
		//$('.shippingDiv').css('visibility','visible');
		$('span#shipOpt').css('visibility','visible');
	}
	else {
		$('#catshopbuy').css('visibility','visible');
		$('#catshopquote').css('visibility','visible');
		//$('.shippingDiv').css('visibility','visible');
		$('span#shipOpt').css('visibility','visible');
	}

	//quote workflow option
	if ( $("span:contains('djj')").length > 0 ) {
		$('span#gst').text('GST exclusive');

	} 
	else {
		$('span#gst').text('10% GST inclusive');
	}

	//quote workflow option
	//if ( $("span:contains('djj')").length > 0 ) {
	//	var checkout = $("#catshopquote");
	//	var hyp = checkout.attr("href");
	//	checkout.attr("href", hyp + "&workflow=14200");
	//} 


	$('td.remove a').click( function() {
		location.reload();
	});

	$('select.shippingDropDown').change( function() {
		location.reload();
	});

	$("input.cartInputText").change( function() {
		location.reload();					 
	});

	//add Selected classes to menu and submenu items
	var partnerpath = location.href.substring(location.href.lastIndexOf('/')+1);//+location.hash;
	if ( partnerpath )
		//$('#buttons a[href$="' + partnerpath + '"]').addClass('selected').parents('ul').css('display','block');
		$('#buttons a[href$="' + partnerpath + '"]').parent().addClass('selected').parent().css('display','block').parent().addClass('selected');		
	
    //var path = location.pathname.substring(1).replace('.aspx', '').split('/');
    //if (path[path.length - 2] != '') {
    //    var immediateFolder = path[path.length - 2];
    //    var fileName = path[path.length - 1];
    //    var s = $('#buttons li[data-location="' + immediateFolder + '"]').length;
    //    if (s > 0) {
    //        $('#buttons li[data-location="' + immediateFolder + '"]').addClass('selected');
    //    }
        //else {
        //    switch (fileName.toLowerCase()) {
        //        case 'breads':
        //        case 'shopping':
        //        case 'checkout':
        //        case 'buyonline':
        //        case 'myaccount':
        //        case 'myorders':
        //        case 'vieworders':
        //            $('#buttons li[data-location=home]').addClass('selected');
        //            break;
        //    }
        //}
    //}
//	});

	//Remove GST note if all the items are "GOV" items.
	//var url = location.href;
	//if(url.indexOf("status=test") > -1){
		var gstProducts = true;
		var itemTitle;
		$('.type > .productitemcell').each(function(index){
			if(gstProducts == true){
				itemTitle = $(this).text();
				itemTitle = itemTitle.substring(0, 3);
				if(itemTitle == "GOV" || itemTitle == "DJJ"){
					gstProducts = false;
				}
			}
		});
		if(gstProducts == false){
			$('.gstNote').html("*Please note that all prices displayed are GST exclusive.");
		}
	//}
	
});

