







// JavaScript Document
//That goes for the header page it need always to be loaded.

	$(document).ready(function() {
							   
							   
	   		//that goes for header login focus and blur
			$('input[foc=yes]').focus(function() {
				$(this).css("border","2px solid #666666");
			})
			$('input[foc=yes]').blur(function() {
				$(this).css("border","1px solid #999999");
			});

			$("div[info]").each(function(){
				$(this).qtip({content:$(this).attr('info'),position:'bottomright',style:{padding:'5px',tip:
		  		{corner:'bottomLeft',color:'#ffffff'}}});
			});
							   
							   
							   
							   
	
		//for hovering top menu 
		$("#header-top-menu1").hover(function() {
			$(this).css("background-image","url('http://www.audiominds.net/images/header-spring-2010/menu-top1.jpg')");
		}, function() {
			$(this).css("background-image","url('http://www.audiominds.net/images/header-spring-2010/header_03.gif')");
		});
		
		$("#header-top-menu2").hover(function() {
			$(this).css("background-image","url('http://www.audiominds.net/images/header-spring-2010/menu-top2.jpg')");
		}, function() {
			$(this).css("background-image","url('http://www.audiominds.net/images/header-spring-2010/header_04.gif')");
		});
		
		$("#header-top-menu3").hover(function() {
			$(this).css("background-image","url('http://www.audiominds.net/images/header-spring-2010/menu-top3.jpg')");
		}, function() {
			$(this).css("background-image","url('http://www.audiominds.net/images/header-spring-2010/header_05.gif')");
		});
		
		
		
		
		//brands
		$("#header-brands-bottom").toggle(function() {
			$("#header-brands-list").slideDown();
		}, function() {
			$("#header-brands-list").slideUp();
		});

	
	
		//here start for main menu styling
		function addClass() {
			var tmpThis = this;
			clearInterval(this.timer);
			this.timer = setTimeout(function(){$("#header-main-menu .selected").removeClass("selected"); $(tmpThis).addClass("selected");},150);
		}
		function removeClass() {
			var tmpThis = this;
			clearInterval(this.timer);
			this.timer = setTimeout(function(){$(tmpThis).removeClass("selected")},200);
		}
		// cat menu rules
		$("#header-main-menu #AMkeyboards").hover(addClass,removeClass);
		$("#header-main-menu #AMsoundware").hover(addClass,removeClass);
		$("#header-main-menu #AMacoustic").hover(addClass,removeClass);
		$("#header-main-menu #AMbooks").hover(addClass,removeClass);
		$("#header-main-menu #AMstudio").hover(addClass,removeClass);
		$("#header-main-menu #SWDrums").hover(addClass,removeClass);
		$("#header-main-menu #SWLive-sound").hover(addClass,removeClass);
		$("#header-main-menu #SWDj").hover(addClass,removeClass);
		$("#header-main-menu #SWBooks-videos").hover(addClass,removeClass);
		$("#header-main-menu #SWAccessories").hover(addClass,removeClass);
		// help menu
		$("#SWHelp-support").hover(addClass,removeClass);
		// fix rollover search box
		$("#s").mouseover(function(){$("#header-main-menu .selected").removeClass("selected")});
		
		
		
		
		
		
		
		
		
		
		
		
		//login tools 
		$("#header-login").toggle(
			function(){
				$("#header-brands-list").hide();
				$(this).addClass("header-login-active");
				$("#header-login-content").fadeIn();
			}, 
			function () {
				$(this).removeClass("header-login-active");
				$("#header-login-content").hide();
		});




	//});


		//Here goes search result ; 
		/*$('div#divsearch div').mouseleave(function(e){

				e.stopPropagation();
  	});
		$('div#divsearch').mouseleave(function(e){
			$(this).hide();
		});
		
		
		//Here goes hovering the store result 
		$('div#divstore div').mouseleave(function(e){

				e.stopPropagation();
  		});
		$('div#divstore').mouseleave(function(e){


			$(this).hide();
		});*/


//for maximizing image 
 	$('.image-resize').each(function() {
        var maxWidth = $(this).attr('size');
        var maxHeight = $(this).attr('size');
        var ratio = 0;  // Used for aspect ratio
        var width = $(this).width();    // Current image width
        var height = $(this).height();  // Current image height
 
        // Check if the current width is larger than the max
        if(width > maxWidth){
            ratio = maxWidth / width;   // get ratio for scaling image
            $(this).css("width", maxWidth); // Set new width
            $(this).css("height", height * ratio);  // Scale height based on ratio
            height = height * ratio;    // Reset height to match scaled image
            width = width * ratio;    // Reset width to match scaled image
        }
 
        // Check if current height is larger than max
        if(height > maxHeight){
            ratio = maxHeight / height; // get ratio for scaling image
            $(this).css("height", maxHeight);   // Set new height
            $(this).css("width", width * ratio);    // Scale width based on ratio
            width = width * ratio;    // Reset width to match scaled image
        }
    });
	
	

});




				
			//here goes search jquery ajax function 
			function j_search(str,heights){
				$('#divsearch').show()
				var serialize = "&q="+$(str).val(); 
 			if($(str).val() != '' && $(str).val() != 'search here....' ) {
						$.ajax({
							type: "GET",
							url: "http://www.audiominds.net/newmodules/web2.0/search.php?rnd="+Math.random()*10000,
							dataType: "html",
							data: serialize,
							beforeSend: function(){
								$('#header-search-content').slideDown()
								$('#form_divsearch').slideUp();
								$('#notification_divsearch').slideDown();
								},
								timeout: 3000,
								success: function(results) {
									if (results == "reload"){
										window.location.reload()
									}else{
										$('#form_divsearch').html(results);
										$('#notification_divsearch').slideUp();
										$('#form_divsearch').slideDown();
									}
							},
					error: function(){
							jAlert('Problem retrieving data! Internet connection problem, retry please', 'Alert Dialog');
						   }
				});
      	}
      	}



			//store function 
			function j_store(){ 
       		                $('#divstore').slideDown();
				$('#header-store-content').slideDown();
			}
			
			
			
			
			
			
		//here goes to emulate the css 
		function emulate1(str){
			$(str).css({'border':'1px solid #999999'});
		}

		function emulate(str){
			$(str).css({'border':'2px solid #ff0000'});
			var notification = "n"+$(str).attr('id');
			$("#"+notification).html($(str).attr('message'));
		}
        
        function remulate(str){
        
 			var notification = "n"+$(str).attr('id');
			$("#"+notification).html('');       
        }
		
		




		//here goes login in process
		function sf(status,serial,validates,div,page,animate,heights,scroll){
			
			//that's goes for scrolling into top of the form of input;
			if ($.browser.opera){$('html').animate({scrollTop: $(scroll).offset().top}, 500);} 
			else $('html,body').animate({scrollTop: $(scroll).offset().top}, 500);
			//end scrolling
			
			//set the validate option to true to for initialising
			var validate = true ;
			
			
			//check the forms for serials
			var myArray =serial.split(" ");
			
			var myPrint = "";
			
			var myCompare = "";
			
			
			//here the checks the serial how many input it have
			if ( myArray.length > 1 ){
				
						//serialize the serial input value=;
						for(i=0;i<myArray.length;i++) {
							
								myPrint +="&"+myArray[i]+"=";									
								
									if($('#'+myArray[i]).is(':checked')){
										myPrint += "true" 									}
									else{
										myPrint += $('#'+myArray[i]).val()
									}
 						}
				
			}
			else{
				
				myPrint += serial;
				
			}
			


			//#################################
			//start validation if set to true 
 			if (validates == true){
				
							
				$('input[foc=yes]').each(function(){
					emulate1(this)
				});
				
				$('select[foc=yes]').each(function(){
					emulate1(this)
				});
				
				$('textarea[foc=yes]').each(function(){
					emulate1(this)
				});
				
				//here the checks the serial how many input it have
				if ( myArray.length > 0 ){
					
						//serialize the serial input value=;
						
						for(i=0;i<myArray.length;i++) {
							
							if ( $('#'+myArray[i]).attr('genre') == "required" ){
								
								if( $('#'+myArray[i]).val() == '') {
									//alert("1");
									emulate('#'+myArray[i])
									validate = false
								}
                                else{ remulate('#'+myArray[i]) }
								
								if ( $('#'+myArray[i]).attr('nature') == "email" ){
									if ( !/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('#'+myArray[i]).val()) ){
																		//alert("2");
									emulate('#'+myArray[i])
									validate = false
									}
								}
                                //else{ remulate('#'+myArray[i]) }
								
								
								
								//here to compare an input with each other
								myCompare = myArray[i].split("@");

								
								if ( myCompare.length > 1 ){
									//alert(myCompare+'tess');
									if( $('#'+myCompare[0]).val() != $('#'+myCompare[1]).val()  ){
										emulate('#'+myCompare[0])
										emulate('#'+myCompare[1])
										validate = false
										
									}
                                    else{ remulate('#'+myCompare[0]); remulate('#'+myCompare[1]) }
									
								}
								
							} // if required 
						
						}//end for loop
							
							
				}
				
				
				
			}//end if validates == true 
			
			
			
			//get ouf validation if it passed true
			if ( validate ){
				
				//get sery
				var get = "&status="+status+myPrint;
				
				
				//start the ajax issue
				$.ajax({
					   
						type: "GET",
						url: "http://www.audiominds.net/"+page+"?rnd="+Math.random()*10000,
						dataType: "html",
						data: get,
						
						beforeSend: function(){
					
									$(animate).animate({
										height: '40px',
    								}, 1000 );
									
									$('#form_'+div).slideUp();
									$('#notification_'+div).slideDown();
						},
						
						timeout: 3000,
						
						success: function(results) {
							
							if (results == "reload"){
								
									window.location.reload()
									
							}else{
								
								$(animate).animate({
								height: heights,
    							}, 2000 );
								
									$('#form_'+div).html(results);
									$('#notification_'+div).slideUp();
									$('#form_'+div).slideDown();
								}
								
						 },//END SUCCESS
						 
						 
						 error: function(){
							 
							jAlert('Problem retrieving data! Internet connection problem, retry please', 'Alert Dialog');
							
						 }
					
					
				});//end ajax issue;  
					   
			}
			
			
			
		}//end function 
			
			
			
			
			
			
			
			
			
  
