$(document).ready(function(){ 

	/*
	$("input[type=file].funky").filestyle({ 
		image: "images/file_button.gif",
		imageheight : 22,
		imagewidth : 108,
		width : 192
	});
	*/
		
	// textbox/textarea toggle title
	$("input:text, textarea, input:password").each(function(){
        if(this.value == '')
            this.value = this.title;
    });
    $("input:text, textarea, input:password").focus(function(){
        if(this.value == this.title)
            this.value = '';
    });
    $("input:text, textarea, input:password").blur(function(){
        if(this.value == '')
            this.value = this.title;
    });
    $("input:image, input:button, input:submit").click(function(){
        $(this.form.elements).each(function(){
            if(this.type =='text' || this.type =='textarea' || this.type =='password' ){
                if(this.value == this.title && this.title != ''){
                    this.value='';
                }
            }
        });
    });
	//

	// Scroll Position
 	getScrollPos = function() {
	var docElem = document.documentElement;
	this.scrollX = self.pageXOffset || (docElem&&docElem.scrollLeft) || document.body.scrollLeft;
	this.scrollY = self.pageYOffset || (docElem&&docElem.scrollTop) || document.body.scrollTop;
	}
	//
	
	// basket box load - reload
	//$("div#box_basket div.box_main").load("basket_box.php"); // load basket
	$("#basket_top").load("basket_top.php"); // load basket top
	var reloadBasket = function() {
		//$("div#box_basket div.box_main").load("basket_box.php");
		$("#basket_top").load("basket_top.php");
	};
	// 

	// popupbox	
	
	
	$("a[rel='popupbox']").click(function() { 
		var scrollPos = new getScrollPos();
		var popupboxheight = scrollPos.scrollY+320+'px';
		$("div#popupbox .body").load($(this).attr('href'));
		//$("div#popupbox").css({display:"block", top:popupboxheight});
		$("div#popupbox").css({top:popupboxheight});
		$("div#popupbox").fadeIn();
		window.setTimeout(reloadBasket,1000);
		window.setTimeout(hidePopup,4000);
		return false;
	});
	
	$("a[rel='popupbox_options']").click(function() { 	
		var option_string = '';
		$("input.option:checked").each(function(i){
			var option_id = $(this).attr('rel');								
			var option_value_id = $(this).val();
			option_string = option_string + '|' + option_id + ',' + option_value_id;
		});												   
		//alert(option_string);									  

		if (option_string) {
												 
			var scrollPos = new getScrollPos();
			var popupboxheight = scrollPos.scrollY+320+'px';
			$("div#popupbox .body").load($(this).attr('href') + '&option_string=' + option_string);
			$("div#popupbox").css({display:"block", top:popupboxheight});
			$("div#popupbox").css({top:popupboxheight});
			$("div#popupbox").fadeIn();
			window.setTimeout(reloadBasket,1000);
			window.setTimeout(hidePopup,4000);
		
		} 
		return false;
	});
	
	var hidePopup = function() {
		$('div#popupbox').fadeOut();
	};
	
	$(".close_popupbox").click(function(){
		hidePopup();
	});
	//
	
	// secure form
	$('.js_warning').remove();
	$.get("includes/safeform/token.php",function(txt){
  		$(".safeform").append('<input type="hidden" name="ts" value="'+txt+'" />');
	});
	//
		
	// admin .input fields change on focus
	$(".input").focus(function() {
	$(this).addClass("input_focus")
	});
	$(".input").blur(function() {
		$(this).removeClass("input_focus")
	});
	//
	
	// 
	$("table.striped tr").mouseover( function() {
		$(this).addClass('table_over');
	}).mouseout( function() {
		$(this).removeClass('table_over');
	});

	$(".basket_button").mouseover( function() {
		$(this).addClass('basket_button_over');
	}).mouseout( function() {
		$(this).removeClass('basket_button_over');
	});

	
});

