jQuery(document).ready(function($){
	
		Cufon.replace('h2, #main .post .share h4, #main #commentsarea h3');
		
		
		
		contact_form(); //controls the contact form
		
		
	
		
			
	$(function() { 
		$('#store-banners').innerfade( {
			speed: 'slow', timeout: 5000, type: 'sequence'
		});
	});
	
	// SLIDER (by CSS-Tricks http://css-tricks.com/examples/FeaturedContentSlider/ )
	
	var theInt = null;
		var $crosslink;
		var curclicked = 0;
		
		theInterval = function(cur){
			clearInterval(theInt);
			
			if( typeof cur != 'undefined' )
				curclicked = cur;
			
			$crosslink.removeClass("active-thumb");
			$crosslink.eq(curclicked).addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
			
			theInt = setInterval(function(){
				$crosslink.removeClass("active-thumb");
				$crosslink.eq(curclicked).addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
				curclicked++;
				if( 5 == curclicked )
					curclicked = 0;
				
			}, 3000);
		};
		
		$(function(){
		    
		    $("#main-photo-slider").codaSlider();
		    
		    $crosslink = $(".cross-link");
		    
		    $crosslink
		    .click(function() {
		    	var $this = $(this);
		    	theInterval($this.attr('href').slice(1) - 1);
		    	return false;
		    });
		    
		    theInterval();
		});
		
	$(function(){
		$('.add_another_file_input').show();
		// add click handler to add icon
		$('.add_another_file_input').click(function(){
			// get input html
			var html = $(this).parents('.input').html();
			// add to form
			$('.file:last').after( '<div class="input file hide">'+html+'</div>' );
			// hide the add icon
			$('.file:last a.add_another_file_input').hide();
			// fade in the input
			$('.file:last').fadeIn().removeClass('hide');
	
		return false;
		});
	});
	
	function contact_form(){
		var my_error;
		var url = "http://www.qeeworld.com/wp-content/themes/qee_theme";
		jQuery(".ajax_form #send").bind("click", function(){
												 
		my_error = false;
		jQuery(".ajax_form #name, .ajax_form #message, .ajax_form #email ").each(function(i){
					
					
					var value = jQuery(this).attr("value");
					var check_for = jQuery(this).attr("id");
					var surrounding_element = jQuery(this).parent();
					if(check_for == "email"){
						if(!value.match(/^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$/)){
							
							surrounding_element.attr("class","").addClass("error");
							
							my_error = true;
							}else{
							surrounding_element.attr("class","").addClass("valid");	
							}
						}
					
					if(check_for == "name" || check_for == "message"){
						if(value == ""){
							
							surrounding_element.attr("class","").addClass("error");
							
							my_error = true;
							}else{
							surrounding_element.attr("class","").addClass("valid");	
							}
						}
							   if(jQuery(".ajax_form #name, .ajax_form #message, .ajax_form #email").length  == i+1){
									if(my_error == false){
										jQuery(".ajax_form").slideUp(400);
										
										var $datastring = "ajax=true";
										jQuery(".ajax_form input, .ajax_form textarea").each(function(i)
										{
											var $name = jQuery(this).attr('name');	
											var $value = jQuery(this).attr('value');
											$datastring = $datastring + "&" + $name + "=" + $value;
										});
																			
										
										jQuery(".ajax_form #send").fadeOut(100);	
										
										jQuery.ajax({
										   type: "POST",
										   url: url+"/send.php",
										   data: $datastring,
										   success: function(response){
										   jQuery(".ajax_form").before("<div class='ajaxresponse' style='display: none;'></div>");
										   jQuery(".ajaxresponse").html(response).slideDown(400); 
										   jQuery(".ajax_form #send").fadeIn(400);
										   jQuery(".ajax_form #name, .ajax_form #message, .ajax_form #email , .ajax_form #website").val("");
											   }
											});
										} 
								}
						});
				return false;
		});
	}
	
	

		
		$(function(){	
			$("a[rel^='lightbox']").fancybox({
				'transitionIn' : 'none',
				'transitionOut' : 'none',
				'titlePosition' : 'inside',
				'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
					return '<span id="fancybox-title-inside">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
				}
			});
		});
		
		$(function(){
			$('.postcontent-single a[href]:has(img)').not('a[href^=javascript]').not($('a[target=_blank]')).each(function() {
				$(this).attr('rel','lightbox[set]');
					$(this).fancybox({
					'transitionIn' : 'none',
					'transitionOut' : 'none',
					'titlePosition' : 'inside',
					'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
						return '<span id="fancybox-title-inside">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
					}
				});
			});
						
		});
		
		
		
});