jQuery(document).ready(function(){
	initTabs();
	initPage();
	pageAnimate();
	fadeDrop();
	fadeHover();
	jQuery('input:checkbox').customCheckbox();
	initGallery();
	if (navigator.userAgent.toLowerCase().indexOf('firefox/3') != -1 || navigator.userAgent.toLowerCase().indexOf('opera') != -1 ) initRoundedCorners();
	initSlideBox();
	hoverForText(".textarea-holder textarea", "textarea-hover");
});
function hoverForText(h_list, h_class){
	jQuery(h_list).hover(function (){
		jQuery(this).parent().addClass(h_class);
	}, function (){
		jQuery(this).parent().removeClass(h_class);
	});
}
//init slide box
function initSlideBox(){
	jQuery('.slide-box').each(function(){
		var holder = jQuery(this);
		var offset = holder.offset().top - 17;
		var t;
		
		
		function moveHolder(){
			var limit = jQuery('#twocolumns').offset().top + jQuery('#twocolumns').outerHeight() - holder.outerHeight();
			jQuery('#twocolumns').css({
				minHeight:jQuery('#twocolumns').height()
			});
			if (jQuery(window).scrollTop() > offset && jQuery(window).scrollTop() < limit){
				holder.addClass('slide-box-fixed').removeClass('slide-box-absolute');
			} else if (jQuery(window).scrollTop() > limit){
				holder.removeClass('slide-box-fixed').addClass('slide-box-absolute');
			} else {
				holder.removeClass('slide-box-fixed').removeClass('slide-box-absolute');
			}
		}
		jQuery(window).scroll(moveHolder);
		moveHolder();
	});
}
// init rounded corners
function initRoundedCorners() {
	var images = document.getElementsByTagName('img');
	for(var i = 0; i < images.length; i++) {
		if(images[i].className.indexOf('photo') != -1) {
			var radValue = parseInt(images[i].className.replace(/.*rounded-corner-(\d+).*/, '$1'),10);
			if(!isNaN(radValue)) {
				new ImgCorner({
					image: images[i],
					radius: radValue
				});
			}
		}
	}
}
//init gallery
function initGallery(){
	jQuery('div.gallery-box').gallery({
		duration: 500,
		autoRotation: 3500,
		listOfSlides: '.gallery > li',
		switcher: '.switcher>li'
	});
}
//gallery plugin
(function($) {
	jQuery.fn.gallery = function(options) {
		var args = Array.prototype.slice.call(arguments);
		args.shift();
		this.each(function(){
			if(this.galControl && typeof options === 'string') {
				if(typeof this.galControl[options] === 'function') {
					this.galControl[options].apply(this.galControl, args);
				}
			} else {
				this.galControl = new Gallery(this, options);
			}
		});
		return this;
	};
	function Gallery(context, options) { this.init(context, options); };
	Gallery.prototype = {
		options:{},
		init: function (context, options){
			this.options = jQuery.extend({
				duration: 700,
				slideElement:1,
				autoRotation: false,
				effect: false,
				listOfSlides: '.list > li',
				switcher: false,
				autoSwitcher: false,
				stopOnHover:false,
				disableBtn: false,
				nextBtn: 'a.link-next, a.btn-next, a.next',
				prevBtn: 'a.link-prev, a.btn-prev, a.prev',
				circle: true,
				clone: false,
				direction: false,
				event: 'click'
			}, options || {});
			var self = this;
			this.context = jQuery(context);
			this.initEls();
			this.autoRotation = this.options.autoRotation;
			this.direction = this.options.direction;
			this.duration = this.options.duration;
			this.move = true;
			this.wrap = this.list.parent();
			if (this.options.nextBtn) this.nextBtn = this.context.find(this.options.nextBtn);
			if (this.options.prevBtn) this.prevBtn = this.context.find(this.options.prevBtn);

			this.calcParams(this);
			this.calcMinEls();
			
			if (this.options.autoSwitcher) {
				this.switcherHolder = this.context.find(this.options.switcher).empty();
				this.switchPattern = jQuery('<ul class="'+ (this.options.autoSwitcher == true ? '' : this.options.autoSwitcher) +'"></ul>');
				for (var i=0;i<this.max+1;i++){
					jQuery('<li><a href="#">'+i+'</a></li>').appendTo(this.switchPattern);
				}
				this.switchPattern.appendTo(this.switcherHolder);
				this.switcher = this.context.find(this.options.switcher).find('li');
				this.active = 0;
			} else {
				if (this.options.switcher) {
					this.switcher = this.context.find(this.options.switcher);
					this.active = this.switcher.index(this.switcher.filter('.active:eq(0)'));
				}
				else this.active = this.els.index(this.els.filter('.active:eq(0)'));
			}
			if (this.active < 0) this.active = 0;
			this.last = this.active;
			if (this.options.switcher) this.switcher.removeClass('active').eq(this.active).addClass('active');
			if (this.options.clone) this.active += this.count;
			
			if (this.options.effect) this.els.css({opacity: 0}).removeClass('active').eq(this.active).addClass('active').css({opacity: 1}).css('opacity', 'auto');
			else {
				if (this.direction) this.list.css({marginTop: -(this.mas[this.active])});
				else this.list.css({marginLeft: -(this.mas[this.active])});
			}
			
			if (this.options.nextBtn) this.initEvent(this, this.nextBtn,true);
			if (this.options.prevBtn) this.initEvent(this, this.prevBtn,false);
			
			this.initWindow(this,jQuery(window));
			
			if (this.autoRotation) this.runTimer(this);
			
			if (this.options.switcher) this.initEventSwitcher(this, this.switcher);
			if (this.options.disableBtn && !this.options.circle && !this.options.clone) this.disableControls();
			
			if (this.options.stopOnHover) this.stopHover(this);
		},
		initEls: function(){
			this.els = this.context.find(this.options.listOfSlides);
			this.count = this.els.length;
			this.list = this.els.parent();
			if (this.options.clone) {
				this.list.append(this.els.clone());
				this.list.prepend(this.els.clone());
				this.els = this.context.find(this.options.listOfSlides);
			}
		},
		reCount: function(){
			this.initEls();
			this.calcParams(this);
			this.calcMinEls();
			if (this.options.effect) this.els.css({opacity: 0}).removeClass('active').eq(this.active).addClass('active').css({opacity: 1}).css('opacity', 'auto');
			else {
				if (this.direction) this.list.css({marginTop: -(this.mas[this.active])});
				else this.list.css({marginLeft: -(this.mas[this.active])});
			}
		},
		stopHover: function($this){
			this.context.bind('mouseenter', function(){
				$this.stop();
				$this.move = false;
			}).mouseleave(function(){
				$this.move = true;
				$this.play();
			});
		
		},
		calcMinEls: function(){
			if (this.sum <= (this.direction?this.wrap.outerHeight():this.wrap.outerWidth())) {
				if (this.options.nextBtn) this.nextBtn.css({visibility:'hidden'});
				if (this.options.prevBtn) this.prevBtn.css({visibility:'hidden'});
			}
		},
		calcParams: function(self){
			this.mas = [];
			this.sum = 0;
			this.max = this.count-1;
			this.width = 0;
			if (!this.options.effect) {
				this.els.each(function(){self.mas.push(self.width);self.width += self.direction?jQuery(this).outerHeight(true):jQuery(this).outerWidth(true);self.sum+=self.direction?jQuery(this).outerHeight(true):jQuery(this).outerWidth(true);});
				this.finish = this.direction?this.sum-this.wrap.outerHeight():this.sum-this.wrap.outerWidth();
				for (var i=0;i<this.count;i++){
					if (this.mas[i]>=this.finish) {
						this.max = i;
						break;
					}
				}
			}
		},
		changeSettings: function(set,val){
			this[set] = val;
		},
		fadeElement: function(){
			this.els.eq(this.last).animate({opacity:0}, {queue:false, duration: this.duration});
			this.els.removeClass('active').eq(this.active).addClass('active').animate({
				opacity:1
			}, {queue:false, duration: this.duration, complete: function(){
				jQuery(this).css('opacity','auto');
			}});
			if (this.options.switcher) this.switcher.removeClass('active').eq(this.active).addClass('active');
			this.last = this.active;
		},
		scrollElement: function(f){
			if (this.direction) this.list.animate({marginTop: f ? -this.finish : -(this.mas[this.active])}, {queue:false, duration: this.duration});
			else this.list.animate({marginLeft: f ? -this.finish : -(this.mas[this.active])}, {queue:false, duration: this.duration});
			if (this.options.switcher) this.switcher.removeClass('active').eq(this.options.clone ? this.active < this.count ? this.active/this.options.slideElement : this.active >= this.count*2 ? (this.active - this.count*2)/this.options.slideElement : (this.active - this.count)/this.options.slideElement : this.active/this.options.slideElement).addClass('active');
		},
		runTimer: function($this){
			if($this._t) clearTimeout($this._t);
			if ($this.move) {
				$this._t = setInterval(function(){
					$this.nextStep();
				}, this.autoRotation);
			}
		},
		initEventSwitcher: function($this, el){
			el.bind($this.options.event, function(){
				if (!jQuery(this).hasClass('active')){
					$this.active = $this.switcher.index(jQuery(this)) * $this.options.slideElement;
					if ($this.options.clone) $this.active += $this.count;
					$this.initMove();
					if ($this.autoRotation) $this.runTimer($this);
				}
				return false;
			});
		},
		initEvent: function($this, addEventEl, dir){
			addEventEl.bind($this.options.event, function(){
				if (dir) $this.nextStep();
				else $this.prevStep();
				if ($this.autoRotation) $this.runTimer($this);
				return false;
			});
		},
		disableControls: function(){
			this.prevBtn.removeClass(this.options.disableBtn);
			this.nextBtn.removeClass(this.options.disableBtn);
			if (this.active>=this.max) this.nextBtn.addClass(this.options.disableBtn);
			if (this.active<=0) this.prevBtn.addClass(this.options.disableBtn);
		},
		initMove: function(){
			var f = false;
			if (this.active >= this.max && !this.options.clone) {
				f = true;
				this.active = this.max;
			}
			if(this._t) clearTimeout(this._t);
			if (!this.options.effect) this.scrollElement(f);
			else this.fadeElement();
			if (this.options.disableBtn && !this.options.circle && !this.options.clone) this.disableControls();
		},
		nextStep:function(){
			var f = false;
			this.active = this.active + this.options.slideElement;
			if (this.options.disableBtn && !this.options.circle && !this.options.clone) this.disableControls();
			if (this.options.clone){
				if (this.active > this.count*2) {
					if (this.direction) this.list.css({marginTop:-this.mas[this.count]});
					else this.list.css({marginLeft:-this.mas[this.count]});
					this.active = this.count+this.options.slideElement;
				}
			} else {
				if (this.active >= this.max) {
					if (this.options.circle) {
						if (this.active > this.max) this.active = 0;
						else {
							this.active = this.max;
							f = true
						}
					}
					else {
						this.active = this.max;
						f = true;
					}
				}
			}
			if (!this.options.effect) this.scrollElement(f);
			else this.fadeElement();
		},
		prevStep: function(){
			var f = false;
			this.active = this.active - this.options.slideElement;
			if (this.options.disableBtn && !this.options.circle && !this.options.clone) this.disableControls();
			if (this.options.clone){
				if (this.active < 0) {
					if (this.direction) this.list.css({marginTop:-this.mas[this.count]});
					else this.list.css({marginLeft:-this.mas[this.count]});
					this.active = this.count-1;
				}
			} else {
				if (this.active < 0) {
					if (this.options.circle) {
						this.active = this.max;
						f = true;
					}
					else this.active = 0;
				}
			}
			if (!this.options.effect) this.scrollElement(f);
			else this.fadeElement();
		},
		initWindow: function($this,$window){
			$window.focus(jQuery.proxy(this.play,this));
			$window.blur(jQuery.proxy(this.stop,this));
		},
		stop: function(){
			if (this._t) clearTimeout(this._t);
		},
		play: function(){
			if (this.autoRotation) this.runTimer(this);
		}
	}
}(jQuery));
//fadeHover
function fadeHover(){
	jQuery('.img-holder').each(function(){
		var holder = jQuery(this);
		var duration = 300;
		var hover = holder.find('.product-info').css({
			opacity:0,
			display:'block'
		});
		holder.mouseenter(function(){
			hover.stop().animate({
				opacity:1
			},{
				queue:false,
				duration:duration
			});
		}).mouseleave(function(){
			hover.stop().animate({
				opacity:0
			},{
				queue:false,
				duration:duration
			});
		});
	});
}
//fade dropdown
function fadeDrop(){
	var fader;
	if (jQuery('.fader').length > 0) fader = jQuery('.fader');
	else{
		fader = jQuery('<div class="fader"></div>');
		jQuery('body').append(fader);
		fader.css({
			position: 'absolute',
			zIndex: 999,
			left:0,
			top:0,
			width:'100%',
			background: '#000',
			opacity: '0.6'
		}).hide();
	}
	jQuery('#nav>li:has(".drop-down")').each(function(){
		var li = jQuery(this);
		var duration = 150;
		var hoverClass = 'hover';
		var drop = li.find('.drop-down').clone().appendTo(jQuery('body'));
		jQuery('body').append(fader);
		li.bind('mouseenter touchstart', function(){
			if (!jQuery('body').hasClass('active-fade')){
				li.addClass(hoverClass);
				drop.hide().css({
					top: li.offset().top,
					left: li.offset().left
				}).fadeIn(duration);
				jQuery('body').addClass('active-fade');
				setTimeout(function(){
					fader.height(jQuery(document).height()).fadeIn(duration);
				},1);
				
			}
		})
		drop.mouseleave(function(){
			li.removeClass(hoverClass).find('> a').css({backgroundImage:'none'});
			fader.fadeOut(duration);
			drop.fadeOut(duration,function(){
				jQuery('body').removeClass('active-fade');
			});
		});
		jQuery(window).resize(function(){
			li.removeClass(hoverClass).find('> a').css({backgroundImage:'none'});
			fader.fadeOut(0);
			drop.fadeOut(0,function(){
				jQuery('body').removeClass('active-fade');
			});
		});
		fader.bind('mouseenter touchstart', function(){
			li.removeClass(hoverClass).find('> a').css({backgroundImage:'none'});
			fader.fadeOut(duration);
			drop.fadeOut(duration,function(){
				jQuery('body').removeClass('active-fade');
			});
		});
	});
}
// custom checkboxes module
jQuery.fn.customCheckbox = function(_options){
	var _options = jQuery.extend({
		checkboxStructure: '<div></div>',
		checkboxDisabled: 'disabled',
		checkboxDefault: 'checkboxArea',
		checkboxChecked: 'checkboxAreaChecked'
	}, _options);
	return this.each(function(){
		var checkbox = jQuery(this);
		if(!checkbox.hasClass('outtaHere') && checkbox.is(':checkbox')){
			var replaced = jQuery(_options.checkboxStructure);
			this._replaced = replaced;
			if(checkbox.is(':disabled')) replaced.addClass(_options.checkboxDisabled);
			else if(checkbox.is(':checked')) replaced.addClass(_options.checkboxChecked);
			else replaced.addClass(_options.checkboxDefault);

			replaced.click(function(){
				if(checkbox.is(':checked')) checkbox.removeAttr('checked');
				else checkbox.attr('checked', 'checked');
				changeCheckbox(checkbox);
			});
			checkbox.click(function(){
				changeCheckbox(checkbox);
			});
			replaced.insertBefore(checkbox);
			checkbox.addClass('outtaHere');
		}
	});
	function changeCheckbox(_this){
		_this.change();
		if(_this.is(':checked')) _this.get(0)._replaced.removeClass().addClass(_options.checkboxChecked);
		else _this.get(0)._replaced.removeClass().addClass(_options.checkboxDefault);
	}
}
//page scroll top
function pageAnimate(){
	jQuery('#back-top').click(function () {
		jQuery('body,html').animate({
			scrollTop: 0
		}, 800);
		return false;
	});
}
function initPage(){
	clearFormFields({
		clearInputs: true,
		clearTextareas: true,
		passwordFieldText: true,
		addClassFocus: "focus",
		filterClass: "default"
	});
}
function clearFormFields(o){
	if (o.clearInputs == null) o.clearInputs = true;
	if (o.clearTextareas == null) o.clearTextareas = true;
	if (o.passwordFieldText == null) o.passwordFieldText = false;
	if (o.addClassFocus == null) o.addClassFocus = false;
	if (!o.filter) o.filter = "default";
	if(o.clearInputs) {
		var inputs = document.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++ ) {
			if((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass)) {
				inputs[i].valueHtml = inputs[i].value;
				inputs[i].onfocus = function ()	{
					if(this.valueHtml == this.value) this.value = "";
					if(this.fake) {
						inputsSwap(this, this.previousSibling);
						this.previousSibling.focus();
					}
					if(o.addClassFocus && !this.fake) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				inputs[i].onblur = function () {
					if(this.value == "") {
						this.value = this.valueHtml;
						if(o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
					}
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
				if(o.passwordFieldText && inputs[i].type == "password") {
					var fakeInput = document.createElement("input");
					fakeInput.type = "text";
					fakeInput.value = inputs[i].value;
					fakeInput.className = inputs[i].className;
					fakeInput.fake = true;
					inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
					inputsSwap(inputs[i], null);
				}
			}
		}
	}
	if(o.clearTextareas) {
		var textareas = document.getElementsByTagName("textarea");
		for(var i=0; i<textareas.length; i++) {
			if(textareas[i].className.indexOf(o.filterClass)) {
				textareas[i].valueHtml = textareas[i].value;
				textareas[i].onfocus = function() {
					if(this.value == this.valueHtml) this.value = "";
					if(o.addClassFocus) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				textareas[i].onblur = function() {
					if(this.value == "") this.value = this.valueHtml;
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
			}
		}
	}
	function inputsSwap(el, el2) {
		if(el) el.style.display = "none";
		if(el2) el2.style.display = "inline";
	}
}
//tabs
function initTabs()
{
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -1)
		{
			var tabs = [];
			var links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("tab") != -1)
				{
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));

					if (c) if (links[j].className.indexOf("active") != -1) c.style.display = "block";
					else c.style.display = "none";

					links[j].onclick = function ()
					{
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							for (var i = 0; i < this.tabs.length; i++)
							{
								var tab = document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1));
								if (tab)
								{
									tab.style.display = "none";
								}
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";
							return false;
						}
					}
				}
			}
		}
	}
}
// mobile browsers detect
browserPlatform = {
	platforms: [
		{ uaString:['symbian','midp'], cssFile:'symbian.css' }, // Symbian phones
		{ uaString:['opera','mobi'], cssFile:'opera.css' }, // Opera Mobile
		{ uaString:['msie','ppc'], cssFile:'ieppc.css' }, // IE Mobile <6
		{ uaString:'iemobile', cssFile:'iemobile.css' }, // IE Mobile 6+
		{ uaString:'webos', cssFile:'webos.css' }, // Palm WebOS
		{ uaString:'Android', cssFile:'android.css' }, // Android
		{ uaString:['BlackBerry','/6.0','mobi'], cssFile:'blackberry6.css' },	// Blackberry 6
		{ uaString:['BlackBerry','/7.0','mobi'], cssFile:'blackberry7.css' },	// Blackberry 7+
		{ uaString:'ipad', cssFile:'ipad.css', miscHead:'<meta name="viewport" content="width=device-width" />' }, // iPad
		{ uaString:['safari','mobi'], cssFile:'safari.css', miscHead:'<meta name="viewport" content="width=device-width" />' } // iPhone and other webkit browsers
	],
	options: {
		cssPath:'/wp-content/themes/studiodork/css/',
		mobileCSS:'allmobile.css'
	},
	init:function(){
		this.checkMobile();
		this.parsePlatforms();
		return this;
	},
	checkMobile: function() {
		if(this.uaMatch('mobi') || this.uaMatch('midp') || this.uaMatch('ppc') || this.uaMatch('webos')) {
			this.attachStyles({cssFile:this.options.mobileCSS});
		}
	},
	parsePlatforms: function() {
		for(var i = 0; i < this.platforms.length; i++) {
			if(typeof this.platforms[i].uaString === 'string') {
				if(this.uaMatch(this.platforms[i].uaString)) {
					this.attachStyles(this.platforms[i]);
					break;
				}
			} else {
				for(var j = 0, allMatch = true; j < this.platforms[i].uaString.length; j++) {
					if(!this.uaMatch(this.platforms[i].uaString[j])) {
						allMatch = false;
					}
				}
				if(allMatch) {
					this.attachStyles(this.platforms[i]);
					break;
				}
			}
		}
	},
	attachStyles: function(platform) {
		var head = document.getElementsByTagName('head')[0], fragment;
		var cssText = '<link rel="stylesheet" href="' + this.options.cssPath + platform.cssFile + '" type="text/css"/>';
		var miscText = platform.miscHead;
		if(platform.cssFile) {
			if(document.body) {
				fragment = document.createElement('div');
				fragment.innerHTML = cssText;
				head.appendChild(fragment.childNodes[0]);
			} else {
				document.write(cssText);
			}
		}
		if(platform.miscHead) {
			if(document.body) {
				fragment = document.createElement('div');
				fragment.innerHTML = miscText;
				head.appendChild(fragment.childNodes[0]);
			} else {
				document.write(miscText);
			}
		}
	},
	uaMatch:function(str) {
		if(!this.ua) {
			this.ua = navigator.userAgent.toLowerCase();
		}
		return this.ua.indexOf(str.toLowerCase()) != -1;
	}
}.init();

// iepp v2.1pre @jon_neal & @aFarkas github.com/aFarkas/iepp
// html5shiv @rem remysharp.com/html5-enabling-script
// Dual licensed under the MIT or GPL Version 2 licenses
/*@cc_on(function(a,b){function r(a){var b=-1;while(++b<f)a.createElement(e[b])}if(!window.attachEvent||!b.createStyleSheet||!function(){var a=document.createElement("div");return a.innerHTML="<elem></elem>",a.childNodes.length!==1}())return;a.iepp=a.iepp||{};var c=a.iepp,d=c.html5elements||"abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|subline|summary|time|video",e=d.split("|"),f=e.length,g=new RegExp("(^|\\s)("+d+")","gi"),h=new RegExp("<(/*)("+d+")","gi"),i=/^\s*[\{\}]\s*$/,j=new RegExp("(^|[^\\n]*?\\s)("+d+")([^\\n]*)({[\\n\\w\\W]*?})","gi"),k=b.createDocumentFragment(),l=b.documentElement,m=b.getElementsByTagName("script")[0].parentNode,n=b.createElement("body"),o=b.createElement("style"),p=/print|all/,q;c.getCSS=function(a,b){try{if(a+""===undefined)return""}catch(d){return""}var e=-1,f=a.length,g,h=[];while(++e<f){g=a[e];if(g.disabled)continue;b=g.media||b,p.test(b)&&h.push(c.getCSS(g.imports,b),g.cssText),b="all"}return h.join("")},c.parseCSS=function(a){var b=[],c;while((c=j.exec(a))!=null)b.push(((i.exec(c[1])?"\n":c[1])+c[2]+c[3]).replace(g,"$1.iepp-$2")+c[4]);return b.join("\n")},c.writeHTML=function(){var a=-1;q=q||b.body;while(++a<f){var c=b.getElementsByTagName(e[a]),d=c.length,g=-1;while(++g<d)c[g].className.indexOf("iepp-")<0&&(c[g].className+=" iepp-"+e[a])}k.appendChild(q),l.appendChild(n),n.className=q.className,n.id=q.id,n.innerHTML=q.innerHTML.replace(h,"<$1font")},c._beforePrint=function(){if(c.disablePP)return;o.styleSheet.cssText=c.parseCSS(c.getCSS(b.styleSheets,"all")),c.writeHTML()},c.restoreHTML=function(){if(c.disablePP)return;n.swapNode(q)},c._afterPrint=function(){c.restoreHTML(),o.styleSheet.cssText=""},r(b),r(k);if(c.disablePP)return;m.insertBefore(o,m.firstChild),o.media="print",o.className="iepp-printshim",a.attachEvent("onbeforeprint",c._beforePrint),a.attachEvent("onafterprint",c._afterPrint)})(this,document)@*/
// rounded image module
;(function(window){
	// init VML for IE6, IE7, IE8
	var IE = /(MSIE (6|7|8))/.test(navigator.userAgent);
	if(IE) {
		var ns = 'rcr';
		if(document.namespaces && !document.namespaces[ns]) {
			// add VML namespace
			document.namespaces.add(ns,'urn:schemas-microsoft-com:vml','#default#VML'); 
			// create stylesheets
			var screenStyleSheet, printStyleSheet;
			screenStyleSheet = document.createElement('style');
			screenStyleSheet.setAttribute('media', 'screen');
			document.documentElement.firstChild.insertBefore(screenStyleSheet, document.documentElement.firstChild.firstChild);
			if (screenStyleSheet.styleSheet) {
				try {
					// add screen-media rule
					screenStyleSheet = screenStyleSheet.styleSheet;
					screenStyleSheet.addRule(ns + '\\:*', '{behavior:url(#default#VML); display:inline-block}');
					// add a print-media stylesheet
					printStyleSheet = document.createElement('style');
					printStyleSheet.setAttribute('media', 'print');
					document.documentElement.firstChild.insertBefore(printStyleSheet, screenStyleSheet);
					printStyleSheet = printStyleSheet.styleSheet;
					printStyleSheet.addRule(ns + '\\:*', '{display: none !important;}');
				} catch(e) {}
			}
		}
	}

	// browsers techniques support detection
	var supportCanvas = !!document.createElement('canvas').getContext;
	var supportBorderRadius = (function(){
		var cssAttributeNames = ['borderRadius','BorderRadius','MozBorderRadius','WebkitBorderRadius','OBorderRadius','KhtmlBorderRadius']; 
		for (var i = 0; i < cssAttributeNames.length; i++) {
			var attributeName = cssAttributeNames[i];
			if (document.documentElement.style[attributeName] !== undefined) {
				return true;
				break;
			}
		}
		return false;
	}());
	
	// rounded image class
	ImgCorner = function() {
		this.options = {
			radius: 0,
			image: null,
			roundedClass: 'img-rounded'
		}
		this.init.apply(this, arguments);
	}
	ImgCorner.prototype = {
		init: function(options) {
			for(var p in options) {
				if(options.hasOwnProperty(p)) {
					this.options[p] = options[p];
				}
			}
			this.initImage();
		},
		initImage: function() {
			// create image to calculate dimensions
			if(this.options.image) {
				// check borders
				this.realImage = this.options.image;
				this.borderWidth = parseInt(this.getStyle(this.realImage, 'borderTopWidth')) || 0;
				this.borderColor = this.getStyle(this.realImage, 'borderTopColor') || '#333';
			
				this.tmpImage = new Image();
				this.tmpImage.onload = this.bind(function() {
					this.realWidth = this.tmpImage.width;
					this.realHeight = this.tmpImage.height;
					this.onImageComplete();
				},this);
				this.tmpImage.src = this.realImage.src;
			}
		},
		onImageComplete: function() {
			if(IE) {
				this.createVMLNode();
			} else {
				if(supportBorderRadius) {
					this.createCSS3Node();
				} else if(supportCanvas) {
					this.createCanvasNode();
				}
			}
		},
		createCanvasNode: function() {
			var canvas = document.createElement('canvas'), ctx;
			canvas.width = this.realWidth + this.borderWidth*2;
			canvas.height = this.realHeight + this.borderWidth*2;
			if(typeof canvas.getContext === 'function') {
				// create path function
				var createPath = function(dc,x,y,w,h,r,bw) {
					var a = Math.PI/180;
					r -= bw;
					dc.beginPath();
					dc.moveTo(x+r,y);
					dc.lineTo(x+w-r,y);
					dc.arc(x+w-r,y+r,r,a*270,a*360,false);
					dc.lineTo(x+w,y+h-r);
					dc.arc(x+w-r,y+h-r,r,a*0,a*90,false);
					dc.lineTo(x+r,y+h);
					dc.arc(x+r,y+h-r,r,a*90,a*180,false);
					dc.lineTo(x,y+r);
					dc.arc(x+r,y+r,r,a*180,a*270,false); 
				}
			
				// create rounded path
				ctx = canvas.getContext('2d');
				ctx.save();
				createPath(ctx, this.borderWidth,this.borderWidth,this.realWidth,this.realHeight,this.options.radius, this.borderWidth);

				// draw border only if needed
				if(this.borderWidth) {
					ctx.strokeStyle = this.borderColor;
					ctx.lineWidth = this.borderWidth*2;
					ctx.stroke();
				}
				ctx.clip();
				ctx.drawImage(this.tmpImage,this.borderWidth,this.borderWidth);
				ctx.restore();

				// append canvas image
				this.realImage.style.display = 'none';
				this.realImage.parentNode.insertBefore(canvas, this.realImage);
			}
		},
		createVMLNode: function() {
			var w = this.realWidth, h = this.realHeight, r = this.options.radius;
			var vmlBox = document.createElement('corner');
			var sh = document.createElement(ns + ':shape');
			var filler = document.createElement(ns + ':fill');
			vmlBox.style.cssText = 'width:'+this.realWidth+'px;height:'+this.realHeight+'px;margin:0;padding:0;border:0;';
			sh.appendChild(filler);
			sh.style.cssText = 'width:'+this.realWidth+'px;height:'+this.realHeight+'px;display:inline-block;';
			sh.path = 'm '+r+',0 l '+(w-r)+',0 qx '+w+','+r+' l '+w+','+(h-r)+' qy '+(w-r)+','+h+' l '+r+','+h+' qx 0,'+(h-r)+' l 0,'+r+' qy '+r+',0 e';
			sh.coordorigin = "-1 -1";
			sh.coordsize = w+' '+h;

			// draw border if needed
			if(this.borderWidth) {
				sh.strokecolor = this.borderColor;
				sh.strokeweight = this.borderWidth/2;
				sh.stroked = true;
			} else {
				sh.stroked = false;
			}
			
			filler.style.display = 'inline-block';
			filler.setAttribute('type', 'frame');
			filler.setAttribute('src', this.realImage.src);
			vmlBox.appendChild(sh);
			vmlBox.innerHTML = vmlBox.innerHTML;
			this.realImage.style.display = 'none';
			this.realImage.parentNode.insertBefore(vmlBox, this.realImage);
		},
		createCSS3Node: function() {
			var borderAttr = ['borderRadius', 'MozBorderRadius', 'WebkitBorderRadius', 'OBorderRadius']; 
			var span = document.createElement('span');
			span.style.width = this.realWidth+'px';
			span.style.height = this.realHeight+'px';
			span.style.display = 'inline-block';
			span.style.background = 'url('+this.realImage.src+')';
			span.style.overflow = 'hiddden';
			
			for(var i = 0; i < borderAttr.length; i++) {
				span.style[borderAttr[i]] = this.options.radius + 'px';
			}
			
			// draw border if needed
			if(this.borderWidth) {
				span.style.border = this.borderWidth+'px solid '+this.borderColor;
			}
			
			this.realImage.style.border = '0';
			this.realImage.style.display = 'none';
			this.realImage.parentNode.insertBefore(span, this.realImage);
			span.appendChild(this.realImage);
			return span;
		},
		getStyle: function(el, prop) {
			if (document.defaultView && document.defaultView.getComputedStyle) {
				return document.defaultView.getComputedStyle(el, null)[prop];
			} else if (el.currentStyle) {
				return el.currentStyle[prop];
			} else {
				return el.style[prop];
			}
		},
		bind: function(fn, scope, args) {
			return function() {
				return fn.apply(scope, args || arguments);
			}
		} 
	}
})(this);
