var interval;
$(function(){


	$('#reseller_form_t').hide();
	$('#reseller_form').submit(function(){
		$('#reseller_form_t').text("Processing...").fadeIn();

			expVals="";
			$('#reseller_form_t').text("Getting Data...").fadeIn();
			$('#reseller_form input[type="text"]').each(function(){expVals=expVals+$(this).val()+"SPACEITOUTNOW";});
			$('#reseller_form textarea').each(function(){expVals=expVals+$(this).val()+"SPACEITOUTNOW";});
			$('#reseller_form select').each(function(){expVals=expVals+$(this).val()+"SPACEITOUTNOW";});
			$('#reseller_form_t').text("Sending Mail...").fadeIn();
			
			$.post("/media/scripts/php/sendmail.php",{
				vals:expVals
			},function(data){
				$('#reseller_form_t').text(data).fadeIn();
			});
        return false;	
	});

	if($('#promotion').length>0){
	$(window).bind("resize",function(){
		$('.pgecontainer').pgeConCen();					   
	});
	$(window).bind("load",function(){
			$('#promotion').PgeMask(function(){
			$('.pgecontainer img, .pgewrapper .pgemask').click(function(){
				$(this).PgeUnloadmask();					
			});				
		});
	});
	}


	$('#baf_return').hide();
	$('#baf').submit(function(){
		chkeml = $('#baf_eml').checkEmail();
		if(chkeml)
		{
			$.post("plugs/baf/process.php",{
				emailadd:$('#baf_eml').val()
			},function(data){
				$('#baf_return').html(data).fadeIn();
				$('#baf_eml').val("");
			});
		}
		else
		{
			$('#baf_return').html("Please enter a valid email address.").fadeIn();
		}
		return false;
	});

	//news switcher
	var ns = {
		change: $('#newswrap div'),
		clicker: $('#nswitcher a'),
		duration: 500,
		queue:false,
		offstage: -300,
		onstage: 0
	};
	
	//
	ns.change
	.css({left: ns.offstage})
	.eq(0)
	.css({left: ns.onstage})

	ns.clicker
	.eq(0)
	.addClass('cur');


	//on click
	ns.clicker
	.bind('click',function(){
		clearInterval(interval);
		ti=ns.clicker.index(this);

		ns.change
		.animate({left: ns.offstage},{queue: ns.queue, duration: ns.duration})
		.eq(ti)
		.animate({left: ns.onstage},{queue: ns.queue, duration: ns.duration});

		ns.clicker
		.removeClass('cur')
		.eq(ti)
		.addClass('cur');

	return false;
	});

	//auto switch
	c=0;

	interval=setInterval(function(){
		if(c==ns.change.length-1) {c=0;} else {c++;}
		ns.change
		.animate({left: ns.offstage},{queue: ns.queue, duration: ns.duration})
		.eq(c)
		.animate({left: ns.onstage},{queue: ns.queue, duration: ns.duration});

		ns.clicker
		.removeClass('cur')
		.eq(c)
		.addClass('cur');
		
	},4000);




    var nav = $('#nav a');
	var slices = $('#slices div');
	
	
	
	//$('.contentC').corner();
	$('#nav a').sprite({
		h: 40, 
		sh: 70,
		hoverh: -20
	});
	$('#associates li a').sprite({
		h: 20,
		sw: 200,
		sh: 50
	});
	
	$(window).bind("load", function(){
		
		$('.searchBar').submit(function(){
			hidVal=$(this).children('p').children('input[type="hidden"]').val();
			searVal=$(this).children('p').children('input[type="text"]').val();
			if(hidVal!="" || searVal==""){return false;}
		});
	});
	
	
	/*nav.hover(function(){		
		$().stopTime();
		var ti=nav.index(this);
			slices_animate(ti);
	},function(){
		$().oneTime(1000, function(){
			slices_animate(0);
		});
	});*/
	
	var slices = {
		element: $('#slices div'),
		c: 0,
		cl: $('#slices div').length-1
	};
	
	slices.element.eq(0).css({width: 970},{queue:false});
	
	var slices_animate = setInterval(function (){
		if(slices.c<slices.cl) slices.c=slices.c+1; else slices.c=0;
		
		slices.element		
		.animate({
			width: 0
		},{
			queue:false
		})
		.eq(slices.c)
		.animate({
			width: 970
		},{
			queue:false
		});
		
	},5000);
	
    if($('#accslide').length>0) {
        $('#accslide').accordion({
            addsClass: "current",
            effect: "normal"
        });
	}
	if($('.accordion').length>0){
		$('.accordion').accordion({
			effect: "normal"
		});
		$('.accordion2').accordion({
			effect: "normal"
		});
	}



});

(function($) {
    $.fn.clearInput = function(){
        return this.each(function(i){
            var obj=$(this);
            var tv = obj.val();
            obj.attr('rel',tv);											
				
            obj.focus(function(){
                if(obj.attr('rel')==obj.val())$(this).val('');
            }).blur(function(){
                if(obj.val()=="") obj.val($(this).attr('rel'));
            }); 
        });
    };
})(jQuery);
(function($) {
    $.fn.checkEmail = function() {
        var ret;
        this.each(function(){
            var obj=$(this);
            var email = obj.val();
            if (email.indexOf("@") == -1 || email.lastIndexOf(".") == -1) ret=false;
            else ret=true;
        });
        return ret;
    };
})(jQuery);
(function($) {
    $.fn.sprite = function(options){
        var defaults = {
            w: 0,
            h: 0,
            sh: 0,
            sw: 0,
            hoverh: 0,
            hoverw: 0
        };
        
        var options = $.extend(defaults, options);

        return this.each(function(i){
                var obj=$(this);
                var width=(options.sw+(i*options.w));
                var height=(options.sh+(i*options.h));
                obj.css("background-position", -width + "px " + -height + "px");

                if(options.hoverh!=0){
                    obj.hover(function(){
                        hh=height + options.hoverh;
                        $(this).css("background-position", -width + "px " + -hh + "px");
                    },function(){
                        $(this).css("background-position", -width + "px " + -height + "px");
                    });
                } else
                if(options.hoverw!=0){
                    obj.hover(function(){
                        hw = width + options.hoverw;
                        $(this).css("background-position", -hw  + "px " + -height + "px");
                    },function(){
                        $(this).css("background-position", -width + "px " + -height + "px");
                    });
                }
            });
    };
})(jQuery);





