$(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
	$("#lightbox_top").load("lightbox_top.php");
	var reloadBasket = function() {
		//$("div#box_basket div.box_main").load("basket_box.php");
		$("#basket_top").load("basket_top.php");
		$("#lightbox_top").load("lightbox_top.php");
	};
	// 


	// popupbox	
	var hidePopup = function() {
		$('div#popupbox').fadeOut();
	};
	
	$("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_price']").click(function() { 
		//var price_id = 0;		
		var price_id = $("input[@name=price_option]:checked").val(); 
		if (price_id > 0) {
												 
			var scrollPos = new getScrollPos();
			var popupboxheight = scrollPos.scrollY+320+'px';
			$("div#popupbox .body").load($(this).attr('href') + '&price=' + price_id);
			//$("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;
	});
	
	$(".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+'" />');
	});
	//
	
	
	// .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');
	});
	
	
	
	$(".photo_item").mouseover( function() {
		$(this).addClass('photo_item_over');
	}).mouseout( function() {
		$(this).removeClass('photo_item_over');
	});
	
	
	$(".basket_button").mouseover( function() {
		$(this).addClass('basket_button_over');
	}).mouseout( function() {
		$(this).removeClass('basket_button_over');
	});

	
	
});


