// JavaScript Document
var common__productImageMouseDownStatus = false;
var common__productImageMouseX = 0;
var common__productImageMouseY = 0;
function common__productImageMouseDown(evnt) {
	evnt.stop();
	common__productImageMouseDownStatus = true;
	common__productImageMouseX = evnt.pointerX();
	common__productImageMouseY = evnt.pointerY();
}

function common__productImageMouseUp(evnt) {
	evnt.stop();
	common__productImageMouseDownStatus = false;
}

function common__productImageMouseMove(evnt) {
	evnt.stop();
	if(!common__productImageMouseDownStatus) return;

	var mouseDeltaX = evnt.pointerX() - common__productImageMouseX;
	var mouseDeltaY = evnt.pointerY() - common__productImageMouseY;
	////console.log(mouseDeltaX+", "+mouseDeltaY);

	this.style.left = (parseFloat(this.style.left) + mouseDeltaX) + "px";
	this.style.top	= (parseFloat(this.style.top)  + mouseDeltaY) + "px";

	common__productImageMouseX = evnt.pointerX();
	common__productImageMouseY = evnt.pointerY();
}

function common__productImageScroll(evnt) {
	evnt = evnt == null ? Event.extend(window.event) : evnt;
	Event.stop(evnt);
	/**
	 * Event::wheelDelta is IE & WebKit
	 * Event::detail is Firefox.
	 * Firefox units are a factor of 40 smaller than
	 * those used by IE & WebKit, and are also sign-inverse
	 */
	var wheelDelta = typeof(evnt.wheelDelta) != 'undefined' ? evnt.wheelDelta : (evnt.detail * -40.0);
	/**
	 * OK after we've 'normalized' the mouse-wheel amount
	 * we're in a position where each "tick" is 120,
	 * with "up" or "away from the user" being positive.
	 */

	var imageWidth = parseFloat($('imageWidth').value);
	var imageHeight = parseFloat($('imageHeight').value);
	var oldScaleFactor = parseFloat(this.style.width) / imageWidth;
	var newScaleFactor = oldScaleFactor + (wheelDelta/25000.0);
	this.style.width = (imageWidth * newScaleFactor)+"px";
	this.style.height = (imageHeight * newScaleFactor)+"px";
}

function common__productImageSaveCrop(evnt) {
	try {
		//alert(evnt);
		//alert(window.location.pathname);
		var image = $('headerImage');
		var imageContainer = $('headerImageCont');
		var offsetX = parseInt(image.style.left);
		var offsetY = parseInt(image.style.top);
		var scale = parseFloat(image.style.width) / parseFloat($('imageWidth').value);
		var name = $('name').value;
		var isEvent = $('isEvent').value;
		var redirect = $('redirect').value;

		var width = parseInt(imageContainer.style.width);
		var height = parseInt(imageContainer.style.height);
		
		var form = new Element("form");
		form.action = "/images/crop_process";
		form.method = "post";
		form.style.display = "none";
		document.body.appendChild(form);
		
		form.appendChild($('ID'));
		form.appendChild($('imageID'));
		
		var nameInp  = new Element("input");
		nameInp.value = name;
		nameInp.name = "name";
		form.appendChild(nameInp);
		
		var eventInp  = new Element("input");
		eventInp.value = isEvent;
		eventInp.name = "isEvent";
		form.appendChild(eventInp);
		
		var rdrInp  = new Element("input");
		rdrInp.value = redirect;
		rdrInp.name = "redirect";
		form.appendChild(rdrInp);
		
		var scaleInp  = new Element("input");
		scaleInp.value = scale;
		scaleInp.name = "scale";
		form.appendChild(scaleInp);
		
		var offsetXInp  = new Element("input");
		offsetXInp.value = offsetX;
		offsetXInp.name = "offsetX";
		form.appendChild(offsetXInp);
		
		var transYInp  = new Element("input");
		transYInp.value = offsetY;
		transYInp.name = "offsetY";
		form.appendChild(transYInp);
		
		var imageWidth  = new Element("input");
		imageWidth.value = width;
		imageWidth.name = "imageWidth";
		form.appendChild(imageWidth);
		
		var imageHeight  = new Element("input");
		imageHeight.value = height;
		imageHeight.name = "imageHeight";
		form.appendChild(imageHeight);
		
		var module = new Element("input");
		pathArray = window.location.pathname.split( '/' );
		var abc = pathArray[5];
		//alert(abc);
		module.value = abc;
		module.name = "module";
		form.appendChild(module);
		
		form.submit();
	}
	catch(e) {
		alert(e);	
	}
}

var win = null;
function mail(mypage,myname,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable=yes'
	win = window.open(mypage,myname,settings);
}

$(function(){
	$('#eventsContainer').vTicker({
		speed: 3000,
		pause: 10000,
		animation: 'fade',
		mousePause: true,
		//height: 150,
		direction: 'up',
		showItems: 2
	});
});

$(function(){
	$('#offersContainer').vTicker({
		speed: 3000,
		pause: 10000,
		animation: 'fade',
		mousePause: true,
		//height: 176,
		direction: 'up',
		showItems: 2
	}); 
});

function clearText(e) {
	e.value = "";
	e.onfocus = "";
}
function inputFocus(i){
    if(i.value==i.defaultValue){ i.value=""; i.style.color="#000"; }
}
function inputBlur(i){
    if(i.value==""){ i.value=i.defaultValue; i.style.color="#888"; }
}

$(document).ready(function()
  {					
    $("#contactForm").validationEngine();
        
	$('div.bk-diamondslider').slider_plugin({		
		rows: 1,	
		columns: 1,		
		auto_play : true,	
		show_timer: false,	
		ken_burns_for_thumbs: false,	
		socondary_nav_type: 'none',	
		pause_on_hover: true,	
		def_transition: 'tl-br-diagonal-fade',	
		slide_timeout: 2000,	
		slide_animation: 2000,	
		kb_slides_start_cpoint: [0,100],	
		kb_slides_start_cpoint_random: true,	
		kb_slides_dest_cpoint: [0,100],	
		kb_slides_dest_cpoint_random: true,	
		ken_burns_for_slides: true,	
		kb_slides_play_in_loop: false,	
		//kb_slides_zoomfactor: 0.9,
		kb_slides_anim_time: 5000
	});

        // front,cybamaila request
    $('#cybamaila').submit(function(e){        
        //this is changed if the user enters some data
        if($('#firstname').css("color") != "rgb(136, 136, 136)" && $('#firstname').val() != "Name" && $('#firstname').val() != ""){
            var firstname_val = $('#firstname').val();
        }else{
            var firstname_val = '';
        }
        var email_val = $('#email').val();
        $.post("/cybamaila.php", { action: "cybamaila", firstname: firstname_val, email: email_val },
			function(data){
			 //console.log(data);
             
//				$("#newsletter-loader").hide();
				if(data != "yes")
				{
					$("#subscribe-cross").show();
                    $("#feedback").show().html(data).css("color", "red");
                    $("#subscribe-tick").hide();
				}
				else if (data == "yes")
				{ 
					$("#subscribe-tick").show();
                    $("#email").val("");
                    $("#firstname").val("");
                    $("#subscribe-cross").hide();
                    $("#feedback").html("Successfully subscribed to newsletter").css("color", "green");
                    $("#feedback").delay('2000').fadeOut("slow");
                    $("#subscribe-tick").delay('2000').fadeOut("slow");
				}
   			});
            
        e.preventDefault();                     
    });    
    	
});					 															

