jQuery.noConflict();

jQuery(document).ready(function($){
	
	$.maxZIndex = $.fn.maxZIndex = function(opt) {
		var zmax = 0;
		var def = {inc:10,group:"*"};
		$.extend(def, opt);    
		$(def.group).each(function(){
			var cur = parseInt($(this).css('z-index'));
			zmax = cur > zmax ? cur : zmax;
		});
		if (!this.jquery)return zmax;
		return this.each(function(){
			zmax += def.inc;
			$(this).css("z-index", zmax);
		});
	}
	
	/**/
	
	$('._opanel').mouseenter(function(){
		var _this = $(this);
		var idName = _this.attr('id');
		var opened = false;
		var forId = idName.split('a_')[1];

		if((navigator.userAgent.indexOf("MSIE 7"))!=-1)
		{
			var offSet = getOffset( this );
			var _x = $(this).offset().left-$("#topmenu").offset().left;
			var _y = 11;
			var _width = $('#'+forId).width()-8;
			var i = $('.bsh',$('#'+forId)).css({'width':_width,'left':'4','position':'absolute'});
			$('.cl, .cr',$('#'+forId)).css({'top': $('#'+forId).height()});
		}
		else
		{
			var _x = this.offsetLeft+this.scrollLeft;
			var _y = this.offsetTop+this.scrollTop;
		}
		
		$('.opanel').css({'display':'none'});
		$('._opanel').removeClass( 'selected' );
		$('#'+forId).css({'display': 'block','top':_y+25,'left':_x-4});
		
		_this.addClass( 'selected' );

		$('#'+forId).mouseleave(function(){
			$(this).css({'display':'none'});
			_this.removeClass( 'selected' );
		})
		$('#'+forId).mouseenter(function(){
			opened = true;
		})
		
		_this.mouseout(function(){
			var __this = $(this);
			var idName = __this.attr('id');
			var forId = idName.split('a_')[1];
			var t = setTimeout(function(){
				if(!opened)
				{
					if($('#'+forId).css('display') != 'none')
					{
						$('#'+forId).css({'display':'none'});
						__this.removeClass( 'selected' );
					}
			}
				clearTimeout(t);
			}, 400);
		})
		
	});
	
	/**/
	
	$('input.i-input').focus(function(){
		if( $(this).attr('value') == $(this).attr('title') )
		{
			$(this).attr('value','');
		}
	});
	$('input.i-input').blur(function(){
		if( !$(this).attr('value') )
		{
			$(this).attr('value',$(this).attr('title'));
		}
	});
	
	$( 'form.i-emailform' ).submit(function(){
		var e = $( 'input.i-input', $(this) );
		if( ( e.attr('value') == null ) || ( e.attr('value') == "" ) ){
			alert( "Please Enter your Email!" );
			e.focus();
			return false;
		}
		if( echeck( e.attr('value') ) == false ){
			e.value = "";
			e.focus();
			return false;
		}
	});
	
	function echeck(str) {
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
        alert("Invalid E-mail!")
        return false
    }
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
        alert("Invalid E-mail!")
        return false
    }
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        alert("Invalid E-mail!")
        return false
    }
    if (str.indexOf(at,(lat+1))!=-1){
        alert("Invalid E-mail!")
        return false
    }
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("Invalid E-mail!")
        return false
    }
    if (str.indexOf(dot,(lat+2))==-1){
        alert("Invalid E-mail!")
        return false
    }
    if (str.indexOf(" ")!=-1){
        alert("Invalid E-mail!")
        return false
    }
    return true}
	function getOffset( el ) {
    var _x = 0;
    var _y = 0;
    while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
        _x += el.offsetLeft - el.scrollLeft;
        _y += el.offsetTop - el.scrollTop;
        el = el.parentNode;
    }
    return { top: _y, left: _x };}
	
	/* Wish List */
	
	$('#form1 .istrok').click(function(){Validate($('#form1'));return false;});
	
	/* Init JQuery Modules */

	//try{$(".jsonslider").jsonSlider("/templates/slider.asp", "/templates/getcategory.asp",{autoPlay:false});}catch(e){}
	
	/* Cert VAlign Bug fix */
	
	try{$("#footer_main #footer_ribbon img").each(function(){var img = $(this);var imgHeight = img.height();img.css({"margin-top":(84-imgHeight)/2})});}catch(e){}

	try{$(".accessories_box_mini .minipic img").each(function(){
		var img = $(this);
		if( !/\.\w{3,4}/.test(img.attr('src')) )
		{
			img.parent().parent().parent().hide();
		}
	});
	
	}catch(e){}
	


	Number.prototype.formatMoney = function(c, d, t)
	{
		var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "," : d, t = t == undefined ? "." : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
		return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
	};
	String.prototype.getFloat = function(){return parseFloat(this.replace(",",""))}

	$(".cssselect").change(function(){
		var price = $("#form_price").val().getFloat();
		var cssselect = $(".cssselect option:selected");
		cssselect.each(function(i,v){
			price += ($(v).attr("class").split("|")[1]).getFloat();
		});
		$(".priceline p").text("$"+price.formatMoney(2,".",","));
	});
	

});
