
	/* Browser Sniff */
	var bBugBrowser = false;
	var bEnableStyle = true;
	var agt=navigator.userAgent.toLowerCase();
	var is_safari = (agt.indexOf("safari") >= 0 && agt.indexOf('chrome') <= 0);
        var full;
	var offer;
	
	if(is_safari) {
		document.write("<link href='styles/safari.css' rel='stylesheet' type='text/css'>");
	}

	function checkAll(frm) {
		if (inputs = document.getElementsByTagName('input')) {
			var check = false;
			if (document.getElementById('bookCover').checked == true) {
				check = true;
			}
			
			if (!inputs.length) {
				if (inputs.getAttribute('type') == "checkbox") {
					inputs.checked = check;
				}
			} else {
				for (i = 0; i < inputs.length; i++) {
					if (inputs[i].getAttribute('type') == "checkbox") {
						inputs[i].checked = check;
					}
				}
			}
		}
		
		if (frm != ''){
			var d = document.getElementById(frm);
			if (d != null){
				d.submit();
			}
		}
	}

        function validateSearch(){
				var d = document.getElementById('frmTopSearch');
				if (d != null){
					if (d.keyword.value.length < 3){
						alert("You must enter a minimum of 3 letters!");
						d.keyword.focus();
						return false;
					}
				}
				
				return true;
			}

        /*
         * JQuery stuff
         */
        $(document).ready(function() {
                        $.fn.accordion = function (s) {
				var s = $.extend({
					start:false
				}, s);

				function initialize (el) {
					if (s.start) {
						var arr = $('#'+s.start).parents('ul').css('display', 'block');
					}

					$(el).find('li a:not(:only-child)').bind('click', function() {
						$(this).parent().find('ul:first').slideToggle().removeClass('closed').addClass('open');
						return false;
					});

					$(el).find('ul').css({
						'display' : 'none'
					})
				}

				initialize(this);
			}


				   $('#leftNav').accordion();



                        update_cart_count = function() {
                               $.get("/cartActions.php", {action:'count_cart'},
                                        function(data) {
                                            $('#cartContainItems').html(data.cartcount);
                                        }, 'json');
                           }
                           
                           get_url_vars = function(url)
                            {
                                
                                var vars = [], hash;
                                var hashes = url.slice(url.indexOf('?') + 1).split('&');
                                for(var i = 0; i < hashes.length; i++)
                                {
                                    hash = hashes[i].split('=');
                                    vars.push(hash[0]);
                                    vars[hash[0]] = hash[1];
                                }
                                return vars;
                            }

                        addToCart = function() {
                            // add the quickcode to the form
                           quickcode = get_url_vars($('.buyBtn')[1].href)['quickcode'];
                           
                           // add this as a hidden element
                           var $hiddenInput = $('<input/>',{type:'hidden',name:'quickcode',value:quickcode});
                           $('#frmSchoolList').append($hiddenInput);
                           
                           $.post("/cartActions.php", $("#frmSchoolList").serialize(),
                           function() {
                               $("#dialog").load('/batch-cart-message.html');
                               $("#dialog").dialog({modal: true, width: 500,
                                        height: 250,
                                        buttons: {Ok: function() {$(this).dialog('close');}
                                        }
                                });
                           });
                           update_cart_count();
                            
                          
                            return false;
                        }

                        // add action on cart add buttons
                        $('li.btnProdAdd a').bind('click', function() {
                        $('body').css('cursor','wait');  
                          $.get($(this).attr('href'), function() {
                             $("#dialog").html('<h1>Item added to cart</h1><p>You have added a product to your cart.</p>');
                              $("#dialog").dialog({
                                        modal: true,
                                        buttons: {
                                                'Go To Cart': function() {window.location = '/cart.php';},
                                                 Ok: function() {$(this).dialog('close');}
                                        }
                                });
                                $('body').css('cursor','auto');
                          });
                          update_cart_count();
                          return false;
                        });

                        $('#btnAddAllTop').bind('click', addToCart);
                        $('#btnAddAll').bind('click', addToCart);


                        // buy buttons on school list
                        $('a.buyBtn').bind('click', function(event){
                            var $$, href, text;

                            $$ = $(event.target);
                            href = $$.attr('href');
                            text = $$.text();

                            $$.attr('href', href += '&qty='
                                + $("#qty_" + text).val()
                                + '&sh=' + $("#new_sh_" + text).val());
                        });

                        $("#sSearch").autocomplete({
                            source: "/autocomplete.php",
                            minLength: 2
                        });

                        $('.pics').cycle({
                                    fx:    'fade', 
                                    speed:  2500
                               });

                        //show offer window
                        $('#showoffer').click(function(event){

                            $('#offer').modal();
                            return false;
                            
                        });

                        //hide offer window
                        $('#hideoffer').click(function(event){

                            $('#offer').hide();

                        });
                        
						$('#refreshCaptcha').click(function(){
							var imgSrc = '/securimage/securimage_show.php?' + Math.random();
									$('#captcha').attr('src', imgSrc);
						});
						
});

