@import '../_theme_variables';
@mixin opacity($opacity) {
	opacity: $opacity;
	filter: unquote("alpha(opacity=#{round($opacity * 100)})");
	-moz-opacity: $opacity;
}

@mixin hideYetClickable() {
	@include opacity(0);
	border: none;
	background: none;
}

@mixin inline-block() {
	display: -moz-inline-box;
	display: inline-block;
	*display: inline;
	zoom: 1;
}

@mixin ellipsis() {
	text-overflow: ellipsis;
	display: block;
	overflow: hidden;
	white-space: nowrap;
}

@mixin border-radius($radius) {
	-webkit-border-radius: $radius;
	-moz-border-radius: $radius;
	border-radius: $radius;
}

@mixin box-shadow($def) {
	-webkit-box-shadow: $def;
	-moz-box-shadow: $def;
	box-shadow: $def;
}

@mixin retina() {
	@media only screen {
		@media (min-resolution: 124dpi), (-webkit-min-device-pixel-ratio: 1.3), (min--moz-device-pixel-ratio: 1.3), (-o-min-device-pixel-ratio: 4/3), (min-device-pixel-ratio: 1.3), (min-resolution: 1.3dppx) {
			@include use-backgrounds(url($sprite-retina), $sprite-size, url($input-background-retina), url($input-background-focus-retina), $input-background-size);
		}
	}
}

@mixin use-backgrounds($sprite, $sprite-size, $input, $input-focus, $input-size) {
	div#{$class-wrapper} {
		&#{$class-select},
		&#{$class-select} span,
		&#{$class-checkbox} span,
		&#{$class-upload},
		&#{$class-upload} span#{$class-action},
		&#{$class-button},
		&#{$class-button} span {
			background-image: $sprite;

			@if $sprite-size > 0 {
				background-size: $sprite-size;
			}
		}
	}

	#{$class-wrapper-element}#{$class-wrapper} input#{$class-input},
    #{$class-wrapper-element}#{$class-wrapper} select#{$class-multiselect},
    #{$class-wrapper-element}#{$class-wrapper} textarea#{$class-textarea} {
		background-image: $input;

		@if $sprite-size > 0 {
			background-size: $input-size;
		}

		@include whenActive {
			background-image: $input-focus;
		}
	}
}

@mixin whenActive {
	&#{$class-active} {
		@content
	}
}

@mixin whenHover {
	&#{$class-hover}, &#{$class-focus} {
		@content
	}
}

@mixin whenDisabled {
	&#{$class-disabled}, &#{$class-disabled}#{$class-active} {
		@content
	}
}

@mixin whenChecked {
	&#{$class-checked} {
		@content
	}
}


$sprite: "../../img/jquery/uniform/sprite.png" !default;
$sprite-retina: "../../img/jquery/uniform/sprite-retina.png" !default;
$sprite-size: 493px !default;
$button-height: 30px !default;
$button-margin-left: 13px !default;
$button-padding: 0 !default;
$button-span-height: $button-height !default;
$checkbox-height: 15px !default;
$checkbox-width: 15px !default;
$input-padding: 3px !default;
$input-background: "../../../img/jquery/uniform/bg-input.png" !default;
$input-background-retina: "../../../img/jquery/uniform/bg-input-retina.png" !default;
$input-background-focus: "../../../img/jquery/uniform/bg-input-focus.png" !default;
$input-background-focus-retina: "../../../img/jquery/uniform/bg-input-focus-retina.png" !default;
$input-background-size: 1px !default;
$radio-height: 13px !default;
$radio-width: 13px !default;
$select-fixed-width: 190px !default;
$select-height: 27px !default;
$select-margin-left: 10px !default;
$select-margin-right: 30px !default;
$select-select-height: 27px !default;
$select-select-top: 0 !default;
$upload-action-width:94px !default;
$upload-filename-margin-top: 0 !default;
$upload-filename-margin-bottom: 0 !default;
$upload-filename-margin-left: 0 !default;
$upload-filename-width: 172px !default;
$upload-filename-padding: 0 10px !default;
$upload-height: 27px !default;
$upload-width: 100% !default;


$checkbox-voffset: (-10 * $select-height);
$radio-voffset: ($checkbox-voffset - $checkbox-height);
$upload-voffset: ($radio-voffset - $radio-height);
$button-voffset: ($upload-voffset - (8 * $upload-height));

$class-action: ".action" !default;
$class-active: ".active" !default;
$class-button: ".button" !default;
$class-checkbox: ".checker" !default;
$class-checked: ".checked" !default;
$class-disabled: ".disabled" !default;
$class-input: ".uniform-input" !default;
$class-filename: ".filename" !default;
$class-focus: ".focus" !default;
$class-hover: ".hover" !default;
$class-multiselect: ".uniform-multiselect" !default;
$class-radio: ".radio" !default;
$class-select: ".selector" !default;
$class-select1: ".selector1" !default;
$class-select2: ".selector2" !default;
$class-select3: ".selector3" !default;
$class-upload: ".uploader" !default;
$class-textarea: ".uniform" !default;
$class-wrapper: "" !default;

$class-wrapper-element: "";
@if $class-wrapper != "" {
	$class-wrapper-element: "span"
}

/* General settings */

div#{$class-wrapper} {
	&#{$class-select},
	&#{$class-select} span,
	&#{$class-upload},
	&#{$class-upload} span#{$class-action},
	&#{$class-button},
	&#{$class-button} span {
		background-image: url($sprite);
		background-repeat: no-repeat;
		-webkit-font-smoothing: antialiased;
	}

	&#{$class-select},
	&#{$class-checkbox},
	&#{$class-button},
	&#{$class-radio},
	&#{$class-upload} {
		
		vertical-align: middle;

		/* Keeping this as :focus to remove browser styles */
		&:focus {
			outline: 0;
		}
	}

	&#{$class-select},
	&#{$class-radio},
	&#{$class-checkbox},
	&#{$class-upload},
	&#{$class-button} {
		&, & * {
			margin: 0;
			padding: 0;
		}
	}
}

.highContrastDetect {
	background: url($input-background) repeat-x 0 0;
	width: 0;
	height: 0;
}

/* Input & Textarea */

#{$class-wrapper-element}#{$class-wrapper} input#{$class-input},
#{$class-wrapper-element}#{$class-wrapper} select#{$class-multiselect},
#{$class-wrapper-element}#{$class-wrapper} textarea#{$class-textarea} {
	padding: $input-padding;
	background: white;
	outline: 0;

	@include whenActive {
		
	}
}

/* Remove default webkit and possible mozilla .search styles.
 * Keeping this as :active to remove browser styles */
div#{$class-wrapper}#{$class-checkbox} input,
input[type="search"],
input[type="search"]:active  {
	-moz-appearance: none;
	-webkit-appearance: none;
}

/* Select */
div#{$class-wrapper}#{$class-select} {
	line-height: $select-height;
	height: $select-height;
	padding: 0 0 0 $select-margin-left;
	position: relative;
	overflow: hidden;
	border:1px solid $base-border-color;
	background:#fff;
	span {
		@include ellipsis();
		background:none;
		height: $select-height - 2;
		line-height: $select-height - 2;
		padding-right: $select-margin-right;
		cursor: pointer;
		width: 100%;
		display: block;
		&:after {
			content:'\f0d7';
			font-family:$font-icon;
			position:absolute;
			right:1px;
			top:1px;
			border:1px solid $base-border-color;
			text-align:center;
			height:23px;
			width:23px;
			font-size:19px;
			line-height:21px;
			color:#AFAEAE;
			background:#fafafa;
		}
	}

	&.fixedWidth{
		width: $select-fixed-width;
		span {
			width: ($select-fixed-width - $select-margin-left - $select-margin-right);
		}
	}

	select {
		@include hideYetClickable();
		position: absolute;
		height: $select-select-height;
		top: $select-select-top;
		left: 0;
		width: 100%;
	}

	@include whenActive {
		span {
			&:after {
				color:darken(#AFAEAE, 25);
				top:1px;
			}
		}
	}

	@include whenHover {
		span {
			&:after {
				color:darken(#AFAEAE, 25);
				top:1px;
			}
		}

		@include whenActive {	
			span {
				&:after {
					color:darken(#AFAEAE, 25);
					top:1px;
				}
			}
		}
	}

	@include whenDisabled {
		span {
			&:after {
				color:darken(#AFAEAE, 25);
				top:1px;
			}
		}
	}
}

/* Checkbox */

div#{$class-wrapper}#{$class-checkbox} {
	position: relative;

	&, span {
		width: $checkbox-width;
		height: $checkbox-height;
	}
	input {
		position:relative;
		left:-1px;
		top:-3px;
		width: $checkbox-width;
		height: $checkbox-height - 1 !important;
		padding:0;
		cursor:pointer;
	}
	span {
		@include inline-block();
		text-align: center;
		border:1px solid $base-border-color;
		overflow:hidden;
		background:#fff;
	    @include whenChecked {
			&:before {
				content:'\f00c';
				font-family:$font-icon;
				position:absolute;
				left:auto;
				top:auto;
				padding:0 0 0 1px;
				text-align:center;
				width:13px;
				height:13px;
				line-height:14px;
				font-size:12px;
				background:lighten($base-border-color, 6.5);
			}
		}
	}

	input {
		@include hideYetClickable();
		@include inline-block();
	}

	@include whenActive {
		span {
			background-position: (-1 * $checkbox-width) ($checkbox-voffset + $radio-height);
		
			@include whenChecked {
				background-position: (-1 * $checkbox-width) ($checkbox-voffset + $radio-height);
			}
		}
	}

	@include whenHover {
		span {
			background:lighten($base-border-color, 6.5);

			@include whenChecked {
				background:lighten($base-border-color, 4.5);
			}
		}

		@include whenActive {}
	}

	@include whenDisabled {
		background-position: 0 ($checkbox-voffset + $radio-height);

		span {
			@include whenChecked {
				background-position: 0 ($checkbox-voffset + $radio-height);
			}
		}
	}
}


/* Radio */

div#{$class-wrapper}#{$class-radio} {
	position: relative;
	display:inline;
	&, span, input {
		width: $radio-width;
		height: $radio-height;
	}
	span {
		width: $radio-width + 1;
		height: $radio-height + 1;
	}
	span {
		@include inline-block();
		text-align: center;
		@include border-radius(100%);
		border:1px solid $base-border-color;

		@include whenChecked {
			&:before {
				width:8px;
				height:8px;
				@include border-radius(100%);
				background:darken(#777777, 2);
				position:absolute;
				z-index:1;
				left:2px;
				top:2px;
				display:block;
				text-indent:-5000px;
				content:'*';
			}
		}
	}

	input {
		@include hideYetClickable();
		@include inline-block();
		text-align: center;
	}

	@include whenActive {
		span {
			@include whenChecked {
			}
		}
	}

	@include whenHover {
		span {
			background-color:#f7f7f7;
		}
	}

	@include whenDisabled {
		span {}
	}
}

/* Uploader */

div#{$class-wrapper}#{$class-upload} {
	background:none;
	height: $upload-height;
	width: $upload-width;
	cursor: pointer;
	position: relative;
	overflow: hidden;

	span#{$class-action} {
		background-position: 0 -378px;
		height: $upload-height;
		line-height: $upload-height;
		width: $upload-action-width;
		text-align: center;
		float: left;
		display: inline;
		overflow: hidden;
		cursor: pointer;
	}

	span#{$class-filename} {
		@include ellipsis();
		float: left;
		cursor: default;
		height: ($upload-height - $upload-filename-margin-top - $upload-filename-margin-bottom);
		margin: $upload-filename-margin-top 0 $upload-filename-margin-bottom $upload-filename-margin-left;
		line-height: ($upload-height - $upload-filename-margin-top - $upload-filename-margin-bottom);
		width: $upload-filename-width;
		padding: $upload-filename-padding;
	}

	input {
		@include hideYetClickable();
		position: absolute;
		top: 0;
		right: 0;
		float: right;
		cursor: default;
		width: 100%;
		height: 100%;
	}
}

/* Buttons */

div#{$class-wrapper}#{$class-button} {
	background-position: 0 ($button-voffset + (-4 * $button-height));
	height: $button-height;
	cursor: pointer;
	position: relative;

	/* Keep buttons barely visible so they can get focus */
	a, button, input {
		@include opacity(0.01);
		display: block;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		position: absolute;
	}

	span {
		@include inline-block();
		line-height: $button-span-height;
		text-align: center;
		background-position: right $button-voffset;
		height: $button-span-height;
		margin-left: $button-margin-left;
		padding: $button-padding;
	}

	@include whenActive {
		background-position: 0 ($button-voffset + (-5 * $button-height));

		span {
			background-position: right ($button-voffset + (-1 * $button-height));
			cursor: default;
		}
	}

	@include whenHover {
		background-position: 0 ($button-voffset + (-6 * $button-height));

		span {
			background-position: right ($button-voffset + (-2 * $button-height)); 
		}
	}

	@include whenDisabled {
		background-position: 0 ($button-voffset + (-7 * $button-height));

		span {
			background-position: right ($button-voffset + (-3 * $button-height));
			cursor: default;
		}
	}
}
