﻿// ========================
//    Simple jQuery Center object
// ========================
jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
    return this;
}



// ========================
//    Simple jQuery Slideshow Script
// ========================
function slideSwitch() {
    var $active = $('#slideshow img.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first');

    // uncomment the 3 lines below to pull the images in random order
    
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}



// ========================
//    Brands Menu
// ========================
function ShowCategory(obj) {
	if ($("#cat"+obj ).is(':hidden'))
		$("#cat"+obj ).slideDown("fast");
	else
		$("#cat"+obj ).slideUp("fast");
	
}


// ========================
// 	Clear Form
// ========================
$.fn.clearForm = function() {
	return this.each(function() {
	var type = this.type, tag = this.tagName.toLowerCase();
	if (tag == 'form')
		return $(':input',this).clearForm();
	if (type == 'text' || type == 'password' || tag == 'textarea')
		this.value = '';
	else if (type == 'checkbox' || type == 'radio')
		this.checked = false;
	else if (tag == 'select')
		this.selectedIndex = -1;
	});
};

// ========================
// 	Contact Form Validation
// ========================
RE = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/   // Email Validate
function ContactValidation(frm){
	fail = true
	$("#contact-form div").hide()
	$("#msg").hide();

	if (jQuery.trim($("#iname").val()).length < 3) {
		fail = false
		$("#er1").show()	
	}

	if (jQuery.trim($('#imail').val()).length <= 3 ) {
		fail = false
		$("#er2").show()	
	}
	else {
		if (!RE.test(jQuery.trim($('#imail').val()))){
			fail = false
			$("#er3").show()	
		}
	}

	if (jQuery.trim($("#idesc").val()).length < 5) {
		fail = false
		$("#er4").show()	
	}

	if (fail) {
		ContactSend(jQuery.trim($('#iname').val()),jQuery.trim($('#imail').val()),jQuery.trim($('#iphone').val()),jQuery.trim($('#idesc').val()))
	}
	return false

}

// ========================
// 	Contact Send
// ========================
function ContactSend (myName,myEmail,myPhone,myMsg) {
	$.ajax({
		url: "contactsend.asp?name=" + myName + "&email=" + myEmail + "&phone=" + myPhone + "&message=" + myMsg,
		cache: false,
		beforeSend: function(){
			$("#msg").removeClass("mess3")
			$("#msg").removeClass("mess2")
			$("#msg").addClass("mess1")
			$('#msg').html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Please wait ...");
			$("#msg").show();
		},
		success: function(html){
			$("#msg").removeClass("mess1")
			$("#msg").addClass("mess2")
			$('#msg').html("Your message has been sent successfully");
		},
		error: function(html){
			$("#msg").removeClass("mess1")
			$("#msg").addClass("mess3")
			$('#msg').html("An error occurred, please try again later");
		},
		complete: function(){
			$('#frmcontact').clearForm()
		}
	});
}



// ========================
// 	More Images - Load next image for products
// ========================
function MoreImages(imgname, num) {
	TechnicalDetails(0)

	img = "images/products/" + imgname + "-" + num + "-m.jpg"

	$("#moreimages img").removeClass("activemore")
	$("#moreimages img").addClass("more")
	$("#moreimages img").eq(num-1).addClass("activemore")

//	$("#largimg").fadeOut()
//	$("#largimg").css({opacity: 0.0}).attr({src : img}).animate({opacity: 1.0}, "fast")

	$("#largimg").attr({src : img})

}


// ========================
// 	Show Technical Details 
// ========================
function TechnicalDetails(mode) {
	if (mode==1)
		$('#technicaldetails').slideDown('normal', function(){
			$("#technicalclose").show()
		});
	else{
		$("#technicalclose").hide()
		$('#technicaldetails').slideUp('normal')
	}
}




// ========================
// 	Category Menu For Brands
// ========================
// menu show & hide //
var MenuSelect = false
var MenuTime
var MenuID
function myMenu(myid,mode){
	MenuID = $("#" + myid + '-content');
	// $ mean document get - $("#" + myid + '-content' means: document get elemnt by id + myid + -content //
	if (mode == 1){
		clearTimeout(MenuTime);
		MenuID.fadeIn("normal");
	}
	if (mode == 0)
		MenuTime= setTimeout("if (MenuSelect == false) MenuID.fadeOut('slow');",300)
	if (mode == 3){
		clearTimeout(MenuTime);
		MenuSelect = true
	}
	if (mode == 4) {
		MenuSelect = false
		MenuTime = setTimeout("if (MenuSelect == false) MenuID.fadeOut('slow');",300)
	}
}




